diff options
author | bill-auger <mr.j.spam.me@gmail.com> | 2022-05-14 08:34:47 -0400 |
---|---|---|
committer | bill-auger <mr.j.spam.me@gmail.com> | 2022-08-16 08:12:57 -0400 |
commit | 17fef675231e6c5dca0203027aa68ed13f2b4ccb (patch) | |
tree | 141bacc97a7712c140994ff3a20c13f7cc25685a | |
parent | 2f18030412ea5a25c0212685a647150772ebb6b7 (diff) |
housekeeping
-rwxr-xr-x | install.sh | 43 | ||||
-rw-r--r-- | session-common.sh.inc | 132 | ||||
-rwxr-xr-x | session-init.sh | 12 |
3 files changed, 113 insertions, 74 deletions
@@ -39,9 +39,9 @@ source $(cd $(dirname ${BASH_SOURCE[0]}) ; pwd)/session-common.sh.inc # sets: $Lang -declare -r -A KEYRINGS=( [armv7l]='archlinux-keyring parabola-keyring archlinuxarm-keyring' - [i686]=' archlinux-keyring parabola-keyring archlinux32-keyring ' - [x86_64]='archlinux-keyring parabola-keyring ') +declare -r -A KEYRINGS=( [armv7l]='archlinux-keyring parabola-keyring archlinuxarm-keyring' \ + [i686]=' archlinux-keyring parabola-keyring archlinux32-keyring' \ + [x86_64]='archlinux-keyring parabola-keyring' ) declare -r -A BASE_PACKAGES=( [core]='base' \ [standard]='base parabola-base' ) declare -r -A BOOT_PACKAGES=( [grub]='grub grub2-theme-gnuaxiom' ) @@ -64,10 +64,11 @@ Init() # MOCK_INIT ; return 0 ; # sanity checks - while [[ -z "$(GetStateVar 'XKBMAP')" ]] || - [[ -z "$(GetStateVar 'LANG' )" ]] || - [[ -z "$(GetStateVar 'TR_KEY')" ]] - do "${THIS_DIR}"/session-init.sh + while [[ -z "$(GetStateVar 'LANG' )" || + -z "$(GetStateVar 'TR_KEY' )" || + -z "$(GetStateVar 'XKBMAP' )" ]] + do SetStateVar 'SESSION' 'wizard' + "${THIS_DIR}"/session-init.sh done SetLang $(GetStateVar 'TR_KEY') @@ -165,8 +166,8 @@ SelectLogins() local login='' dlg_title="${dlg_title/*) /}" # trim "(Optional) " until ValidateId "${login}" - do login=$( WizardDlg "${dlg_title}" \ - --inputbox "${TR[user_login-${Lang}]}" 8 56 ${login/ *} ) + do login=$( WizardDlg "${dlg_title}" \ + --inputbox "${TR[user_login-${Lang}]}" 8 56 ${login/ */} ) [[ -n "${login}" ]] || exit done @@ -183,7 +184,7 @@ SelectBase() # checks to skip this stage per SelectDefaults() [[ -z "$(GetStateVar 'BASE')" || -z "$(GetStateVar 'INIT')" ]] || return 0 - # prompt for local vs remote package repos if possible + # prompt for local vs remote package repos, if possible local install=$( [[ "$(GetStateVar 'INSTALL')" != 'prompt' ]] && \ echo $(GetStateVar 'INSTALL') || \ WizardDlg "${TR[dlg_base-${Lang}]}" \ @@ -263,8 +264,8 @@ SelectEnv() local hostname='' local display_host until ValidateId "${hostname}" - do display_host=$( [[ -n "${hostname}" ]] && echo ${hostname/ *} || \ - echo ${DEF_HOSTNAME} ) + do display_host=$( [[ -n "${hostname}" ]] && echo ${hostname/ */} || \ + echo ${DEF_HOSTNAME} ) hostname=$( WizardDlg "${TR[dlg_env-${Lang}]}" \ --inputbox "${TR[hostname-${Lang}]}" 8 56 \ ${display_host} ) @@ -351,6 +352,7 @@ SelectEnv() SelectPartition() { + # prepare for partition probe umount /mnt &> /dev/null || true # query disk device information @@ -358,8 +360,9 @@ SelectPartition() (( ${#DlgParams[@]} )) || ExitFail "${TR[device_none-${Lang}]}" # prompt for disk device - local device_n=$( WizardDlg "${TR[dlg_part-${Lang}]}" \ - --menu "${TR[device-${Lang}]}" 20 70 50 "${DlgParams[@]}" ) + local device_n=$( WizardDlg "${TR[dlg_part-${Lang}]}" \ + --menu "${TR[device-${Lang}]}" 20 70 50 \ + "${DlgParams[@]}" ) local device=$( GetDevice $(( ${device_n} - 1 )) ) [[ -n "${device_n}" ]] && SetStateVar 'DEVICE_N' ${device_n} || exit [[ -n "${device}" ]] && SetStateVar 'DEVICE' ${device} || exit @@ -375,6 +378,7 @@ SelectPartition() NoticeReady() { local ready_msg="${TR[notice_ready-${Lang}]}" + if [[ "$(GetStateVar 'PART_METHOD')" == 'auto' ]] then ready_msg+="\n\n\Z1${TR[ready_warn-${Lang}]}\Zn\n\n * $(GetStateVar 'DEVICE')" fi @@ -469,10 +473,6 @@ _PartitionManual() Partition() { - # sanity checks - [[ -n "$(GetStateVar 'DEVICE' )" ]] - [[ -n "$(GetStateVar 'PART_METHOD')" ]] - # switch automatic/manual partitioning [[ "$(GetStateVar 'PART_METHOD')" == 'auto' ]] && _PartitionAuto || _PartitionManual @@ -485,7 +485,7 @@ Partition() local partition local dlg_msg - # format un-formatted partitions and mount partitions + # format un-formatted partitions umount /mnt/boot &> /dev/null || true umount /mnt/home &> /dev/null || true umount /mnt &> /dev/null || true @@ -509,6 +509,7 @@ Partition() fi done + # mount partitions if [[ -n "${partitions[Root]}" ]] ; then mkdir -p /mnt ; mount ${partitions[Root]} /mnt ; fi ; if [[ -n "${partitions[Boot]}" ]] ; then mkdir -p /mnt/boot ; @@ -529,8 +530,8 @@ InstallPkgs() local conf_regex=$( [[ "${init}" == 'openrc' ]] && echo "$PACCONF_NONSYSTEMD_REGEX" || \ echo "$PACCONF_SYSTEMD_REGEX" ) local install=$( GetStateVar 'INSTALL') - local init=$( GetStateVar 'INIT' ) local base_set=$( GetStateVar 'BASE' ) + local init=$( GetStateVar 'INIT' ) local bootloader=$(GetStateVar 'BOOT' ) local wmde=$( GetStateVar 'WMDE' ) local base_packages="${BASE_PACKAGES[${base_set}]}" @@ -627,6 +628,6 @@ Partition # Partition and mount target disks (may or may not be interactiv InstallPkgs # Install packages with pacstrap ConfigChroot # Generate fstab, register login, configure services (in-chroot) NoticeDone # Yay!!! -Cleanup # Clean-up and un-mount the chroot (non-interactive) +Cleanup # Clean-up and un-mount the chroot exit diff --git a/session-common.sh.inc b/session-common.sh.inc index e847b4c..4af8e20 100644 --- a/session-common.sh.inc +++ b/session-common.sh.inc @@ -22,6 +22,7 @@ readonly THIS_DIR="$(cd $(dirname ${BASH_SOURCE[0]}) ; pwd)" +# defaults readonly DEF_KEYMAP='us' readonly DEF_LANG='en_US.UTF-8' readonly DEF_TRKEY='en' @@ -70,14 +71,20 @@ GetStateVar() # (var_name [def_value]) ## dialog prompt helpers ## # WizardDlg() notes: -# the primary purpose of the WizardDlg() function is to simplify and normalize -# creation of various dialog boxes, such that they acan all be handled uniformly. +# the primary purpose of the WizardDlg() function, is to simplify and normalize +# creation of various dialog boxes, such that they can all be handled uniformly. +# +# in order for this to work properly, callers of WizardDlg() should pass the +# box-type argument (eg: --menu, --yesno, --inputbox) as positional parameter #2, +# followed by it's box-specific options. additional dialog options may be set +# via the 'DIALOGOPTS' environment variable. # # when the "Cancel" button or <ESC> key is pressed, in a 'msgbox', # 'dialog' exits with a non-zero status; and no result is printed. # install.sh runs under `set -e`; so we can not propogate the non-zero status, # otherwise, all callers of these helpers would need to supress it. # callers should instead, exit upon the empty result, when a selection is mandatory. +# # because an 'inputbox' may be blank, when the "OK" button is pressed, we emit a space, # in order to maintain the invariant, such that the "OK" result is never empty. # @@ -94,7 +101,7 @@ GetStateVar() # (var_name [def_value]) readonly CANCEL_STATUS=1 readonly CANCEL_SENTINEL='CANCEL' -# dialog prompts for session-init.sh +# dialog prompt for session-init.sh (with auto-accept timeout) InitDlg() # (title prompt default_option options*) { local title="$1" @@ -102,31 +109,31 @@ InitDlg() # (title prompt default_option options*) local default_option="$3" local options=("${@:4}") - dialog --stdout --sleep 1 --timeout 30 --no-tags --no-cancel \ - --backtitle "$title" \ - --default-item "${default_option}" \ - --menu "$prompt" $H $W $N_ITEMS "${options[@]}" + dialog --stdout --sleep 1 --no-tags --no-cancel --timeout 30 \ + --backtitle "${title}" \ + --default-item "${default_option}" \ + --menu "${prompt}" 15 42 10 \ + "${options[@]}" } # dialog prompts for install.sh -WizardDlg() # (title dialog_args*) +WizardDlg() # (title box_type boxargs* options*) { - # ASSERT: all callers should pass the dialog type as positional parameter #2 - local title="$1" - local options=("${@:2}") - local dialog_type=${options[0]} + local dialog_type=$2 + local boxargs_and_options=("${@:3}") local result local status - result=$( DIALOG_ESC=${CANCEL_STATUS} \ - dialog --stdout --insecure --sleep 1 \ - --colors --erase-on-exit \ - --backtitle "${TR[wizard-${Lang}]}" \ - --title "${title}" \ - "${options[@]}" ) && status=$? || status=$? - clear >&2 + result=$( DIALOG_ESC=${CANCEL_STATUS} \ + dialog --stdout --insecure --sleep 1 \ + --colors --erase-on-exit \ + --backtitle "${TR[wizard-${Lang}]}" \ + --title "${title}" \ + ${dialog_type} "${boxargs_and_options[@]}" ) && status=$? || status=$? + #clear >&2 + # NOTE: a failure on the following LOC, indicates a bug in the caller code (( ! status || status == CANCEL_STATUS )) if [[ "${dialog_type}" == '--menu' ]] @@ -144,7 +151,9 @@ WizardDlg() # (title dialog_args*) elif [[ "${dialog_type}" == '--checklist' ]] then (( status != CANCEL_STATUS )) && echo "${result}" || echo ${CANCEL_SENTINEL} - elif [[ "${dialog_type}" == '--msgbox' ]] + elif [[ "${dialog_type}" == '--msgbox' ]] || + [[ "${dialog_type}" == '--progressbox' ]] || + [[ "${dialog_type}" == '--textbox' ]] then echo '' else echo "unhandled dialog_type: ${dialog_type}" >&2 @@ -174,7 +183,7 @@ ExitFail() # ("exit_msg") ## partitioning helpers ## readonly DISK_RECORD_SEP='|' -readonly DISK_FIELD_SEP=',' +readonly DISK_FIELD_SEP=':' declare -A PartsData # raw data declare -a DlgParams # dialog options @@ -183,31 +192,62 @@ GetDisksPartsData() { local line local dev + local size + local part_n local format - # example parted output: + # example parted output (GPT): + # BYT; + # /dev/sda:1074MB:scsi:512:512:gpt:ATA QEMU HARDDISK:; # QEMU device + # 1:1049kB:106MB:105MB:ext4::; # EXT4 partition + # 2:106MB:211MB:105MB:::; # un-formatted partition + # # <-- ~800MB unallocated space + # + # example parted output (MBR): + # BYT; + # /dev/sdb:250GB:scsi:512:512:msdos:ATA ST3250318AS:; # hardware device + # 1:1049kB:525MB:524MB:ntfs::boot; # windows boot partition + # 2:525MB:20.5GB:20.0GB:ntfs::; # windows system partition + # 4:20.5GB:249GB:228GB:::lvm; # LLVM partition + # 3:249GB:250GB:1049MB:ntfs::msftres; # windows data partition + # + # NOTE: the example /dev/sdb is a typical windows partition scheme, where partition #2 was shrunken, + # partition #3 was deleted, and a *nix partition (#4) was added + # + # example parted output (multiple devices, no partition table on sdb): # BYT; - # /dev/sdb:9664MB:scsi:512:512:msdos:ATA X HARDDISK:; - # 1:1049kB:9663MB:9662MB:ext4::; # formatted - # 1:9663MB:9664MB:1048kB:::; # un-formatted - # example output: - # /dev/sda:42.9GB|/dev/sda1:42.9GB:ext4 - # /dev/sdb:9664MB|/dev/sdb1:9662MB:ext4|/dev/sdb2:1048kB - sudo parted --list --machine | \ + # /dev/sda:42.9GB:scsi:512:512:msdos:ATA QEMU HARDDISK:; + # 1:1049kB:42.9GB:42.9GB:ext4::; + # + # BYT; + # /dev/sdb:1074MB:scsi:512:512:unknown:ATA QEMU HARDDISK:; + # + # NOTE: in the 'BYT;' line of the example /dev/sdb, + # all of those spaces and a stray CR are present in the output + # ' \rBYT;' + # + # example GetDisksPartsData() output: + # /dev/sda:1074MB|/dev/sda1:105MB:ext4|/dev/sda2:105MB + # /dev/sdb:250GB|/dev/sdb1:524MB:ntfs|/dev/sdb2:20.0GB:ntfs|/dev/sdb4:228GB:|/dev/sdb3:1049MB:ntfs + + parted --list --machine 2> /dev/null | tr -d '\r' | \ while read line - do - if [[ "${line}" == 'BYT;' ]] - then echo ' ' - else if [[ "${line}" =~ ^(/dev/sd[a-z]):([^:]*): ]] - then dev="${BASH_REMATCH[1]}" - echo -n "${dev}${DISK_FIELD_SEP}${BASH_REMATCH[2]}" - elif [[ "${line}" =~ ^([0-9]):[^:]*:[^:]*:([^:]*):([^:]*): ]] - then format=$( [[ -n "${BASH_REMATCH[3]}" ]] && echo ${BASH_REMATCH[3]} || : ) - echo -n "${DISK_RECORD_SEP}${dev}${BASH_REMATCH[1]}" - echo -n "${DISK_FIELD_SEP}${BASH_REMATCH[2]}" - echo -n "${DISK_FIELD_SEP}${format}" - fi - fi + do if [[ "$line" =~ ^BYT\;\ *$ ]] # device delimiter + then echo ' ' + + elif [[ "${line}" =~ ^(/dev/sd[a-z]):([^:]*): ]] # device specifier + then dev="${BASH_REMATCH[1]}" + size="${BASH_REMATCH[2]}" + echo -n "${dev}${DISK_FIELD_SEP}${size}" + + elif [[ "${line}" =~ ^([0-9]):[^:]*:[^:]*:([^:]*):([^:]*): ]] # partition specifier + then part_n=${BASH_REMATCH[1]} + size=${BASH_REMATCH[2]} + format=$( [[ -n "${BASH_REMATCH[3]}" ]] && echo ${BASH_REMATCH[3]} || : ) + echo -n "${DISK_RECORD_SEP}${dev}${part_n}" + echo -n "${DISK_FIELD_SEP}${size}" + echo -n "${DISK_FIELD_SEP}${format}" + fi done } @@ -250,7 +290,7 @@ GetDevice() # (disk_data_n) echo ${device} } -PopulatePartsData() # (disk_data_n) # modifies $PartsData +PopulatePartsData() # (disk_data_n) # sets $PartsData { local disk_data_n=$1 local disk_parts_data=( $(GetDiskPartsData ${disk_data_n}) ) @@ -271,7 +311,7 @@ PopulatePartsData() # (disk_data_n) # modifies $PartsData done } -PopulateDisksOptions() # modifies $DlgParams +PopulateDisksOptions() # sets $DlgParams { local disks_part_data=( $(GetDisksPartsData) ) local disk_data_n @@ -284,7 +324,7 @@ PopulateDisksOptions() # modifies $DlgParams done } -PopulatePartOptions() # (device_n) +PopulatePartOptions() # (device_n) # sets $DlgParams { local dlg_device_n=$1 local part_data_n @@ -296,7 +336,7 @@ PopulatePartOptions() # (device_n) done } -RemoveOption() # (part_n) +RemoveOption() # (part_n) # modifies $PartsData { local dlg_part_n=$1 unset 'PartsData['"${dlg_part_n}"']' diff --git a/session-init.sh b/session-init.sh index c9a0dca..2cf259a 100755 --- a/session-init.sh +++ b/session-init.sh @@ -33,11 +33,6 @@ source $(cd $(dirname ${BASH_SOURCE[0]}) ; pwd)/session-common.sh.inc # sets: $Lang -readonly TIMEOUT=30 -readonly H=15 -readonly W=42 -readonly N_ITEMS=10 - readonly LANG_TITLE="System language selection" readonly LANG_PROMPT="Select your language:" readonly -a LANGUAGES=( $(sort -u "${THIS_DIR}"/LANGUAGES) ) @@ -76,7 +71,8 @@ fi Keymap=$(GetStateVar 'XKBMAP' '_UNDEFINED_') if [[ "${Keymap}" == '_UNDEFINED_' ]] -then Keymap=$( InitDlg "${TR[dlg_keymap-${Lang}]}" "${TR[keymap-${Lang}]}" ${DEF_KEYMAP} "${KEYMAPS[@]}" ) +then Keymap=$( InitDlg "${TR[dlg_keymap-${Lang}]}" "${TR[keymap-${Lang}]}" \ + ${DEF_KEYMAP} "${KEYMAPS[@]}" ) [[ "${Keymap}" == "" ]] && Keymap=${DEF_KEYMAP} logger "$0: selected keymap='${Keymap}'" @@ -88,9 +84,11 @@ fi ## prompt to launch installer or CLI ## + Session=$(GetStateVar 'SESSION' '_UNDEFINED_') if [[ "${Session}" == '_UNDEFINED_' ]] -then Session=$( InitDlg "${TR[dlg_session-${Lang}]}" "${TR[session-${Lang}]}" ${SESSION_DEFAULT} "${SESSIONS[@]}" ) +then Session=$( InitDlg "${TR[dlg_session-${Lang}]}" "${TR[session-${Lang}]}" \ + ${SESSION_DEFAULT} "${SESSIONS[@]}" ) [[ "${Session}" == "" ]] && Session=${SESSION_DEFAULT} logger "$0: selected interface='${Session}'" |