summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrew Cady <d@jerkface.net>2021-02-27 11:04:02 -0500
committerAndrew Cady <d@jerkface.net>2021-02-27 11:04:02 -0500
commit963ffcbcecfddbcf950fc96da5a8c7e4d0bea3b7 (patch)
tree260b497ea0a6be0187b5d6315112bf15afccfbe3
parent3b4d7432fac47ccb89fdd65e851f84985c415ff2 (diff)
partvi: move all functions to top
-rwxr-xr-xsrc/partvi104
1 files 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 @@
1#!/bin/bash 1#!/bin/bash
2shopt -s nullglob
3PATH=/sbin:$PATH
4
5: ${GRUB_CONFIG:=../conf/grub.cfg}
6samizdat_linux_dir=/
7
8
9 2
10add_initrd() 3add_initrd()
11{ 4{
@@ -282,6 +275,47 @@ cleanup()
282 fi 275 fi
283} 276}
284 277
278copy_data_to_mounted_target_filesystems()
279{
280 case "$type" in
281 efi-system-partition|boot|samizdat-keys) ;;
282 dm-verity-hashes|partition-table|bios-grub) return ;;
283 *) notice "Not mounting $name"; return ;;
284 esac
285
286 img=${f%.conf}
287 dev=/dev/mapper/${whole#/dev/}p${img#part}
288 mnt=${f%.conf}.mnt
289
290 mkdir -p "$mnt"
291 loudly $sudo mount "$dev" "$mnt"
292
293 case "$type" in
294 boot)
295 BOOT_DIR=$mnt
296 install_boot_dir "$mnt"
297 ;;
298 samizdat-keys)
299 $sudo rsync -a --info=STATS "$GPG_INPUT_DIR"/ "$mnt"/gnupghome/
300 ;;
301 efi-system-partition)
302 EFI_DIR=$mnt
303 ;;
304 esac
305}
306
307shopt -s nullglob
308PATH=/sbin:$PATH
309
310: ${GRUB_CONFIG:=../conf/grub.cfg}
311samizdat_linux_dir=/
312builddir=_build
313
314if [ "$UID" = 0 ]
315then sudo=
316else sudo=sudo
317fi
318
285if [ "$GPG_INPUT_DIR" ] 319if [ "$GPG_INPUT_DIR" ]
286then 320then
287 $sudo [ -d "$GPG_INPUT_DIR" ] 321 $sudo [ -d "$GPG_INPUT_DIR" ]
@@ -293,6 +327,7 @@ else
293 break 327 break
294 done 328 done
295fi 329fi
330
296SKIP_ROOTFS_COPY= 331SKIP_ROOTFS_COPY=
297if [ "$1" = 'key' ] 332if [ "$1" = 'key' ]
298then 333then
@@ -301,14 +336,8 @@ fi
301 336
302set -e 337set -e
303 338
304builddir=_build
305mkdir -p "$builddir" 339mkdir -p "$builddir"
306 340
307if [ "$UID" = 0 ]
308then sudo=
309else sudo=sudo
310fi
311
312if [ "$SKIP_ROOTFS_COPY" ] 341if [ "$SKIP_ROOTFS_COPY" ]
313then 342then
314 target=key.img 343 target=key.img
@@ -316,7 +345,11 @@ else
316 target=whole.img 345 target=whole.img
317fi 346fi
318 347
319iterate_partitions build_partition_image 348
349
350
351
352
320 353
321if whole=$(losetup -j "$target" -O NAME --noheadings) 354if whole=$(losetup -j "$target" -O NAME --noheadings)
322then 355then
@@ -324,43 +357,30 @@ then
324 whole= 357 whole=
325fi 358fi
326truncate -s0 "$target" 359truncate -s0 "$target"
327iterate_partitions clone_parts_to_target 360iterate_partitions build_partition_image
361
362
328 363
364
365iterate_partitions clone_parts_to_target
329$sudo losetup -L -f "$target" 366$sudo losetup -L -f "$target"
330whole=$(losetup -j "$target" -O NAME --noheadings) 367whole=$(losetup -j "$target" -O NAME --noheadings)
368
369
370
371
372
373
374
331pee_on_table "$whole" 375pee_on_table "$whole"
332$sudo kpartx -su "$whole"
333 376
334trap cleanup EXIT
335 377
336copy_data_to_mounted_target_filesystems()
337{
338 case "$type" in
339 efi-system-partition|boot|samizdat-keys) ;;
340 dm-verity-hashes|partition-table|bios-grub) return ;;
341 *) notice "Not mounting $name"; return ;;
342 esac
343 378
344 img=${f%.conf}
345 dev=/dev/mapper/${whole#/dev/}p${img#part}
346 mnt=${f%.conf}.mnt
347 379
348 mkdir -p "$mnt"
349 loudly $sudo mount "$dev" "$mnt"
350 380
351 case "$type" in 381trap cleanup EXIT
352 boot) 382$sudo kpartx -su "$whole"
353 BOOT_DIR=$mnt 383
354 install_boot_dir "$mnt"
355 ;;
356 samizdat-keys)
357 $sudo rsync -a --info=STATS "$GPG_INPUT_DIR"/ "$mnt"/gnupghome/
358 ;;
359 efi-system-partition)
360 EFI_DIR=$mnt
361 ;;
362 esac
363}
364iterate_partitions copy_data_to_mounted_target_filesystems 384iterate_partitions copy_data_to_mounted_target_filesystems
365 385
366loudly $sudo eatmydata -- grub-install --target=i386-pc --recheck --boot-directory="$BOOT_DIR" "$whole" 386loudly $sudo eatmydata -- grub-install --target=i386-pc --recheck --boot-directory="$BOOT_DIR" "$whole"