Browse Source

Support mounting and unmounting target only

The MMGen Project 4 years ago
parent
commit
23aa04c94b
1 changed files with 39 additions and 7 deletions
  1. 39 7
      scripts/armbian_rootenc_setup.sh

+ 39 - 7
scripts/armbian_rootenc_setup.sh

@@ -52,6 +52,8 @@ print_help() {
              '-m'  Add all currently loaded modules to the initramfs (may help
              '-m'  Add all currently loaded modules to the initramfs (may help
                    fix blank screen on bootup issues)
                    fix blank screen on bootup issues)
              '-o'  Add specified modules to the initramfs (comma-separated list)
              '-o'  Add specified modules to the initramfs (comma-separated list)
+             '-M'  Mount source and target systems and exit
+             '-U'  Unmount source and target systems and exit
              '-p'  Partition and create filesystems only.  Do not copy data
              '-p'  Partition and create filesystems only.  Do not copy data
              '-R'  Force reformat of encrypted root partition
              '-R'  Force reformat of encrypted root partition
              '-s'  Use 'authorized_keys' file from working directory, if available
              '-s'  Use 'authorized_keys' file from working directory, if available
@@ -251,6 +253,12 @@ check_sdcard_name_and_params() {
 _get_user_var() {
 _get_user_var() {
 	local var desc dfl prompt pat pat_errmsg vtest cprompt seen_prompt reply redo
 	local var desc dfl prompt pat pat_errmsg vtest cprompt seen_prompt reply redo
 	var=$1 desc=$2 dfl=$3 prompt=$4 pat=$5 pat_errmsg=$6 vtest=$7
 	var=$1 desc=$2 dfl=$3 prompt=$4 pat=$5 pat_errmsg=$6 vtest=$7
+
+	[ "$MOUNT_TARGET_ONLY" ] && [[ ! $var =~ ^(DISK_PASSWD|ROOTFS_NAME)$ ]] && {
+		eval "$var=$dfl"
+		return 0
+	}
+
 	while true; do
 	while true; do
 		if [ -z "${!var}" -o "$seen_prompt" -o "$redo" ]; then
 		if [ -z "${!var}" -o "$seen_prompt" -o "$redo" ]; then
 			if [ "$seen_prompt" ]; then
 			if [ "$seen_prompt" ]; then
@@ -326,11 +334,16 @@ _get_user_vars() {
 		"Name must contain no more than 48 characters in the set 'a-z0-9_'" \
 		"Name must contain no more than 48 characters in the set 'a-z0-9_'" \
 		'_test_rootfs_mounted'
 		'_test_rootfs_mounted'
 
 
-	_get_user_var 'DISK_PASSWD' 'disk password' '' \
-		"Choose a simple disk password for the installation process.
+	if [ "$MOUNT_TARGET_ONLY" ]; then
+		local pw_prompt="Enter disk password:"
+	else
+		local pw_prompt="Choose a simple disk password for the installation process.
 		Once your encrypted system is up and running, you can change
 		Once your encrypted system is up and running, you can change
 		the password using the 'cryptsetup' command.
 		the password using the 'cryptsetup' command.
-		Enter password:" \
+		Enter password:"
+	fi
+
+	_get_user_var 'DISK_PASSWD' 'disk password' '' "$pw_prompt" \
 		'^[A-Za-z0-9_ ]{1,10}$' \
 		'^[A-Za-z0-9_ ]{1,10}$' \
 		"Temporary disk password must contain no more than 10 characters in the set 'A-Za-z0-9_ '"
 		"Temporary disk password must contain no more than 10 characters in the set 'A-Za-z0-9_ '"
 
 
@@ -1125,19 +1138,29 @@ _set_env_vars() {
 	shopt -u extglob
 	shopt -u extglob
 }
 }
 
 
+_mount_target_and_exit() {
+	setup_loopmount
+	mount_target
+	_set_target_vars
+	rmdir $BOOT_ROOT
+	exit
+}
+
 # begin execution
 # begin execution
 
 
 set -e
 set -e
 
 
-while getopts hCdmofFpRsuvz OPT
+while getopts hCfFmo:MUpRsudvz OPT
 do
 do
 		case "$OPT" in
 		case "$OPT" in
 			h)  print_help; exit ;;
 			h)  print_help; exit ;;
 			C)  NO_CLEANUP='y' ;;
 			C)  NO_CLEANUP='y' ;;
-			F)  FORCE_REBUILD='y' ;;
 			f)  FORCE_RECONFIGURE='y' ;;
 			f)  FORCE_RECONFIGURE='y' ;;
+			F)  FORCE_REBUILD='y' ;;
 			m)  ADD_ALL_MODS='y' ;;
 			m)  ADD_ALL_MODS='y' ;;
 			o)  ADD_MODS=$OPTARG ;;
 			o)  ADD_MODS=$OPTARG ;;
+			M)  MOUNT_TARGET_ONLY='y' ;;
+			U)  UMOUNT_TARGET_ONLY='y' ;;
 			p)  PARTITION_ONLY='y' ;;
 			p)  PARTITION_ONLY='y' ;;
 			R)  FORCE_REFORMAT_ROOT='y' ;;
 			R)  FORCE_REFORMAT_ROOT='y' ;;
 			s)  USE_LOCAL_AUTHORIZED_KEYS='y' ;;
 			s)  USE_LOCAL_AUTHORIZED_KEYS='y' ;;
@@ -1185,17 +1208,26 @@ else
 	_do_header
 	_do_header
 	_set_host_vars
 	_set_host_vars
 	get_armbian_image
 	get_armbian_image
-	apt_install_host # we need cryptsetup in next cmd
+	apt_install_host # _preclean requires cryptsetup
 	_preclean
 	_preclean
+
+	[ "$UMOUNT_TARGET_ONLY" ] && exit
+
 	check_sdcard_name_and_params $ARG1
 	check_sdcard_name_and_params $ARG1
+	create_build_dir
+
+	[ "$MOUNT_TARGET_ONLY" ] && warn 'Mounting source and target and exiting at user request'
+
 	_get_user_vars
 	_get_user_vars
 	_test_sdcard_mounted
 	_test_sdcard_mounted
+
+	[ "$MOUNT_TARGET_ONLY" ] && _mount_target_and_exit
+
 	_warn_user_opts
 	_warn_user_opts
 	_confirm_user_vars
 	_confirm_user_vars
 
 
 	[ "$IP_ADDRESS" == 'none' ] || get_authorized_keys
 	[ "$IP_ADDRESS" == 'none' ] || get_authorized_keys
 
 
-	create_build_dir
 	[ "$NO_CLEANUP" ] || trap '_clean' EXIT
 	[ "$NO_CLEANUP" ] || trap '_clean' EXIT
 
 
 	setup_loopmount
 	setup_loopmount