From ea584f7bc7643aaf1292b87c5dcd1920fc651fe4 Mon Sep 17 00:00:00 2001 From: "Kevin Veen-Birkenbach [aka. Frantz]" Date: Fri, 2 Oct 2020 13:54:43 +0200 Subject: [PATCH] Refactored code --- scripts/image/setup.sh | 57 ++++++++++++++++++++---------------------- 1 file changed, 27 insertions(+), 30 deletions(-) diff --git a/scripts/image/setup.sh b/scripts/image/setup.sh index b398540..bc6f57c 100644 --- a/scripts/image/setup.sh +++ b/scripts/image/setup.sh @@ -407,10 +407,17 @@ fi if [ "$encrypt_system" == "y" ] then # Adapted this instruction for setting up encrypted systems @see https://gist.github.com/gea0/4fc2be0cb7a74d0e7cc4322aed710d38 - info "Setup encryption..." && + + info "Installing neccessary software..." && + echo "pacman --noconfirm -S --needed $(get_packages "server/luks")" | chroot "$root_mount_path" /bin/bash && + + dropbear_root_key_path="$root_mount_path""etc/dropbear/root_key" && + info "Adding "$target_authorized_keys" to dropbear..." && + cp -v "$target_authorized_keys" "$dropbear_root_key_path" && + #Concerning mkinitcpio warning @see https://gist.github.com/imrvelj/c65cd5ca7f5505a65e59204f5a3f7a6d - mkinitcpio_path="/etc/mkinitcpio.conf" && + mkinitcpio_path="$root_mount_path""etc/mkinitcpio.conf" && info "Configuring $mkinitcpio_path..." && mkinitcpio_search_modules="MODULES=()" && mkinitcpio_replace_modules="MODULES=(g_cdc usb_f_acm usb_f_ecm smsc95xx g_ether)" && @@ -418,43 +425,33 @@ if [ "$encrypt_system" == "y" ] mkinitcpio_replace_binaries=$(echo "BINARIES=(/usr/lib/libgcc_s.so.1)"| sed -e 's/[\/&]/\\&/g') && mkinitcpio_search_hooks="HOOKS=(base udev autodetect modconf block filesystems keyboard fsck)" && mkinitcpio_replace_hooks="HOOKS=(base udev autodetect modconf block sleep netconf dropbear encryptssh filesystems keyboard fsck)" && - ( - echo "pacman --noconfirm -S --needed $(get_packages "server/luks") &&" - echo "cp -v /home/$target_username/.ssh/authorized_keys /etc/dropbear/root_key &&" - echo "sed -i 's/$mkinitcpio_search_modules/$mkinitcpio_replace_modules/g' $mkinitcpio_path &&" - echo "sed -i 's/$mkinitcpio_search_binaries/$mkinitcpio_replace_binaries/g' $mkinitcpio_path &&" - echo "sed -i 's/$mkinitcpio_search_hooks/$mkinitcpio_replace_hooks/g' $mkinitcpio_path &&" - echo "echo \"Content of $mkinitcpio_path:\$(cat \"$mkinitcpio_path\")\" &&" - echo "mkinitcpio -P &&" - ) | chroot "$root_mount_path" /bin/bash && + sed -i "s/$mkinitcpio_search_modules/$mkinitcpio_replace_modules/g" $mkinitcpio_path && + sed -i "s/$mkinitcpio_search_binaries/$mkinitcpio_replace_binaries/g" $mkinitcpio_path && + sed -i "s/$mkinitcpio_search_hooks/$mkinitcpio_replace_hooks/g" $mkinitcpio_path && + echo "Content of $mkinitcpio_path:$(cat "$mkinitcpio_path")" && + info "Generating mkinitcpio..." && + echo "mkinitcpio -vP || exit 1" | chroot "$root_mount_path" /bin/bash && - fstab_path="/etc/fstab" && - info "Generating $fstab_path..." && - ( - echo "echo 'UUID=$root_partition_uuid / ext4 defaults,noatime 0 1' >> $fstab_path &&" - echo "echo \"Content of $fstab_path:\$(cat \"$fstab_path\")\" &&" - ) | chroot "$root_mount_path" /bin/bash && + fstab_path="$root_mount_path""etc/fstab" && + info "Configuring $fstab_path..." && + echo "UUID=$root_partition_uuid / ext4 defaults,noatime 0 1" >> $fstab_path && + echo "Content of $fstab_path:$(cat "$fstab_path")" && - crypttab_path="/etc/crypttab" && + crypttab_path="$root_mount_path""etc/crypttab" && info "Generating $crypttab_path..." && - ( - echo "echo '$root_mapper_name UUID=$root_partition_uuid none luks' >> $crypttab_path &&" - echo "echo \"Content of $crypttab_path:\$(cat \"$crypttab_path\")\" &&" - ) | chroot "$root_mount_path" /bin/bash && + echo "$root_mapper_name UUID=$root_partition_uuid none luks" >> $crypttab_path && + echo "Content of $crypttab_path:$(cat "$crypttab_path")" && #boot.txt just works with raspberry pi 3 @todo Needs to be implemented for arch raspbery pi 4 - boot_txt_path="/boot/boot.txt" && + boot_txt_path="$root_mount_path""boot/boot.txt" && info "Generating $boot_txt_path..." && boot_txt_delete_line=$(echo "part uuid \${devtype} \${devnum}:2 uuid" | sed -e 's/[]\/$*.^[]/\\&/g') && boot_txt_setenv_origin=$(echo "setenv bootargs console=ttyS1,115200 console=tty0 root=PARTUUID=\${uuid} rw rootwait smsc95xx.macaddr=\"\${usbethaddr}\"" | sed -e 's/[]\/$*.^[]/\\&/g') && boot_txt_setenv_replace=$(echo "setenv bootargs console=ttyS1,115200 console=tty0 ip=::::$target_hostname:eth0:dhcp cryptdevice=UUID=$root_partition_uuid:$root_mapper_name root=$root_mapper_path rw rootwait smsc95xx.macaddr=\"\${usbethaddr}\""| sed -e 's/[\/&]/\\&/g') && - ( - echo "sed -i 's/$boot_txt_delete_line//g' $boot_txt_path &&" - echo "sed -i 's/$boot_txt_setenv_origin/$boot_txt_setenv_replace/g' $boot_txt_path &&" - echo "echo \"Content of $boot_txt_path:\$(cat \"$boot_txt_path\")\" &&" - echo "cd /boot/ && ./mkscr &&" - echo "exit || exit 1" - ) | chroot "$root_mount_path" /bin/bash || error + sed -i "s/$boot_txt_delete_line//g" $boot_txt_path && + sed -i "s/$boot_txt_setenv_origin/$boot_txt_setenv_replace/g" $boot_txt_path && + echo "Content of $boot_txt_path:$(cat "$boot_txt_path")" && + echo "cd /boot/ && ./mkscr || exit 1" | chroot "$root_mount_path" /bin/bash || error fi question "Do you want to setup Wifi on the device?(y/N)" && read -r setup_wifi