installer: fix and refactor

This commit is contained in:
Daniel Langbein 2021-06-22 14:02:25 +02:00
parent 894473c306
commit d094f08f9d
3 changed files with 20 additions and 20 deletions

View File

@ -105,11 +105,10 @@ function get_user_input() {
# LUKS_PWD # LUKS_PWD
get_block_devices_with_size || return $? get_block_devices_with_size || return $?
get_single_choice TARGET_BLOCK_DEVICE 'Select target device for installation' BLOCK_DEVICE_SIZES || return $? single_choice_if_empty TARGET_BLOCK_DEVICE 'Select target device for installation' BLOCK_DEVICE_SIZES || return $?
ask_user_if_empty BOOT_FIRMWARE 'Enter desired boot firmware. Valid options are "bios", "uefi" or "autodetect":' || return $?
if [ "${BOOT_FIRMWARE}" = 'autodetect' ]; then if [ "${BOOT_FIRMWARE}" = 'autodetect' ]; then
# Detect BIOS type: https://askubuntu.com/a/162573 # Detect boot firmware type: https://askubuntu.com/a/162573
# Check exit code; if 0 EFI, else BIOS. # Check exit code; if 0 EFI, else BIOS.
# "-q": tell grep to output nothing # "-q": tell grep to output nothing
@ -122,14 +121,14 @@ function get_user_input() {
fi fi
else else
# Let user select BIOS type # If $BOOT_FIRMWARE is empty: Let user select BIOS type
TMP1=('uefi' 'Newer mainboards' 'bios' 'Legacy BIOS on older mainboards') TMP1=('uefi' 'Newer mainboards' 'bios' 'Legacy BIOS on older mainboards')
get_single_choice BOOT_FIRMWARE 'Select your bios type' TMP1 || return $? single_choice_if_empty BOOT_FIRMWARE 'Select your bios type' TMP1 || return $?
fi fi
TMP1=('BTRFS' 'Allows snapshots and dynamic extension of the FS' 'EXT4' 'Default FS of many distributions' 'F2FS' 'Flash-Friendly-FS for SSD or NVMe') TMP1=('BTRFS' 'Allows snapshots and dynamic extension of the FS' 'EXT4' 'Default FS of many distributions' 'F2FS' 'Flash-Friendly-FS for SSD or NVMe')
get_single_choice FS 'Select filesystem to use' TMP1 || return $? single_choice_if_empty FS 'Select filesystem to use' TMP1 || return $?
ask_user_if_empty HOSTNAME 'Enter hostname:' || return $? ask_user_if_empty HOSTNAME 'Enter hostname:' || return $?
ask_user_if_empty USERNAME 'Enter username:' || return $? ask_user_if_empty USERNAME 'Enter username:' || return $?
@ -216,7 +215,7 @@ function get_additional_mount_options() {
;; ;;
esac esac
get_multi_choice FS_ADDITIONAL_MOUNT_OPTIONS 'Select mount options' TMP1 || return $? multi_choice_if_empty FS_ADDITIONAL_MOUNT_OPTIONS 'Select mount options' TMP1 || return $?
} }
function run_pacstrap() { function run_pacstrap() {

View File

@ -6,11 +6,11 @@
HOSTNAME=yodaTest HOSTNAME=yodaTest
USERNAME=yoda USERNAME=yoda
# one should rather enter these interactively than saving in this cfg # One should rather enter these interactively than saving in this cfg.
USER_PWD=test USER_PWD=test
LUKS_PWD=test LUKS_PWD=test
# if unset, then USER_PWD will be used for ROOT_PWD # If unset, then USER_PWD will be used for ROOT_PWD
# ROOT_PWD=test # ROOT_PWD=test
TARGET_BLOCK_DEVICE=/dev/sda TARGET_BLOCK_DEVICE=/dev/sda

View File

@ -1,7 +1,8 @@
function ask_user_if_empty { function ask_user_if_empty {
# If variable with name $1 is zero, then ask user for input. # If variable with name $1 is empty, then ask for user input.
# Only one line user input is allowed. #
# User input must not be empty. # Only one line of user input is allowed.
# The input must not be empty.
# #
# arg $1: name of variable to store user input # arg $1: name of variable to store user input
# arg $2: text to display (e.g. "Enter hostname:") # arg $2: text to display (e.g. "Enter hostname:")
@ -30,19 +31,19 @@ function ask_user_if_empty {
fi fi
} }
function get_single_choice { function single_choice_if_empty {
# If variable with name $1 is zero, then ask user to select one option. # If variable with name $1 is empty, then let user select one of the given options.
# #
# arg $1: name of variable to store the selected option # arg $1: name of variable to store the selected option
# arg $2: text to display # arg $2: text to display
# arg $3: name of variable with array of options to display (for each option there must be two entries in the array: Item and description) # arg $3: name of variable with array of options to display (for each option there must be two entries in the array: Item and description)
if [ "$#" -ne 3 ]; then if [ "$#" -ne 3 ]; then
echo 'get_single_choice requires three args!'; echo 'single_choice_if_empty requires three args!';
return 1 return 1
fi fi
for i in "$@"; do for i in "$@"; do
if [ -z "${i}" ]; then if [ -z "${i}" ]; then
echo 'get_single_choice: all given args must not be empty'; echo 'single_choice_if_empty: all given args must not be empty';
return 1; return 1;
fi fi
done done
@ -61,19 +62,19 @@ function get_single_choice {
fi fi
} }
function get_multi_choice { function multi_choice_if_empty {
# If variable with name $1 is zero, then ask user to select one ore more options. # If variable with name $1 is empty, then let user select one or more of the given options.
# #
# arg $1: name of variable to store array of selected options # arg $1: name of variable to store array of selected options
# arg $2: text to display # arg $2: text to display
# arg $3: name of variable with array of options to display (for each option there must be three entries in the array: Item, description, on/off) # arg $3: name of variable with array of options to display (for each option there must be three entries in the array: Item, description, on/off)
if [ "$#" -ne 3 ]; then if [ "$#" -ne 3 ]; then
echo 'get_multi_choice requires three args!'; echo 'multi_choice_if_empty requires three args!';
return 1 return 1
fi fi
for i in "$@"; do for i in "$@"; do
if [ -z "${i}" ]; then if [ -z "${i}" ]; then
echo 'get_multi_choice: all given args must not be empty'; echo 'multi_choice_if_empty: all given args must not be empty';
return 1; return 1;
fi fi
done done