From d446af1d6acf2eef9b79dee9db0b48b101923144 Mon Sep 17 00:00:00 2001 From: oddlama Date: Thu, 22 Apr 2021 21:09:11 +0200 Subject: [PATCH] Begin partitioning scheme selector --- configure | 370 +++++++++++++++++++++++++--------------------- scripts/config.sh | 40 ++--- 2 files changed, 223 insertions(+), 187 deletions(-) diff --git a/configure b/configure index 1d1400a..d1db09e 100755 --- a/configure +++ b/configure @@ -117,6 +117,21 @@ function recalculate_locales() { LOCALES="${LOCALES:1}" } +ALL_PARTITIONING_SCHEMES=("single_disk" "raid0_luks" "btrfs_raid" "zfs_raid") +PARTITIONING_SCHEME="single_disk" + +function create_btrfs_raid_layout() { + PARTITIONING_SCHEME="btrfs_raid" +} + +function create_raid0_luks_layout() { + PARTITIONING_SCHEME="raid0_luks" +} + +function create_single_disk_layout() { + PARTITIONING_SCHEME="single_disk" +} + ################################################ # Configuration constants @@ -259,70 +274,6 @@ function is_off() { [[ "$1" != true ]] } -SELECTED_MENU_ITEM="" -MENU_SIZE=("20" "76" "12") -INPUTBOX_SIZE=("8" "76") -EDITTEXT_SIZE=("16" "76") -RADIOLIST_SIZE=("20" "76" "8") -BUILDLIST_SIZE=("20" "76" "8") -HELP_POPUP_SIZE=("8" "66") -CONFIRM_SIZE=("8" "66") - - -################################################ -# Menu definition - -MENU_ITEMS=( - "DISK_LAYOUT" - "SWAP" - "ENCRYPT" - "--------" - "HOSTNAME" - "TIMEZONE" - "KEYMAP" - "KEYMAP_INITRAMFS_OTHER" - "KEYMAP_INITRAMFS" - "LOCALES" - "LOCALE" - "--------" - "INIT_SYSTEM" - "GENTOO_MIRROR" - "GENTOO_ARCH" - "SELECT_MIRRORS" - "SELECT_MIRRORS_LARGE_FILE" - "--------" - "INSTALL_SSHD" - "ROOT_SSH_AUTHORIZED_KEYS" - "ADDITIONAL_PACKAGES" -) - -function --------_tag() { echo "────────────────────────────"; } -function --------_label() { echo "────────────────────────────"; } -function --------_show() { return 0; } -function --------_help() { echo "Congratulations, you found a separator."; } -function --------_menu() { true; } - -function HOSTNAME_tag() { echo "Hostname"; } -function HOSTNAME_label() { echo "($HOSTNAME)"; } -function HOSTNAME_show() { return 0; } -function HOSTNAME_help() { echo "Enter the desired system hostname here. Be aware that when creating mdadm raid arrays, this value will be recorded in metadata block. If you change it later, you should also update the metadata."; } -function HOSTNAME_menu() { - local sel - sel="$(dialog \ - --title "Select hostname" \ - --inputbox "Enter the hostname for your new system." \ - "${INPUTBOX_SIZE[@]}" "$HOSTNAME" 3>&2 2>&1 1>&3 3>&-)" - UNSAVED_CHANGES=true -} - -function TIMEZONE_tag() { echo "Timezone"; } -function TIMEZONE_label() { echo "($TIMEZONE)"; } -function TIMEZONE_show() { return 0; } -function TIMEZONE_help() { echo "The timezone for the new system."; } -function TIMEZONE_menu() { - true -} - # $1: title # $2: description # $3: space separated index list of selected items (e.g. "0 1 5 6") @@ -427,6 +378,192 @@ function menu_radiolist() { fi } +function msgbox_help() { + dialog \ + --msgbox "$1" \ + "${HELP_POPUP_SIZE[@]}" 3>&2 2>&1 1>&3 3>&- +} + +function menu_exit() { + if [[ $UNSAVED_CHANGES == "true" ]]; then + local sel + sel="$(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>&-)" + + local diag_exit="$?" + if [[ $diag_exit == 0 ]]; then + # + save "$CONFIG_FILE" + clear_and_exit 0 + elif [[ $diag_exit == 1 ]]; then + # + clear_and_exit 0 + else + # Back to menu (, ) + true + fi + else + # Nothing was changed. Exit immediately. + clear_and_exit 0 + fi +} + +function menu_save_as() { + local sel + sel="$(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>&-)" + + local diag_exit="$?" + if [[ $diag_exit == 0 ]]; then + # + SAVE_AS_FILENAME="$sel" + save "$SAVE_AS_FILENAME" + UNSAVED_CHANGES=false + else + # Back to menu (, ) + true + fi +} + +function menu() { + local item + local item_tag + local tag_item_list=() + declare -A reverse_lookup + + # Create menu list + for item in "${MENU_ITEMS[@]}"; do + # Only if item is visible + "${item}_show" || continue + + item_tag="$("${item}_tag")" + tag_item_list+=("$item_tag" "$("${item}_label")") + reverse_lookup["$item_tag"]="$item" + done + + local sel + sel="$(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>&-)" + + local diag_exit="$?" + if [[ $diag_exit == 0 ]]; then + # - SELECTED_MENU_ITEM="$sel" - "${reverse_lookup[$SELECTED_MENU_ITEM]}_menu" - elif [[ $diag_exit == 1 ]]; then - # - SELECTED_MENU_ITEM="$sel" - menu_save_as - elif [[ $diag_exit == 2 ]]; then - # - SELECTED_MENU_ITEM="${sel#HELP }" - msgbox_help "$("${reverse_lookup[$SELECTED_MENU_ITEM]}_help")" - else - # Exit (, ) - SELECTED_MENU_ITEM="${sel-$SELECTED_MENU_ITEM}" - menu_exit - true - fi -} - # Begin menu loop. Exit will be called to end this loop where it is appropriate. while true; do menu diff --git a/scripts/config.sh b/scripts/config.sh index 1b54819..9343ecc 100644 --- a/scripts/config.sh +++ b/scripts/config.sh @@ -279,8 +279,8 @@ create_single_disk_layout() { create_gpt new_id=gpt device="$device" create_partition new_id="part_$type" id=gpt size=256MiB type="$type" - [[ $size_swap != "false" ]] && \ - create_partition new_id=part_swap id=gpt size="$size_swap" type=swap + [[ $size_swap != "false" ]] \ + && create_partition new_id=part_swap id=gpt size="$size_swap" type=swap create_partition new_id=part_root id=gpt size=remaining type=linux local root_id="part_root" @@ -290,8 +290,8 @@ create_single_disk_layout() { fi format id="part_$type" type="$type" label="$type" - [[ $size_swap != "false" ]] && \ - format id=part_swap type=swap label=swap + [[ $size_swap != "false" ]] \ + && format id=part_swap type=swap label=swap format id="$root_id" type="$root_fs" label=root if [[ $type == "efi" ]]; then @@ -299,8 +299,8 @@ create_single_disk_layout() { else DISK_ID_BIOS="part_$type" fi - [[ $size_swap != "false" ]] && \ - DISK_ID_SWAP=part_swap + [[ $size_swap != "false" ]] \ + && DISK_ID_SWAP=part_swap DISK_ID_ROOT="$root_id" if [[ $root_fs == "btrfs" ]]; then @@ -342,19 +342,19 @@ create_raid0_luks_layout() { for i in "${!extra_arguments[@]}"; do create_gpt new_id="gpt_dev${i}" device="${extra_arguments[$i]}" create_partition new_id="part_${type}_dev${i}" id="gpt_dev${i}" size=256MiB type="$type" - [[ $size_swap != "false" ]] && \ - create_partition new_id="part_swap_dev${i}" id="gpt_dev${i}" size="$size_swap" type=raid + [[ $size_swap != "false" ]] \ + && create_partition new_id="part_swap_dev${i}" id="gpt_dev${i}" size="$size_swap" type=raid create_partition new_id="part_root_dev${i}" id="gpt_dev${i}" size=remaining type=raid done - [[ $size_swap != "false" ]] && \ - create_raid new_id=part_raid_swap name="swap" level=0 ids="$(expand_ids '^part_swap_dev[[:digit:]]$')" + [[ $size_swap != "false" ]] \ + && create_raid new_id=part_raid_swap name="swap" level=0 ids="$(expand_ids '^part_swap_dev[[:digit:]]$')" create_raid new_id=part_raid_root name="root" level=0 ids="$(expand_ids '^part_root_dev[[:digit:]]$')" create_luks new_id=part_luks_root name="root" id=part_raid_root format id="part_${type}_dev0" type="$type" label="$type" - [[ $size_swap != "false" ]] && \ - format id=part_raid_swap type=swap label=swap + [[ $size_swap != "false" ]] \ + && format id=part_raid_swap type=swap label=swap format id=part_luks_root type="$root_fs" label=root if [[ $type == "efi" ]]; then @@ -362,8 +362,8 @@ create_raid0_luks_layout() { else DISK_ID_BIOS="part_${type}_dev0" fi - [[ $size_swap != "false" ]] && \ - DISK_ID_SWAP=part_raid_swap + [[ $size_swap != "false" ]] \ + && DISK_ID_SWAP=part_raid_swap DISK_ID_ROOT=part_luks_root if [[ $root_fs == "btrfs" ]]; then @@ -406,8 +406,8 @@ create_btrfs_raid_layout() { # Create layout on first disk create_gpt new_id="gpt_dev0" device="${extra_arguments[0]}" create_partition new_id="part_${type}_dev0" id="gpt_dev0" size=256MiB type="$type" - [[ $size_swap != "false" ]] && \ - create_partition new_id="part_swap_dev0" id="gpt_dev0" size="$size_swap" type=swap + [[ $size_swap != "false" ]] \ + && create_partition new_id="part_swap_dev0" id="gpt_dev0" size="$size_swap" type=swap create_partition new_id="part_root_dev0" id="gpt_dev0" size=remaining type=linux local root_id @@ -434,8 +434,8 @@ create_btrfs_raid_layout() { fi format id="part_${type}_dev0" type="$type" label="$type" - [[ $size_swap != "false" ]] && \ - format id="part_swap_dev0" type=swap label=swap + [[ $size_swap != "false" ]] \ + && format id="part_swap_dev0" type=swap label=swap format_btrfs ids="$root_ids" label=root raid_type="$raid_type" if [[ $type == "efi" ]]; then @@ -443,8 +443,8 @@ create_btrfs_raid_layout() { else DISK_ID_BIOS="part_${type}_dev0" fi - [[ $size_swap != "false" ]] && \ - DISK_ID_SWAP=part_swap_dev0 + [[ $size_swap != "false" ]] \ + && DISK_ID_SWAP=part_swap_dev0 DISK_ID_ROOT="$root_id" DISK_ID_ROOT_TYPE="btrfs" DISK_ID_ROOT_MOUNT_OPTS="defaults,noatime,compress=zstd,subvol=/root"