diff --git a/lib/block-device.sh b/lib/block-device.sh index 31e5b91..f338caf 100644 --- a/lib/block-device.sh +++ b/lib/block-device.sh @@ -8,10 +8,11 @@ # -x, --sort column function get_uuid() { - # arg $1: partition - # arg $2: variable name to store UUID + # arg $1: Partition + # arg $2: Variable name to store UUID local -n ptr=$2 || return $? + # shellcheck disable=SC2034 ptr="$(blkid -o value -s UUID "${1}")" || return $? } @@ -41,7 +42,7 @@ function get_block_devices_with_size() { # @post # BLOCK_DEVICE_SIZES (array with two entries for each block device: device path and device size) - # Get list of devices and their sizes, one pair per line + # Get list of devices and their sizes, one pair per line. # Use sed to remove multiple white spaces: sed 's|\s\s*| |' BLOCK_DEVICE_SIZES="$(lsblk -dplnx size -o name,size | grep -Ev 'boot|rpmb|loop' | sed 's|\s\s*| |' | tac)" || return $? @@ -62,9 +63,9 @@ function partition() { # BOOT_PART # LUKS_PART - # if BOOT_PART_SIZE not given, set to default value + # If BOOT_PART_SIZE not given, set to default value BOOT_PART_SIZE="${BOOT_PART_SIZE:='261'}" - # if too small, print warning and exit + # If too small, print warning and exit if [ "${BOOT_PART_SIZE}" -lt '261' ]; then echo 'BOOT_PART_SIZE should be larger than 260!'; return 1; @@ -156,7 +157,7 @@ function format() { luks_name=$(basename "${LUKS_PART}") DATA_PART="/dev/mapper/${luks_name}" - # open luks partition + # Open luks partition printf '%s' "${LUKS_PWD}" | sudo cryptsetup luksOpen "${LUKS_PART}" "${luks_name}" || return $? ;; false) diff --git a/lib/user-input.sh b/lib/user-input.sh index 85b5dfb..544d82f 100644 --- a/lib/user-input.sh +++ b/lib/user-input.sh @@ -4,8 +4,8 @@ function ask_user_if_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 $2: text to display (e.g. "Enter hostname:") + # arg $1: Name of variable to store user input + # arg $2: Text to display (e.g. "Enter hostname:") if [ "$#" -ne 2 ]; then echo 'ask_user_if_empty requires two args!'; return 1 @@ -19,12 +19,12 @@ function ask_user_if_empty { local -n ptr=$1 || return $? if [ -z "${ptr}" ]; then - # if ptr has no value yet, ask user for input! + # If ptr has no value yet, ask user for input! echo "${2}" read -r ptr || return $? fi - # check string length to be greater than zero! + # Check string length to be greater than zero! if [ "${#ptr}" -lt 1 ]; then echo 'The input must not be empty!'; return 1; @@ -34,9 +34,9 @@ function ask_user_if_empty { function single_choice_if_empty { # 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 $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 $1: Name of variable to store the selected option + # 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) if [ "$#" -ne 3 ]; then echo 'single_choice_if_empty requires three args!'; return 1 @@ -51,7 +51,7 @@ function single_choice_if_empty { local -n ptr=$1 || return $? if [ -z "${ptr}" ]; then - # if ptr has no value yet, ask user for input! + # If ptr has no value yet, ask user for input! local -n MENU_OPTIONS=$3 || return $? ptr=$(dialog --stdout --menu "${2}" 0 0 0 "${MENU_OPTIONS[@]}") || { @@ -65,9 +65,9 @@ function single_choice_if_empty { function multi_choice_if_empty { # 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 $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 $1: Name of variable to store array of selected options + # 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) if [ "$#" -ne 3 ]; then echo 'multi_choice_if_empty requires three args!'; return 1 @@ -82,17 +82,18 @@ function multi_choice_if_empty { local -n ptr=$1 || return $? if [ -z "${ptr}" ]; then - # if ptr has no value yet, ask user for input! + # If ptr has no value yet, ask user for input! local -n MENU_OPTIONS=$3 || return $? + # shellcheck disable=SC2034 # Variable name used below. TMP1=$(dialog --stdout --checklist "${2}" 0 0 0 "${MENU_OPTIONS[@]}") || { echo 'Error during menu selection!' exit 1 } clear - # Result of dialog is space separated list - # Store this as an array + # Result of dialog is a space separated list. + # Store this as an array. # Without newline at last array element: https://unix.stackexchange.com/a/519917/315162 # readarray -d " " -t ptr < <(printf '%s' "$TMP1") # diff --git a/lib/util.sh b/lib/util.sh index daabba9..2dff9ce 100644 --- a/lib/util.sh +++ b/lib/util.sh @@ -1,9 +1,9 @@ function join_by() { # Join array elements with character $1 # - # arg $1: delimiter - # arg $2: name of source array - # arg $3: variable name to store result + # arg $1: Delimiter + # arg $2: Name of source array + # arg $3: Variable name to store result local -n ptr=$2 || return $? local -n ptr2=$3 || return $? @@ -14,10 +14,10 @@ function join_by() { function newline_to_space() { # Replaces all newlines with spaces # - # arg $1: name of variable + # arg $1: Name of variable local -n ptr=$1 || return $? - # Replace newlines with spaces + # Replace newlines with spaces. # See bash string substitution: https://gist.github.com/JPvRiel/b279524d3e56229a896477cb8082a72b # echo "replacing newlines in str: -->$ptr<--" @@ -27,10 +27,10 @@ function newline_to_space() { function newline_separated_to_array() { # Watch out for tailing newlines as these will get an empty array entry at the end. - # $1 and $2 can be equal (if the result shall be written to the input variable) + # $1 and $2 can be equal (if the result shall be written to the input variable). # - # arg $1: name of variable with newline separated list - # arg $2: name of array to store values into + # arg $1: Name of variable with newline separated list + # arg $2: Name of array to store values into local -n ptr=$1 || return $? local -n ptr2=$2 || return $? @@ -40,8 +40,8 @@ function newline_separated_to_array() { } function space_separated_to_array() { - # arg $1: name of variable with space separated list - # arg $2: name of array to store values into + # arg $1: Name of variable with space separated list + # arg $2: Name of array to store values into local -n ptr=$1 || return $? # shellcheck disable=SC2178 @@ -60,7 +60,7 @@ function get_cpu_vendor() { if [[ -z "${CPU_VENDOR}" ]] || [[ "${CPU_VENDOR}" == 'autodetect' ]]; then - # If run virtual environment (e.g. VirtualBox) then no CPU microcode is required + # If run virtual environment (e.g. VirtualBox) then no CPU microcode is required. if grep '^flags.*hypervisor' /proc/cpuinfo >/dev/null; then echo 'Detected virtual environment.' CPU_VENDOR='none'