From 46be773a1d2bcb30d1754060ceeef30ef0ec546e Mon Sep 17 00:00:00 2001 From: Sebastian Hugentobler Date: Thu, 11 Feb 2021 00:45:29 +0100 Subject: [PATCH] clean up everything correctly --- bootstrap | 37 +++++++++++++++++++------------------ mk_pbp_img | 1 + 2 files changed, 20 insertions(+), 18 deletions(-) diff --git a/bootstrap b/bootstrap index c2689a5..0a961e3 100755 --- a/bootstrap +++ b/bootstrap @@ -99,10 +99,7 @@ open_luks() { local install_dev install_dev="$(get_value "install_dev" "installation device")" - - if ! dmsetup ls | grep "void\s"; then - cryptsetup open "$install_dev"p2 void - fi + cryptsetup open "$install_dev"p2 void } create_lvm() { @@ -133,12 +130,10 @@ ensure_mount() { rbind="--rbind" fi - if grep -qs "$dest " /proc/mounts; then - mount "$rbind" "$src" "$dest" + mount $rbind "$src" "$dest" - if [ ! -z "$with_rbind"]; then - mount --make-rslave "$dest" - fi + if [ ! -z "$with_rbind" ]; then + mount --make-rslave "$dest" fi } @@ -151,9 +146,7 @@ mount_filesystems() { mkdir -p /mnt/boot ensure_mount "$install_dev"p1 "/mnt/boot" - if [ "$(cat /proc/swaps | wc -l)" == 1 ]; then - swapon /dev/void/swap - fi + swapon /dev/void/swap } install_basesystem() { @@ -245,7 +238,7 @@ set_base_conf() { local locale locale="$(get_value "locale" "locale")" - echo "$locale" >> /etc/default/libc-locales + echo "$locale" >> /mnt/etc/default/libc-locales chroot /mnt /bin/env -i \ timezone="$timezone" \ @@ -302,11 +295,17 @@ EOF } tidy_up() { - umount -R /mnt - lvchange -an void/root - lvchange -an void/swap - vgchange -an void - cryptsetup close void + sync + + if grep -qe "/mnt " /proc/mounts; then + umount -R /mnt + fi + + swapoff /dev/void/swap > /dev/null 2>&1 || true + + vgchange --activate n + + cryptsetup close void > /dev/null 2>&1 || true } full_install() { @@ -404,6 +403,8 @@ cmd_loop() { done } +trap tidy_up 0 SIGHUP SIGINT SIGQUIT SIGABRT SIGTERM + if [ "$1" == "full" ]; then full_install else diff --git a/mk_pbp_img b/mk_pbp_img index d05f062..e3fd8d9 100755 --- a/mk_pbp_img +++ b/mk_pbp_img @@ -83,6 +83,7 @@ build_img() { sudo chroot "$TMP_DIR_MOUNT" qemu-aarch64-static /bin/bash <<"EOT" ln -s /etc/sv/dbus /etc/runit/runsvdir/default/ ln -s /etc/sv/NetworkManager /etc/runit/runsvdir/default/ +ln -s /etc/sv/sshd /etc/runit/runsvdir/default/ EOT sudo rm "$TMP_DIR_MOUNT/usr/bin/qemu-aarch64-static"