From 525e7668d88327695f19d78c9addbbcc904d2358 Mon Sep 17 00:00:00 2001 From: oddlama Date: Mon, 26 Apr 2021 23:48:30 +0200 Subject: [PATCH] set -e is staight from hell. [[ $CONFIG_VAR == 1 ]] && do_smth is now wrong, need for command && ret=$? || ret=$?. I'm out. --- configure | 223 ++++++++++++++++++++----------------- install | 2 +- scripts/dispatch_chroot.sh | 3 +- 3 files changed, 121 insertions(+), 107 deletions(-) diff --git a/configure b/configure index d3a8ee5..b077031 100755 --- a/configure +++ b/configure @@ -46,6 +46,10 @@ done # TODO check install dialog echo "Please install dialog on your system to use the configurator" +# Wrap dialog in two functions to prevent it from cluttering stderr. +function dialog_wrapper() { dialog_out=$(command dialog "$@" 3>&2 2>&1 1>&3 3>&-); } +function dialog() { dialog_wrapper "$@" 2>&1; } + ################################################ # Configuration helper functions @@ -121,6 +125,12 @@ function recalculate_locales() { LOCALES="${LOCALES:1}" } +function define_disk_layout() { + # Show function declaration, trim trailing whitespace + declare -f disk_configuration \ + | sed -e 's/\s*$//' +} + ALL_PARTITIONING_SCHEMES=( "classic_single_disk" "Classic single disk layout (boot, swap, root)" "zfs_centric" "ZFS centric (optional raid0/1 and encryption via zfs)" @@ -128,7 +138,6 @@ ALL_PARTITIONING_SCHEMES=( "raid0_luks" "Raid0 (N>=2 disks) and luks for root" "custom" "Custom (edit the config manually later)" ) -PARTITIONING_SCHEME="zfs_centric" function create_single_disk_layout() { create_classic_single_disk_layout @@ -136,10 +145,17 @@ function create_single_disk_layout() { function create_classic_single_disk_layout() { PARTITIONING_SCHEME="classic_single_disk" + USE_SWAP=false } function create_raid0_luks_layout() { PARTITIONING_SCHEME="classic_single_disk" + USE_SWAP=false +} + +function create_zfs_centric_layout() { + PARTITIONING_SCHEME="zfs_centric" + USE_SWAP=false } function create_btrfs_raid_layout() { @@ -148,6 +164,7 @@ function create_btrfs_raid_layout() { function create_btrfs_centric_layout() { PARTITIONING_SCHEME="btrfs_centric" + USE_SWAP=false } @@ -203,12 +220,13 @@ function process_config() { } function load_config() { + # First load defaults, then replace by sourcing config. + load_default_config + # Load settings source "$1" || die "Could not load given configuration." - # Process config to generate intermediary values. # After loading a config no unsaved changes exist. - process_config UNSAVED_CHANGES=false } @@ -220,6 +238,10 @@ function load_default_config() { LOCALES="C.UTF-8 UTF-8" LOCALE="C.utf8" + function disk_configuration() { + create_zfs_centric_layout swap=8GiB type=efi luks=false /dev/sdX + } + SYSTEMD=true GENTOO_MIRROR="https://mirror.eu.oneandone.net/linux/distributions/gentoo/gentoo" @@ -232,9 +254,7 @@ function load_default_config() { INSTALL_SSHD=true ROOT_SSH_AUTHORIZED_KEYS="" - # Process config to generate intermediary values. # All settings are unsaved. - process_config UNSAVED_CHANGES=true } @@ -244,15 +264,17 @@ if [[ -e "$CONFIG_FILE" ]]; then else load_default_config fi +process_config ################################################ # Menu helpers and constants +# $1: exit code function clear_and_exit() { dialog --clear clear -x - exit 0 + exit "$1" } function ellipsis() { @@ -323,16 +345,14 @@ function menu_splitlist() { done # Show selection dialog - local sel - sel="$(dialog \ + dialog \ --title "$title" \ --buildlist "$description\nUse ^ to focus the list of unselected items and $ to focus the list of selected items. Use to select/deselect an item and select by pressing when finished." \ - "${BUILDLIST_SIZE[@]}" "${items[@]}" 3>&2 2>&1 1>&3 3>&-)" + "${BUILDLIST_SIZE[@]}" "${items[@]}" - local diag_exit="$?" + local diag_exit=$? if [[ $diag_exit == 0 ]]; then # - echo -n "$sel" return 0 elif [[ $diag_exit == 1 ]]; then # @@ -347,7 +367,7 @@ function menu_splitlist() { # $2: description # $3: default item # $@: [tag label]... -function menu_radiolist_labeled() { +function menu_radiolist_labeled() { local title="$1" local description="$2" local default_item="$3" @@ -370,8 +390,7 @@ function menu_radiolist_labeled() { done # Show selection dialog - local sel - sel="$(dialog \ + dialog \ --no-tags \ --title "$title" \ --help-button \ @@ -381,22 +400,21 @@ function menu_radiolist_labeled() { --default-item "$default_item" \ --default-button help \ --radiolist "$description\nUse - local sel="${sel#HELP }" + local sel="${dialog_out#HELP }" local sel_cur="${sel% *}" #local sel_radio="${sel#* }" - echo -n "$sel_cur" + dialog_out="$sel_cur" return 0 else # @@ -426,8 +444,7 @@ function menu_radiolist() { done # Show selection dialog - local sel - sel="$(dialog \ + dialog \ --no-items \ --title "$title" \ --help-button \ @@ -437,22 +454,21 @@ function menu_radiolist() { --default-item "$default_item" \ --default-button help \ --radiolist "$description\nUse - local sel="${sel#HELP }" + local sel="${dialog_out#HELP }" local sel_cur="${sel% *}" #local sel_radio="${sel#* }" - echo -n "$sel_cur" + dialog_out="$sel_cur" return 0 else # @@ -461,19 +477,16 @@ function menu_radiolist() { } function msgbox_help() { - dialog \ - --msgbox "$1" \ - "${HELP_POPUP_SIZE[@]}" 3>&2 2>&1 1>&3 3>&- + dialog --msgbox "$1" "${HELP_POPUP_SIZE[@]}" } function menu_exit() { if [[ $UNSAVED_CHANGES == "true" ]]; then - local sel - sel="$(dialog \ + dialog \ --help-button --help-label "Back" \ --yes-label "Save" --no-label "Discard" \ --yesno "Do you want to save your configuration?\n(Press , or choose to continue gentoo configuration)." \ - "${CONFIRM_SIZE[@]}" 3>&2 2>&1 1>&3 3>&-)" + "${CONFIRM_SIZE[@]}" local diag_exit="$?" if [[ $diag_exit == 0 ]]; then @@ -494,16 +507,15 @@ function menu_exit() { } function menu_save_as() { - local sel - sel="$(dialog \ + dialog \ --ok-label "Save" \ --inputbox "Enter a filename to which this configuration should be saved.\n(Press , or choose to abort)." \ - "${INPUTBOX_SIZE[@]}" "$SAVE_AS_FILENAME" 3>&2 2>&1 1>&3 3>&-)" + "${INPUTBOX_SIZE[@]}" "$SAVE_AS_FILENAME" local diag_exit="$?" if [[ $diag_exit == 0 ]]; then # - SAVE_AS_FILENAME="$sel" + SAVE_AS_FILENAME="$dialog_out" save "$SAVE_AS_FILENAME" UNSAVED_CHANGES=false else @@ -528,32 +540,32 @@ function menu() { reverse_lookup["$item_tag"]="$item" done - local sel - sel="$(dialog --colors \ + dialog --colors \ --title "Gentoo configuration ($RELA_CONFIG_FILE)" \ --extra-button --extra-label "Exit" \ --help-button \ --default-item "$SELECTED_MENU_ITEM" \ --ok-label "Select" --cancel-label "Save" \ --menu "This is the gentoo configuration menu. Read and adjust all options below carefully. Save your desired configuration and run ./install afterwards. Use if you want further information on any option." \ - "${MENU_SIZE[@]}" "${tag_item_list[@]}" 3>&2 2>&1 1>&3 3>&-)" + "${MENU_SIZE[@]}" "${tag_item_list[@]}" local diag_exit="$?" if [[ $diag_exit == 0 ]]; then #