From 963ffcbcecfddbcf950fc96da5a8c7e4d0bea3b7 Mon Sep 17 00:00:00 2001 From: Andrew Cady Date: Sat, 27 Feb 2021 11:04:02 -0500 Subject: partvi: move all functions to top --- src/partvi | 104 ++++++++++++++++++++++++++++++++++++------------------------- 1 file changed, 62 insertions(+), 42 deletions(-) diff --git a/src/partvi b/src/partvi index d2b6ac7..2a32851 100755 --- a/src/partvi +++ b/src/partvi @@ -1,11 +1,4 @@ #!/bin/bash -shopt -s nullglob -PATH=/sbin:$PATH - -: ${GRUB_CONFIG:=../conf/grub.cfg} -samizdat_linux_dir=/ - - add_initrd() { @@ -282,6 +275,47 @@ cleanup() fi } +copy_data_to_mounted_target_filesystems() +{ + case "$type" in + efi-system-partition|boot|samizdat-keys) ;; + dm-verity-hashes|partition-table|bios-grub) return ;; + *) notice "Not mounting $name"; return ;; + esac + + img=${f%.conf} + dev=/dev/mapper/${whole#/dev/}p${img#part} + mnt=${f%.conf}.mnt + + mkdir -p "$mnt" + loudly $sudo mount "$dev" "$mnt" + + case "$type" in + boot) + BOOT_DIR=$mnt + install_boot_dir "$mnt" + ;; + samizdat-keys) + $sudo rsync -a --info=STATS "$GPG_INPUT_DIR"/ "$mnt"/gnupghome/ + ;; + efi-system-partition) + EFI_DIR=$mnt + ;; + esac +} + +shopt -s nullglob +PATH=/sbin:$PATH + +: ${GRUB_CONFIG:=../conf/grub.cfg} +samizdat_linux_dir=/ +builddir=_build + +if [ "$UID" = 0 ] +then sudo= +else sudo=sudo +fi + if [ "$GPG_INPUT_DIR" ] then $sudo [ -d "$GPG_INPUT_DIR" ] @@ -293,6 +327,7 @@ else break done fi + SKIP_ROOTFS_COPY= if [ "$1" = 'key' ] then @@ -301,14 +336,8 @@ fi set -e -builddir=_build mkdir -p "$builddir" -if [ "$UID" = 0 ] -then sudo= -else sudo=sudo -fi - if [ "$SKIP_ROOTFS_COPY" ] then target=key.img @@ -316,7 +345,11 @@ else target=whole.img fi -iterate_partitions build_partition_image + + + + + if whole=$(losetup -j "$target" -O NAME --noheadings) then @@ -324,43 +357,30 @@ then whole= fi truncate -s0 "$target" -iterate_partitions clone_parts_to_target +iterate_partitions build_partition_image + + + +iterate_partitions clone_parts_to_target $sudo losetup -L -f "$target" whole=$(losetup -j "$target" -O NAME --noheadings) + + + + + + + pee_on_table "$whole" -$sudo kpartx -su "$whole" -trap cleanup EXIT -copy_data_to_mounted_target_filesystems() -{ - case "$type" in - efi-system-partition|boot|samizdat-keys) ;; - dm-verity-hashes|partition-table|bios-grub) return ;; - *) notice "Not mounting $name"; return ;; - esac - img=${f%.conf} - dev=/dev/mapper/${whole#/dev/}p${img#part} - mnt=${f%.conf}.mnt - mkdir -p "$mnt" - loudly $sudo mount "$dev" "$mnt" - case "$type" in - boot) - BOOT_DIR=$mnt - install_boot_dir "$mnt" - ;; - samizdat-keys) - $sudo rsync -a --info=STATS "$GPG_INPUT_DIR"/ "$mnt"/gnupghome/ - ;; - efi-system-partition) - EFI_DIR=$mnt - ;; - esac -} +trap cleanup EXIT +$sudo kpartx -su "$whole" + iterate_partitions copy_data_to_mounted_target_filesystems loudly $sudo eatmydata -- grub-install --target=i386-pc --recheck --boot-directory="$BOOT_DIR" "$whole" -- cgit v1.2.3