diff options
author | bill-auger <mr.j.spam.me@gmail.com> | 2022-08-11 11:24:53 -0400 |
---|---|---|
committer | bill-auger <mr.j.spam.me@gmail.com> | 2022-08-16 08:12:58 -0400 |
commit | 4f240c279b1342a161d210b524c1dd0053ce1fe5 (patch) | |
tree | 9c69df6ebc2e436f35c13264ebb113ce850642c3 | |
parent | d557650872cff705db51dfdb0e2e440c4f52bbc7 (diff) |
generalize sanity checks
-rwxr-xr-x | install.sh | 79 | ||||
-rw-r--r-- | session-common.sh.inc | 40 |
2 files changed, 67 insertions, 52 deletions
@@ -59,7 +59,7 @@ NoticeIntro() # checks to skip this notice per preset config # NOTE: 'READY' is the signal for unattended install, per a preset config. # This program will not set the 'READY' state var. - [[ -n "$(GetStateVar 'READY')" ]] || + AreConfiguredStateVars 'READY' || WizardDlg "${TR[dlg_intro-${Lang}]}" --msgbox "${TR[notice_intro-${Lang}]}" 0 0 } @@ -81,11 +81,8 @@ Init() fi # sanity checks - while [[ -z "$(GetStateVar 'LANG' )" || - -z "$(GetStateVar 'TR_KEY' )" || - -z "$(GetStateVar 'XKBMAP' )" ]] - do SetStateVar 'SESSION' 'wizard' - "${THIS_DIR}"/session-init.sh + while ! AreConfiguredStateVars 'LANG' 'TR_KEY' 'XKBMAP' + do SetStateVar 'SESSION' 'wizard' ; "${THIS_DIR}"/session-init.sh ; done SetLang $(GetStateVar 'TR_KEY') @@ -114,6 +111,11 @@ InitKeyring() NoticeCustomize() { + # checks to skip this notice per preset or partial config + AreConfiguredStateVars ${STATEVARS_WMDE[*]} && # SelectDefaults() + AreConfiguredStateVars ${STATEVARS_ENV[*]} && # SelectDefaults() + AreConfiguredStateVars ${STATEVARS_LOGINS[*]} && # SelectLogins() + AreConfiguredStateVars ${STATEVARS_BASE[*]} || # SelectDefaults(), SelectBase() WizardDlg "${TR[dlg_customize-${Lang}]}" --msgbox "${TR[notice_customize-${Lang}]}" 0 0 } @@ -123,13 +125,7 @@ SelectDefaults() # MOCK_SELECTDEFAULTS_NO ; return 0 ; # exercise SelectBase, SelectWmde, SelectEnv # checks to skip this stage per preset or partial config - [[ -z "$(GetStateVar 'BASE' )" ]] || - [[ -z "$(GetStateVar 'INIT' )" ]] || - [[ -z "$(GetStateVar 'WMDE' )" ]] || - [[ -z "$(GetStateVar 'HOSTNAME')" ]] || - [[ -z "$(GetStateVar 'TIMEZONE')" ]] || - [[ -z "$(GetStateVar 'KEYMAP' )" ]] || - [[ -z "$(GetStateVar 'LOCALES' )" ]] || return 0 + ! AreConfiguredStateVars ${STATEVARS_DEFAUILTS[*]} || return 0 # prompt to select the default installation configuration # (bypasses many other prompts) @@ -174,9 +170,9 @@ SelectLogins() # MOCK_SELECTLOGINS ; return 0 ; # checks to skip this stage per preset or partial config - ! ValidateId "$(GetStateVar 'ROOT_PASS' )" || - ! ValidateId "$(GetStateVar 'USER_LOGIN')" || - ! ValidateId "$(GetStateVar 'USER_PASS' )" || return 0 + for state_var in ${STATEVARS_LOGINS[*]} + do ! ValidateId "$(GetStateVar ${state_var})" || return 0 + done # prompt for root user password local pass @@ -213,8 +209,7 @@ SelectBase() # MOCK_SELECTBASE ; return 0 ; # checks to skip this stage per preset config, partial config, or SelectDefaults() - [[ -z "$(GetStateVar 'BASE')" ]] || - [[ -z "$(GetStateVar 'INIT')" ]] || return 0 + ! AreConfiguredStateVars ${STATEVARS_BASE[*]} || return 0 # prompt for local vs remote package repos, if possible local install=$( [[ "$(GetStateVar 'INSTALL')" != 'prompt' ]] && \ @@ -244,7 +239,10 @@ SelectBase() NoticeOptional() { - [[ -n "$(GetStateVar 'READY')" ]] || + # checks to skip this notice per preset or partial config + AreConfiguredStateVars ${STATEVARS_BOOT[*]} && # SelectBoot() + AreConfiguredStateVars ${STATEVARS_WMDE[*]} && # SelectWmde() + AreConfiguredStateVars ${STATEVARS_ENV[*]} || # SelectEnv() WizardDlg "${TR[dlg_optional-${Lang}]}" --msgbox "${TR[notice_optional-${Lang}]}" 0 0 } @@ -253,7 +251,7 @@ SelectBoot() # MOCK_SELECTBOOT ; return 0 ; # checks to skip this stage per preset or partial config - [[ -z "$(GetStateVar 'BOOT')" ]] || return 0 + ! AreConfiguredStateVars ${STATEVARS_BOOT[*]} || return 0 # prompt to install GRUB (( $( WizardDlg "${TR[dlg_boot-${Lang}]}" \ @@ -267,7 +265,7 @@ SelectWmde() # MOCK_SELECTWMDE ; return 0 ; # checks to skip this stage per preset config, partial config, or SelectDefaults() - [[ -z "$(GetStateVar 'WMDE')" ]] || return 0 + ! AreConfiguredStateVars ${STATEVARS_WMDE[*]} || return 0 # prompt to install a graphical environment if (( $( WizardDlg "${TR[dlg_wmde-${Lang}]}" \ @@ -290,8 +288,7 @@ SelectEnv() # MOCK_SELECTENV ; return 0 ; # checks to skip this stage per preset config, partial config, or SelectDefaults() - [[ -z "$(GetStateVar 'HOSTNAME')" || -z "$(GetStateVar 'TIMEZONE')" ]] || - [[ -z "$(GetStateVar 'KEYMAP' )" || -z "$(GetStateVar 'LOCALES' )" ]] || return 0 + ! AreConfiguredStateVars ${STATEVARS_ENV[*]} || return 0 local curr_msg="${TR[option_current-${Lang}]}" local host_lang=$(GetStateVar 'LANG') @@ -396,13 +393,9 @@ _UmountAll() SelectPartition() { # checks to skip this stage per preset config - [[ -z "$(GetStateVar 'DEVICE_N' )" ]] || - [[ -z "$(GetStateVar 'DEVICE' )" ]] || - [[ -z "$(GetStateVar 'PART_METHOD')" ]] || return 0 - # NOTE: The user must select all partitioning options, # if the 'READY' state-var is not set, even upon a resumed run. - if [[ -z "$(GetStateVar 'READY')" ]] + if ! AreConfiguredStateVars ${STATEVARS_PARTITION[*]} 'READY' then # reset partitioning state (unnecessary, but pedantic) SetStateVar 'DEVICE' ; SetStateVar 'ROOT_PART' ; SetStateVar 'DEVICE_N' ; SetStateVar 'BOOT_PART' ; @@ -449,7 +442,7 @@ NoticeReady() _PartitionAuto() { # sanity checks - [[ -n "$(GetStateVar 'DEVICE')" ]] + AreConfiguredStateVars 'DEVICE' # checks to skip this stage per preset config # NOTE: this is the only path for preset unattended-install configurations @@ -494,8 +487,7 @@ _PartitionAuto() _PartitionManual() { # sanity checks - [[ -n "$(GetStateVar 'DEVICE' )" ]] - [[ -n "$(GetStateVar 'DEVICE_N')" ]] + AreConfiguredStateVars 'DEVICE' 'DEVICE_N' _UmountAll @@ -551,7 +543,7 @@ Partition() [[ "$(GetStateVar 'PART_METHOD')" == 'auto' ]] && _PartitionAuto || _PartitionManual # sanity checks - [[ -n "$(GetStateVar 'ROOT_PART')" ]] + AreConfiguredStateVars 'ROOT_PART' declare -A partitions=( [Root]=$(GetStateVar 'ROOT_PART') \ [Boot]=$(GetStateVar 'BOOT_PART') \ @@ -590,11 +582,7 @@ Partition() InstallPkgs() { # sanity checks - [[ -n "$(GetStateVar 'INSTALL')" ]] - [[ -n "$(GetStateVar 'INIT' )" ]] - [[ -n "$(GetStateVar 'BASE' )" ]] - [[ -n "$(GetStateVar 'BOOT' )" ]] - [[ -n "$(GetStateVar 'WMDE' )" ]] + AreConfiguredStateVars ${STATEVARS_BASE[*]} ${STATEVARS_BOOT[*]} ${STATEVARS_WMDE[*]} local init=$( GetStateVar 'INIT' ) local base_set=$( GetStateVar 'BASE' ) @@ -625,20 +613,9 @@ InstallPkgs() ConfigChroot() { # sanity checks - [[ -n "$(GetStateVar 'HOSTNAME' )" ]] # chroot-environment.sh - [[ -n "$(GetStateVar 'TIMEZONE' )" ]] - [[ -n "$(GetStateVar 'KEYMAP' )" ]] - [[ -n "$(GetStateVar 'LOCALES' )" ]] - [[ -n "$(GetStateVar 'LANG' )" ]] - [[ -n "$(GetStateVar 'BOOT' )" ]] - [[ -n "$(GetStateVar 'DEVICE' )" ]] - [[ -n "$(GetStateVar 'ROOT_PASS' )" ]] # chroot-login.sh - [[ -n "$(GetStateVar 'USER_LOGIN')" ]] - [[ -n "$(GetStateVar 'USER_PASS' )" ]] - [[ -n "$(GetStateVar 'XKBMAP' )" ]] - [[ -n "$(GetStateVar 'WMDE' )" ]] - [[ -n "$(GetStateVar 'INIT' )" ]] # chroot-services.sh - [[ -n "$(GetStateVar 'WMDE' )" ]] + AreConfiguredStateVars ${STATEVARS_CHROOTENV[*]} # chroot-environment.sh + AreConfiguredStateVars ${STATEVARS_CHROOTLOGIN[*]} # chroot-login.sh + AreConfiguredStateVars ${STATEVARS_CHROOTSERVICES[*]} # chroot-services.sh # copy helper scripts into the chroot and execute them in-chroot install -m100 "${THIS_DIR}"/chroot-environment.sh /mnt/root/ diff --git a/session-common.sh.inc b/session-common.sh.inc index e52304e..ab0420a 100644 --- a/session-common.sh.inc +++ b/session-common.sh.inc @@ -33,6 +33,35 @@ readonly DEF_WMDE='cli' readonly DEF_HOSTNAME='parabola' readonly DEF_TIMEZONE='UTC' +# per-stage state vars +readonly STATEVARS_LOGINS=( 'ROOT_PASS' 'USER_LOGIN' 'USER_PASS' ) +readonly STATEVARS_BASE=( 'INSTALL' 'BASE' 'INIT' ) +readonly STATEVARS_BOOT=( 'BOOT' ) +readonly STATEVARS_DEFAUILTS=( 'INSTALL' 'BASE' 'INIT' \ + 'WMDE' \ + 'LANG' 'HOSTNAME' 'TIMEZONE' 'KEYMAP' 'LOCALES' \ + 'XKBMAP' 'LANG' ) +readonly STATEVARS_WMDE=( 'WMDE' ) +readonly STATEVARS_ENV=( 'LANG' 'HOSTNAME' 'TIMEZONE' 'KEYMAP' 'LOCALES' ) +readonly STATEVARS_PARTITION=( 'DEVICE_N' 'DEVICE' 'PART_METHOD' ) +readonly STATEVARS_READY=( 'ROOT_PART' 'BOOT_PART' 'HOME_PART' ) +readonly STATEVARS_CHROOTENV=( 'HOSTNAME' 'TIMEZONE' 'KEYMAP' 'LOCALES' \ + 'LANG' 'BOOT' 'DEVICE' ) +readonly STATEVARS_CHROOTLOGIN=( 'ROOT_PASS' 'USER_LOGIN' 'USER_PASS' 'XKBMAP' 'WMDE' ) +readonly STATEVARS_CHROOTSERVICES=( 'INIT' 'WMDE' ) +STATEVARS_PRESET=( ${STATEVARS_LOGINS[*]} \ + ${STATEVARS_BASE[*]} \ + ${STATEVARS_BOOT[*]} \ + ${STATEVARS_WMDE[*]} \ + ${STATEVARS_ENV[*]} \ + ${STATEVARS_PARTITION[*]} \ + ${STATEVARS_READY[*]} \ + ${STATEVARS_CHROOTENV[*]} \ + ${STATEVARS_CHROOTLOGIN[*]} \ + ${STATEVARS_CHROOTSERVICES[*]} ) +readarray -td '' STATEVARS_PRESET < <( sort -zu < <(printf "%s\0" "${STATEVARS_PRESET[@]}") ) +readonly STATEVARS_PRESET + ## sanity checks ## @@ -67,6 +96,16 @@ GetStateVar() # (var_name [def_value]) fi } +AreConfiguredStateVars() # ( state_var [ state_var ] ... ) +{ +# for state_var in $* ; do echo -n "AreConfiguredStateVars() state_var=${state_var}=$(GetStateVar ${state_var})=" ; [[ -n "$(GetStateVar ${state_var})" ]] && echo "OK" || ! echo "NFG" ; done ; + + # TODO: replace each call to this function with proper validations + for state_var in $* ; do [[ -n "$(GetStateVar ${state_var})" ]] || return 1 ; done ; + + return 0 +} + ## dialog prompt helpers ## @@ -403,7 +442,6 @@ LogError() # (source_file func_name line_n) ## debugging helpers ## MOCK_INIT() { SetStateVar 'XKBMAP' ${DEF_KEYMAP} ; SetStateVar 'LANG' ${DEF_LANG} ; SetStateVar 'TR_KEY' ${DEF_TRKEY} ; SetStateVar 'INSTALL' ${DEF_INSTALL} ; } -MOCK_INITKEYRING() { SetStateVar 'KEYRING' 'ready' ; } MOCK_SELECTDEFAULTS() { SetStateVar 'INSTALL' ${DEF_INSTALL} ; SetStateVar 'BASE' ${DEF_PKG_SET} ; SetStateVar 'INIT' ${DEF_INIT} ; SetStateVar 'WMDE' ${DEF_WMDE} ; SetStateVar 'HOSTNAME' ${DEF_HOSTNAME} ; SetStateVar 'TIMEZONE' ${DEF_TIMEZONE} ; SetStateVar 'KEYMAP' $(GetStateVar 'XKBMAP') ; SetStateVar 'LOCALES' $(GetStateVar 'LANG') ; } MOCK_SELECTDEFAULTS_NO() { : ; } MOCK_SELECTLOGINS() { SetStateVar 'ROOT_PASS' ROOT_PASS ; MOCK_SELECTLOGINS_USER ; } |