99 lines
1.8 KiB
Bash
Executable file
99 lines
1.8 KiB
Bash
Executable file
#!/bin/sh
|
||
|
||
case $1 in
|
||
prereqs)
|
||
##
|
||
# GET EXECUTED WHEN BUILDING INITRAMFS
|
||
#
|
||
. /usr/share/initramfs-tools/hook-functions
|
||
copy_exec /usr/bin/aria2c
|
||
copy_exec /sbin/sfdisk
|
||
copy_exec /sbin/mke2fs
|
||
copy_file cert /etc/ssl/certs/ca-certificates.crt
|
||
exit 0
|
||
;;
|
||
esac
|
||
|
||
##
|
||
# FUNCTION DEFINITIONS
|
||
##
|
||
|
||
print_waiting() {
|
||
echo -en "\033[36m${1}... \033[0m"
|
||
}
|
||
|
||
print_done() {
|
||
echo -e "\033[32mdone.\033[0m"
|
||
}
|
||
|
||
##
|
||
# HARDCODED DISK PARAMETERS
|
||
##
|
||
|
||
disk=/dev/sda
|
||
|
||
size_part_1=$((3072 * 1024 * 1024 / 512))
|
||
|
||
##
|
||
# PARTITIONING OF DISK
|
||
##
|
||
|
||
print_waiting "Partitioning disk"
|
||
sfdisk -q /dev/sda << PARTTABLE
|
||
label: dos
|
||
label-id: 0xdeadbeef
|
||
device: /dev/sda
|
||
unit: sectors
|
||
|
||
/dev/sda1 : start= 2048, size= $size_part_1, type=83
|
||
PARTTABLE
|
||
print_done
|
||
|
||
print_waiting "Creating Filesystem"
|
||
mke2fs -q -F -t ext4 ${disk}1
|
||
print_done
|
||
|
||
##
|
||
# TEMPORARY NETWORK CONFIG (only for qemu)
|
||
##
|
||
|
||
print_waiting "Setting up temporary network config"
|
||
ip addr add 10.2.2.2/24 dev ens3
|
||
ip link set ens3 up
|
||
print_done
|
||
|
||
##
|
||
# MOUNT TEMPORARY ROOTFS
|
||
##
|
||
|
||
print_waiting "Mounting temporary root filesystem"
|
||
mkdir -p /tmp_root
|
||
mount -t ext4 ${disk}1 /tmp_root
|
||
cd /tmp_root
|
||
print_done
|
||
|
||
##
|
||
# DOWNLOAD FS IMAGE
|
||
##
|
||
|
||
print_waiting "Downloading root filesystem image"
|
||
# (DHT error seems normal, because it is aria2c’s first run)
|
||
|
||
# --check-integrity: verify downloaded file and do not complain about missing controll file
|
||
# --seed-time=0: do not wait until ratio 1, we seed when we’re booted
|
||
# --quiet: no console output
|
||
aria2c --check-integrity --seed-time=0 --quiet=true 'http://10.2.2.1:8081/image.torrent'
|
||
print_done
|
||
|
||
##
|
||
# UNMOUNT TEMPORARY ROOTFS
|
||
##
|
||
|
||
print_waiting "Unmounting temporary root filesystem"
|
||
cd /
|
||
umount /tmp_root
|
||
print_done
|
||
|
||
print_waiting "Waiting for implementation of more features"
|
||
|
||
while sleep 3600;do sleep 3600;done
|