diff options
Diffstat (limited to 'src/initrd/grok-block')
-rwxr-xr-x | src/initrd/grok-block | 38 |
1 files changed, 34 insertions, 4 deletions
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() | |||
46 | ) & | 46 | ) & |
47 | } | 47 | } |
48 | 48 | ||
49 | addmenu_destroy_hard_drive() | ||
50 | { | ||
51 | local device="$1" | ||
52 | ( | ||
53 | addmenu "$device//$loopfile" \ | ||
54 | "[ Install Samizdat to $device -- THIS DESTROYS ALL DATA ]" \ | ||
55 | "menu-select boot-destroy-disk $device" | ||
56 | ) & | ||
57 | } | ||
58 | |||
49 | retry_mount() | 59 | retry_mount() |
50 | { | 60 | { |
51 | tries=20 | 61 | tries=20 |
@@ -75,6 +85,7 @@ gpg_verify() | |||
75 | export GNUPGHOME=/gpg/gnupghome | 85 | export GNUPGHOME=/gpg/gnupghome |
76 | gpg2 --lock-never --no-permission-warning --no-auto-check-trustdb --no-options --verify "$1" | 86 | gpg2 --lock-never --no-permission-warning --no-auto-check-trustdb --no-options --verify "$1" |
77 | } | 87 | } |
88 | |||
78 | is_lvm() | 89 | is_lvm() |
79 | { | 90 | { |
80 | for n in 0 1 2 3; do | 91 | for n in 0 1 2 3; do |
@@ -83,6 +94,19 @@ is_lvm() | |||
83 | return 1 | 94 | return 1 |
84 | } | 95 | } |
85 | 96 | ||
97 | is_device_without_partitions() | ||
98 | { | ||
99 | case "$1" in /dev/nbd*|/dev/sr*|*[0-9]) return 1 ;; esac | ||
100 | |||
101 | [ "$(parted -sm "$1" print | grep -c :)" = 1 ] | ||
102 | } | ||
103 | |||
104 | is_incomplete_samizdat_install() | ||
105 | { | ||
106 | local partition_names="$(parted -sm "$1" print | sed 1,2d | awk -F: -e '{printf "%s:", $6}')" | ||
107 | [ "$partition_names" = 'primary:gpg-incomplete:luks-incomplete:' ] | ||
108 | } | ||
109 | |||
86 | grok_block() | 110 | grok_block() |
87 | { | 111 | { |
88 | local mountpoint="/mnt/${DEVNAME##*/}" | 112 | local mountpoint="/mnt/${DEVNAME##*/}" |
@@ -108,14 +132,22 @@ grok_block() | |||
108 | retry_mount $mount_type -o ro "$DEVNAME" "$mountpoint" | 132 | retry_mount $mount_type -o ro "$DEVNAME" "$mountpoint" |
109 | fi | 133 | fi |
110 | 134 | ||
111 | if [ "$DEVNAME" = /dev/nbd0 ] && mountpoint -q "$mountpoint"; then | 135 | if ! mountpoint -q "$mountpoint"; then |
136 | rmdir "$mountpoint" | ||
137 | is_device_without_partitions "$DEVNAME" || | ||
138 | is_incomplete_samizdat_install "$DEVNAME" && | ||
139 | addmenu_destroy_hard_drive "$DEVNAME" | ||
140 | |||
141 | # TODO: Need option to boot the partitions we create | ||
142 | # TODO: And what if we create partitions and then reboot the machine mid-install? | ||
112 | 143 | ||
144 | elif [ "$DEVNAME" = /dev/nbd0 ]; then | ||
113 | # This is our rootfs, over the network | 145 | # This is our rootfs, over the network |
114 | umount "$mountpoint" | 146 | umount "$mountpoint" |
115 | rmdir "$mountpoint" | 147 | rmdir "$mountpoint" |
116 | bootdone samizdat-nbd-dev | 148 | bootdone samizdat-nbd-dev |
117 | 149 | ||
118 | elif mountpoint -q "$mountpoint"; then | 150 | else |
119 | umount=true | 151 | umount=true |
120 | # Device has an unencrypted filesystem on it. | 152 | # Device has an unencrypted filesystem on it. |
121 | # So we mount it and look for loop-back overlays. | 153 | # So we mount it and look for loop-back overlays. |
@@ -164,8 +196,6 @@ grok_block() | |||
164 | umount "$mountpoint" | 196 | umount "$mountpoint" |
165 | rmdir "$mountpoint" | 197 | rmdir "$mountpoint" |
166 | fi | 198 | fi |
167 | else | ||
168 | rmdir "$mountpoint" | ||
169 | fi | 199 | fi |
170 | } | 200 | } |
171 | 201 | ||