From 8d64781d948fd211045f1e71837772a68f07fff7 Mon Sep 17 00:00:00 2001 From: Andrew Cady Date: Sat, 25 Mar 2017 15:22:08 -0400 Subject: Initial support for installing to an empty disk device Right now, this just installs a new GPT partition table on the disk, with the partitions samizdat needs. Then nothing happens because nothing else is implemented. It will only allow a disk to be wiped like this if there are no partitions on the disk (or if the only partitions on the disk are partially-installed samizdat partitions). --- src/initrd/grok-block | 38 ++++++++++++++++++++++++++++++++++---- 1 file changed, 34 insertions(+), 4 deletions(-) (limited to 'src/initrd/grok-block') diff --git a/src/initrd/grok-block b/src/initrd/grok-block index 081238a..086722d 100755 --- a/src/initrd/grok-block +++ b/src/initrd/grok-block @@ -46,6 +46,16 @@ addmenu_makeroot() ) & } +addmenu_destroy_hard_drive() +{ + local device="$1" + ( + addmenu "$device//$loopfile" \ + "[ Install Samizdat to $device -- THIS DESTROYS ALL DATA ]" \ + "menu-select boot-destroy-disk $device" + ) & +} + retry_mount() { tries=20 @@ -75,6 +85,7 @@ gpg_verify() export GNUPGHOME=/gpg/gnupghome gpg2 --lock-never --no-permission-warning --no-auto-check-trustdb --no-options --verify "$1" } + is_lvm() { for n in 0 1 2 3; do @@ -83,6 +94,19 @@ is_lvm() return 1 } +is_device_without_partitions() +{ + case "$1" in /dev/nbd*|/dev/sr*|*[0-9]) return 1 ;; esac + + [ "$(parted -sm "$1" print | grep -c :)" = 1 ] +} + +is_incomplete_samizdat_install() +{ + local partition_names="$(parted -sm "$1" print | sed 1,2d | awk -F: -e '{printf "%s:", $6}')" + [ "$partition_names" = 'primary:gpg-incomplete:luks-incomplete:' ] +} + grok_block() { local mountpoint="/mnt/${DEVNAME##*/}" @@ -108,14 +132,22 @@ grok_block() retry_mount $mount_type -o ro "$DEVNAME" "$mountpoint" fi - if [ "$DEVNAME" = /dev/nbd0 ] && mountpoint -q "$mountpoint"; then + if ! mountpoint -q "$mountpoint"; then + rmdir "$mountpoint" + is_device_without_partitions "$DEVNAME" || + is_incomplete_samizdat_install "$DEVNAME" && + addmenu_destroy_hard_drive "$DEVNAME" + + # TODO: Need option to boot the partitions we create + # TODO: And what if we create partitions and then reboot the machine mid-install? + elif [ "$DEVNAME" = /dev/nbd0 ]; then # This is our rootfs, over the network umount "$mountpoint" rmdir "$mountpoint" bootdone samizdat-nbd-dev - elif mountpoint -q "$mountpoint"; then + else umount=true # Device has an unencrypted filesystem on it. # So we mount it and look for loop-back overlays. @@ -164,8 +196,6 @@ grok_block() umount "$mountpoint" rmdir "$mountpoint" fi - else - rmdir "$mountpoint" fi } -- cgit v1.2.3