diff options
Diffstat (limited to 'src/partvi')
-rwxr-xr-x | src/partvi | 109 |
1 files changed, 57 insertions, 52 deletions
@@ -174,6 +174,7 @@ iterate_partitions() | |||
174 | 174 | ||
175 | imgfile=$builddir/$img | 175 | imgfile=$builddir/$img |
176 | 176 | ||
177 | check_for_key_only_skip || continue | ||
177 | "$@" || return | 178 | "$@" || return |
178 | done | 179 | done |
179 | } | 180 | } |
@@ -207,7 +208,6 @@ create_ptable_conf() | |||
207 | partition-table) start=$((start + devsz)); return;; | 208 | partition-table) start=$((start + devsz)); return;; |
208 | efi-system-partition) typecode=C12A7328-F81F-11D2-BA4B-00A0C93EC93B ;; | 209 | efi-system-partition) typecode=C12A7328-F81F-11D2-BA4B-00A0C93EC93B ;; |
209 | dm-verity-data|dm-verity-hashes) | 210 | dm-verity-data|dm-verity-hashes) |
210 | check_for_key_only_skip || return 0 | ||
211 | case "$name" in | 211 | case "$name" in |
212 | samizdat-rootfs|samizdat-root-patch) typecode=4f68bce3-e8cd-4db1-96e7-fbcaf984b709 ;; | 212 | samizdat-rootfs|samizdat-root-patch) typecode=4f68bce3-e8cd-4db1-96e7-fbcaf984b709 ;; |
213 | samizdat-root-patch-verity) typecode=2c7357ed-ebd2-46d9-aec1-23d437ec2bf5 ;; | 213 | samizdat-root-patch-verity) typecode=2c7357ed-ebd2-46d9-aec1-23d437ec2bf5 ;; |
@@ -249,38 +249,6 @@ create_ptable_conf() | |||
249 | start=$((start + devsz)) | 249 | start=$((start + devsz)) |
250 | } | 250 | } |
251 | 251 | ||
252 | KEY_ONLY= | ||
253 | if [ "$1" = 'key' ] | ||
254 | then | ||
255 | KEY_ONLY=y | ||
256 | fi | ||
257 | |||
258 | set -e | ||
259 | |||
260 | builddir=_build | ||
261 | mkdir -p "$builddir" | ||
262 | |||
263 | iterate_partitions build_partition_image | ||
264 | |||
265 | if [ "$UID" = 0 ] | ||
266 | then sudo= | ||
267 | else sudo=sudo | ||
268 | fi | ||
269 | |||
270 | if [ "$KEY_ONLY" ] | ||
271 | then | ||
272 | target=key.img | ||
273 | else | ||
274 | target=whole.img | ||
275 | fi | ||
276 | |||
277 | if whole=$(losetup -j "$target" -O NAME --noheadings) | ||
278 | then | ||
279 | quietly $sudo umount *.mnt | ||
280 | quietly $sudo kpartx -dv "$whole" | ||
281 | quietly $sudo losetup -D | ||
282 | fi | ||
283 | |||
284 | sfdisk_init() | 252 | sfdisk_init() |
285 | { | 253 | { |
286 | local DEV LAST LAST_LBA | 254 | local DEV LAST LAST_LBA |
@@ -315,9 +283,11 @@ pee_on_table() | |||
315 | : > "$DOS_TABLE_FILE" | 283 | : > "$DOS_TABLE_FILE" |
316 | iterate_partitions create_ptable_conf | 284 | iterate_partitions create_ptable_conf |
317 | 285 | ||
318 | set -x | 286 | ( |
319 | $sudo sfdisk "$dev" < "$GPT_TABLE_FILE" || return | 287 | set -x |
320 | $sudo sfdisk -Y dos "$dev" < "$DOS_TABLE_FILE" || return | 288 | $sudo sfdisk --no-tell-kernel "$dev" < "$GPT_TABLE_FILE" || return |
289 | $sudo sfdisk --no-tell-kernel -Y dos "$dev" < "$DOS_TABLE_FILE" || return | ||
290 | ) | ||
321 | } | 291 | } |
322 | 292 | ||
323 | check_for_key_only_skip() | 293 | check_for_key_only_skip() |
@@ -332,19 +302,67 @@ check_for_key_only_skip() | |||
332 | clone_parts_to_target() | 302 | clone_parts_to_target() |
333 | { | 303 | { |
334 | 304 | ||
335 | check_for_key_only_skip || return 0 | ||
336 | f=$(readlink -e _build/"${f%.conf}") || return | 305 | f=$(readlink -e _build/"${f%.conf}") || return |
337 | ficlonerange.py "$f" "$target" | 306 | ficlonerange.py "$f" "$target" |
338 | } | 307 | } |
339 | 308 | ||
309 | cleanup() | ||
310 | { | ||
311 | for f in part*.conf | ||
312 | do | ||
313 | mnt=${f%.conf}.mnt | ||
314 | if mountpoint -q "$mnt" | ||
315 | then | ||
316 | loudly $sudo umount "$mnt" | ||
317 | $sudo rmdir "$mnt" | ||
318 | fi | ||
319 | done | ||
320 | if [ "$whole" ] | ||
321 | then | ||
322 | loudly $sudo kpartx -sd "$whole" | ||
323 | loudly $sudo losetup -d "$whole" | ||
324 | fi | ||
325 | } | ||
326 | |||
327 | KEY_ONLY= | ||
328 | if [ "$1" = 'key' ] | ||
329 | then | ||
330 | KEY_ONLY=y | ||
331 | fi | ||
332 | |||
333 | set -e | ||
334 | |||
335 | builddir=_build | ||
336 | mkdir -p "$builddir" | ||
337 | |||
338 | if [ "$UID" = 0 ] | ||
339 | then sudo= | ||
340 | else sudo=sudo | ||
341 | fi | ||
342 | |||
343 | if [ "$KEY_ONLY" ] | ||
344 | then | ||
345 | target=key.img | ||
346 | else | ||
347 | target=whole.img | ||
348 | fi | ||
349 | |||
350 | iterate_partitions build_partition_image | ||
351 | |||
352 | if whole=$(losetup -j "$target" -O NAME --noheadings) | ||
353 | then | ||
354 | cleanup | ||
355 | whole= | ||
356 | fi | ||
340 | truncate -s0 "$target" | 357 | truncate -s0 "$target" |
341 | iterate_partitions clone_parts_to_target | 358 | iterate_partitions clone_parts_to_target |
342 | 359 | ||
343 | $sudo losetup -L -f "$target" | 360 | $sudo losetup -L -f "$target" |
344 | whole=$(losetup -j "$target" -O NAME --noheadings) | 361 | whole=$(losetup -j "$target" -O NAME --noheadings) |
345 | (pee_on_table "$whole") || exit | 362 | pee_on_table "$whole" |
363 | $sudo kpartx -su "$whole" | ||
346 | 364 | ||
347 | $sudo kpartx -u "$whole" | 365 | trap cleanup EXIT |
348 | 366 | ||
349 | for f in part*.conf | 367 | for f in part*.conf |
350 | do | 368 | do |
@@ -381,16 +399,3 @@ do | |||
381 | done | 399 | done |
382 | 400 | ||
383 | loudly $sudo eatmydata -- grub-install --target=i386-pc --recheck --boot-directory="$BOOT_DIR" "$whole" | 401 | loudly $sudo eatmydata -- grub-install --target=i386-pc --recheck --boot-directory="$BOOT_DIR" "$whole" |
384 | loudly $sudo eatmydata -- grub-install --target=x86_64-efi --recheck --removable --efi-directory="$EFI_DIR" "$whole" | ||
385 | |||
386 | for f in part*.conf | ||
387 | do | ||
388 | mnt=${f%.conf}.mnt | ||
389 | if mountpoint -q "$mnt" | ||
390 | then | ||
391 | loudly $sudo umount "$mnt" | ||
392 | $sudo rmdir "$mnt" | ||
393 | fi | ||
394 | done | ||
395 | loudly $sudo kpartx -d "$whole" | ||
396 | loudly $sudo losetup -d "$whole" | ||