The MMGen Project 4 years ago
parent
commit
5d7a6433e7
1 changed files with 31 additions and 18 deletions
  1. 31 18
      scripts/armbian_rootenc_setup.sh

+ 31 - 18
scripts/armbian_rootenc_setup.sh

@@ -178,15 +178,17 @@ _do_header() {
 }
 }
 
 
 _warn_user_opts() {
 _warn_user_opts() {
-	local out
+	local out opt text
+
 	while read opt text; do
 	while read opt text; do
 		[ "$opt" ] || continue
 		[ "$opt" ] || continue
-		if [ $(eval echo -n \$$opt) ]; then out+="  + $text\n"; fi
-	done <<-EOF
-		$USER_OPTS_INFO
-	EOF
+		if [ "${!opt}" ]; then
+			out+="  + $text\n"
+		fi
+	done <<<$USER_OPTS_INFO
+
 	if [ "$out" ]; then
 	if [ "$out" ]; then
-		warn      "  The following user options are in effect:"
+		warn      "\n  The following user options are in effect:"
 		warn_nonl "${out}"
 		warn_nonl "${out}"
 	fi
 	fi
 }
 }
@@ -267,12 +269,22 @@ _get_user_var() {
 			rmsg "  $desc must not be empty"
 			rmsg "  $desc must not be empty"
 			continue
 			continue
 		}
 		}
+
 		if [ "$pat" ]; then
 		if [ "$pat" ]; then
-			echo "${!var}" | egrep -qi "$pat" || {
+			local rpat=$pat
+			if [ "$pat" == 'bool' ]; then
+				rpat='^[ynYN]*$'
+				pat_errmsg="You must type 'y' or 'n'"
+			fi
+			echo "${!var}" | egrep -qi "$rpat" || {
 				rmsg "  ${!var}: $pat_errmsg"
 				rmsg "  ${!var}: $pat_errmsg"
 				continue
 				continue
 			}
 			}
+			if [ "$pat" == 'bool' ]; then
+				if [[ ${!var} =~ ^[Yy]$ ]]; then eval "$var=yes"; else eval "$var="; fi
+			fi
 		fi
 		fi
+
 		if [ "$vtest" ]; then
 		if [ "$vtest" ]; then
 			$vtest || continue
 			$vtest || continue
 		fi
 		fi
@@ -281,11 +293,14 @@ _get_user_var() {
 }
 }
 
 
 _get_user_vars() {
 _get_user_vars() {
+
+	local dq='[0-9]{1,3}'
+
 	_get_user_var 'IP_ADDRESS' 'IP address' '' \
 	_get_user_var 'IP_ADDRESS' 'IP address' '' \
 		"Enter the IP address of the target machine.
 		"Enter the IP address of the target machine.
 		Enter 'dhcp' for a dynamic IP or 'none' for no remote SSH unlocking support
 		Enter 'dhcp' for a dynamic IP or 'none' for no remote SSH unlocking support
 		IP address:" \
 		IP address:" \
-		'^(dhcp|none|[0-9]{1,3}\.[0-9]{1,3}\.[0-9]+\.[0-9]{1,3})$' \
+		"^(dhcp|none|$dq\.$dq\.$dq\.$dq)$" \
 		'malformed IP address'
 		'malformed IP address'
 	IP_ADDRESS=${IP_ADDRESS,,}
 	IP_ADDRESS=${IP_ADDRESS,,}
 
 
@@ -326,10 +341,8 @@ _get_user_vars() {
 		"Unlock the disk from the serial console.  WARNING: enabling this will
 		"Unlock the disk from the serial console.  WARNING: enabling this will
 		make it impossible to unlock the disk using the keyboard and monitor,
 		make it impossible to unlock the disk using the keyboard and monitor,
 		though unlocking via SSH will still work.
 		though unlocking via SSH will still work.
-		Enable serial console unlocking? (y/n):" \
-		'^[ynYN]*$' \
-		"You must type 'y' or 'n'"
-	if [[ $SERIAL_CONSOLE =~ ^[Yy]$ ]]; then SERIAL_CONSOLE='yes'; else SERIAL_CONSOLE='no'; fi
+		Enable unlocking via serial console? (y/n):" \
+		'bool'
 
 
 	true
 	true
 }
 }
@@ -496,8 +509,8 @@ _confirm_user_vars() {
 	echo "  Target IP address:            $IP_ADDRESS"
 	echo "  Target IP address:            $IP_ADDRESS"
 	echo "  Boot partition label:         $BOOTPART_LABEL"
 	echo "  Boot partition label:         $BOOTPART_LABEL"
 	echo "  Disk password:                $DISK_PASSWD"
 	echo "  Disk password:                $DISK_PASSWD"
-	echo "  Serial console unlocking:     $SERIAL_CONSOLE"
-	[ "$UNLOCKING_USERHOST" ] && echo "  user@host of unlocking machine: $UNLOCKING_USERHOST"
+	[ "$UNLOCKING_USERHOST" ] && echo "  user@host of unlocking host:  $UNLOCKING_USERHOST"
+	echo "  Serial console unlocking:     ${SERIAL_CONSOLE:-no}"
 	echo
 	echo
 	_user_confirm '  Are these settings correct?' 'yes'
 	_user_confirm '  Are these settings correct?' 'yes'
 }
 }
@@ -529,9 +542,9 @@ _print_states() {
 _update_state_from_config_vars() {
 _update_state_from_config_vars() {
 	[ -e $CONFIG_VARS_FILE ] || return 0
 	[ -e $CONFIG_VARS_FILE ] || return 0
 	local reply
 	local reply
-	while read reply; do eval "c$reply"; done <<-EOF
-		$(cat $CONFIG_VARS_FILE)
-	EOF
+	while read reply; do
+		eval "c$reply"
+	done <<<$(cat $CONFIG_VARS_FILE)
 	local saved_states cfgvar_changed
 	local saved_states cfgvar_changed
 	saved_states="$(_print_states)"
 	saved_states="$(_print_states)"
 	cfgvar_changed=
 	cfgvar_changed=
@@ -700,7 +713,7 @@ copy_boot_loader() {
 
 
 _print_config_vars() {
 _print_config_vars() {
 	local outfile=$1
 	local outfile=$1
-	local data="$(for i in $CONFIG_VARS; do echo "$i=${!i}"; done)"
+	local data="$(for i in $CONFIG_VARS; do echo "$i='${!i}'"; done)"
 	if [ "$outfile" ]; then echo "$data" > $outfile; else echo "$data"; fi
 	if [ "$outfile" ]; then echo "$data" > $outfile; else echo "$data"; fi
 }
 }