diff --git a/configure b/configure index de6224b..bad5858 100755 --- a/configure +++ b/configure @@ -44,8 +44,7 @@ while [[ $# -gt 0 ]]; do shift done -# TODO check install dialog -echo "Please install dialog on your system to use the configurator" +check_has_programs dialog # Wrap dialog in two functions to prevent it from cluttering stderr. function dialog_wrapper() { dialog_out=$(command dialog --colors "$@" 3>&2 2>&1 1>&3 3>&-); } diff --git a/scripts/functions.sh b/scripts/functions.sh index 60bec50..d7cfd4b 100644 --- a/scripts/functions.sh +++ b/scripts/functions.sh @@ -5,11 +5,6 @@ source "$GENTOO_INSTALL_REPO_DIR/scripts/protection.sh" || exit 1 ################################################ # Functions -function check_has_program() { - type "$1" &>/dev/null \ - || die "Missing program: '$1'" -} - function sync_time() { einfo "Syncing time" ntpd -g -q \ @@ -58,25 +53,30 @@ function preprocess_config() { function prepare_installation_environment() { einfo "Preparing installation environment" - check_has_program gpg - check_has_program hwclock - check_has_program lsblk - check_has_program ntpd - check_has_program partprobe - check_has_program python3 - check_has_program rhash - check_has_program sgdisk - check_has_program uuidgen - check_has_program wget + local needed_programs=() + + needed_programs+=(gpg) + needed_programs+=(hwclock) + needed_programs+=(lsblk) + needed_programs+=(ntpd) + needed_programs+=(partprobe) + needed_programs+=(python3) + needed_programs+=(rhash) + needed_programs+=(sgdisk) + needed_programs+=(uuidgen) + needed_programs+=(wget) [[ $USED_BTRFS == "true" ]] \ - && check_has_program btrfs + && needed_programs+=(btrfs) [[ $USED_ZFS == "true" ]] \ - && check_has_program zfs + && needed_programs+=(zfs) [[ $USED_RAID == "true" ]] \ - && check_has_program mdadm + && needed_programs+=(mdadm) [[ $USED_LUKS == "true" ]] \ - && check_has_program cryptsetup + && needed_programs+=(cryptsetup) + + # Check for existence of required programs + check_has_programs "${needed_programs[@]}" # Check encryption key if used [[ $USED_ENCRYPTION == "true" ]] \ diff --git a/scripts/utils.sh b/scripts/utils.sh index 0354f3d..96b229e 100644 --- a/scripts/utils.sh +++ b/scripts/utils.sh @@ -320,3 +320,25 @@ function parse_arguments() { done fi } + +function check_has_programs() { + local failed=() + local program + for program in "$@"; do + type "$1" &>/dev/null \ + || failed+=("$program") + done + + echo "The following programs are required for the installer to work, but are currently missing on your system:" >&2 + echo " ${failed[@]}" >&2 + + if type pacman &>/dev/null; then + echo "We have detected that pacman is available." + if ask "Do you want to install the missing programs automatically?"; then + pacman -Sy "${failed[@]}" + return + fi + fi + + die "Aborted installer because of missing required programs." +}