From 006e0ab404ddc0878aa331b8ab55c4bc5fa48155 Mon Sep 17 00:00:00 2001 From: The MMGen Project Date: Fri, 9 Apr 2021 11:05:07 +0000 Subject: [PATCH] Add -R option and FORCE_REFORMAT_ROOT env var --- scripts/armbian_rootenc_setup.sh | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/scripts/armbian_rootenc_setup.sh b/scripts/armbian_rootenc_setup.sh index cbacfb0..d54d1f4 100755 --- a/scripts/armbian_rootenc_setup.sh +++ b/scripts/armbian_rootenc_setup.sh @@ -1,5 +1,6 @@ #!/bin/bash +PATH="$PATH:/usr/sbin:/sbin" RED="\e[31;1m" GREEN="\e[32;1m" YELLOW="\e[33;1m" BLUE="\e[34;1m" PURPLE="\e[35;1m" RESET="\e[0m" PROGNAME=$(basename $0) TITLE='Armbian Encrypted Root Filesystem Setup' @@ -24,6 +25,7 @@ USER_OPTS_INFO=" NO_CLEANUP no cleanup of mounts after program run FORCE_REBUILD force full rebuild FORCE_RECONFIGURE force reconfiguration + FORCE_REFORMAT_ROOT force reformat of encrypted root partition ADD_ALL_MODS add all currently loaded modules to initramfs USE_LOCAL_AUTHORIZED_KEYS use local 'authorized_keys' file PARTITION_ONLY partition and create filesystems only @@ -46,6 +48,7 @@ print_help() { '-m' Add all currently loaded modules to the initramfs (may help fix blank screen on bootup issues) '-p' Partition and create filesystems only. Do not copy data + '-R' Force reformat of encrypted root partition '-s' Use 'authorized_keys' file from working directory, if available (see below) '-v' Be more verbose @@ -750,7 +753,7 @@ create_bootpart_label() { } copy_system_root() { - if ! cryptsetup isLuks "/dev/$ROOT_DEVNAME"; then + if [ "$FORCE_REFORMAT_ROOT" ] || ! cryptsetup isLuks "/dev/$ROOT_DEVNAME"; then pu_msg "Formatting encrypted root partition:" echo -n $DISK_PASSWD | cryptsetup luksFormat "/dev/$ROOT_DEVNAME" '-' fi @@ -1102,7 +1105,7 @@ _set_env_vars() { # begin execution -while getopts hCdmfFpsuvz OPT +while getopts hCdmfFpRsuvz OPT do case "$OPT" in h) print_help; exit ;; @@ -1111,6 +1114,7 @@ do f) FORCE_RECONFIGURE='y' ;; m) ADD_ALL_MODS='y' ;; p) PARTITION_ONLY='y' ;; + R) FORCE_REFORMAT_ROOT='y' ;; s) USE_LOCAL_AUTHORIZED_KEYS='y' ;; u) APT_UPGRADE='y' ;; d) DEBUG='y' ;&