diff --git a/configure b/configure index a80cd65..bae60da 100755 --- a/configure +++ b/configure @@ -47,7 +47,7 @@ done 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_wrapper() { dialog_out=$(command dialog --colors "$@" 3>&2 2>&1 1>&3 3>&-); } function dialog() { dialog_wrapper "$@" 2>&1; } @@ -125,10 +125,35 @@ function recalculate_locales() { LOCALES="${LOCALES:1}" } +function define_disk_configuration_function() { + cat << EOF +function disk_configuration() { + $* ; +} +EOF +} + +function define_swap() { + if [[ $PARTITIONING_USE_SWAP == "true" ]]; then + echo -n "${PARTITIONING_SWAP@Q}" + else + echo -n "false" + fi +} + function define_disk_layout() { - # Show function declaration, trim trailing whitespace - declare -f disk_configuration \ - | sed -e 's/\s*$//' + + case "$PARTITIONING_SCHEME" in + "classic_single_disk") define_disk_configuration_function "create_classic_single_disk_layout swap=$(define_swap) type=${PARTITIONING_BOOT_TYPE@Q} luks=${PARTITIONING_USE_LUKS@Q} root_fs=${PARTITIONING_ROOT_FS@Q}" "${PARTITIONING_DEVICE@Q}" ;; + "zfs_centric") define_disk_configuration_function "create_zfs_centric_layout swap=$(define_swap) type=${PARTITIONING_BOOT_TYPE@Q} encrypt=${PARTITIONING_ZFS_ENCRYPTION@Q} pool_type=${PARTITIONING_ZFS_POOL_TYPE@Q}" "${PARTITIONING_DEVICES[@]@Q}" ;; + "btrfs_centric") define_disk_configuration_function "create_btrfs_centric_layout swap=$(define_swap) type=${PARTITIONING_BOOT_TYPE@Q} raid_type=${PARTITIONING_BTRFS_RAID_TYPE@Q} luks=${PARTITIONING_USE_LUKS@Q}" "${PARTITIONING_DEVICES[@]@Q}" ;; + "raid0_luks") define_disk_configuration_function "create_raid0_luks_layout swap=$(define_swap) type=${PARTITIONING_BOOT_TYPE@Q} root_fs=${PARTITIONING_ROOT_FS@Q}" "${PARTITIONING_DEVICES[@]@Q}" ;; + "custom") + # Show current function declaration, trim trailing whitespace + declare -f disk_configuration \ + | sed -e 's/\s*$//' + ;; + esac } ALL_PARTITIONING_SCHEMES=( @@ -139,8 +164,9 @@ ALL_PARTITIONING_SCHEMES=( "custom" "Custom (edit the config manually later)" ) +PARTITIONING_BOOT_TYPES=("efi" "bios") PARTITIONING_ROOT_FS_TYPES=("ext4" "btrfs") -PARTITIONING_RAID_TYPES=("raid0" "raid1") +PARTITIONING_BTRFS_RAID_TYPES=("raid0" "raid1") PARTITIONING_ZFS_POOL_TYPES=("stripe" "mirror") function create_single_disk_layout() { @@ -150,7 +176,7 @@ function create_single_disk_layout() { function parse_swap() { if [[ $1 == "false" ]]; then PARTITIONING_USE_SWAP=false - PARTITIONING_SWAP=0 + PARTITIONING_SWAP=8GiB else PARTITIONING_USE_SWAP=true PARTITIONING_SWAP="$1" @@ -172,7 +198,7 @@ function create_classic_single_disk_layout() { } function create_raid0_luks_layout() { - PARTITIONING_SCHEME="classic_single_disk" + PARTITIONING_SCHEME="raid0_luks" local known_arguments=('+swap' '?type' '?root_fs') local extra_arguments=() @@ -213,7 +239,7 @@ function create_btrfs_centric_layout() { parse_swap "${arguments[swap]}" PARTITIONING_BOOT_TYPE="${arguments[type]}" PARTITIONING_USE_LUKS="${arguments[luks]:-false}" - PARTITIONING_RAID_TYPE="${arguments[raid_type]:-raid0}" + PARTITIONING_BTRFS_RAID_TYPE="${arguments[raid_type]:-raid0}" } @@ -636,7 +662,7 @@ function menu() { SELECTED_MENU_ITEM="" MENU_SIZE=("20" "76" "12") -INPUTBOX_SIZE=("8" "76") +INPUTBOX_SIZE=("11" "76") EDITTEXT_SIZE=("16" "76") RADIOLIST_SIZE=("20" "76" "8") BUILDLIST_SIZE=("20" "76" "8") @@ -654,11 +680,11 @@ MENU_ITEMS=( "PARTITIONING_SWAP" "PARTITIONING_ROOT_FS" "PARTITIONING_USE_LUKS" - "PARTITIONING_DEVICE" - "PARTITIONING_DEVICES" "PARTITIONING_ZFS_ENCRYPTION" "PARTITIONING_ZFS_POOL_TYPE" - "PARTITIONING_RAID_TYPE" + "PARTITIONING_BTRFS_RAID_TYPE" + "PARTITIONING_DEVICE" + "PARTITIONING_DEVICES" "--------" "HOSTNAME" "TIMEZONE" @@ -699,9 +725,9 @@ function PARTITIONING_SCHEME_menu() { # Set disk scheme case "$dialog_out" in "classic_single_disk") create_classic_single_disk_layout swap=8GiB type=efi luks=false root_fs=ext4 /dev/sdX ;; - "zfs_centric") ;; - "btrfs_centric") ;; - "raid0_luks") ;; + "zfs_centric") create_zfs_centric_layout swap=8GiB type=efi encrypt=true pool_type=stripe /dev/sdX ;; + "btrfs_centric") create_btrfs_centric_layout swap=8GiB type=efi raid_type=raid0 luks=false /dev/sdX ;; + "raid0_luks") create_raid0_luks_layout swap=8GiB type=efi root_fs=ext4 /dev/sdX /dev/sdY ;; "custom") PARTITIONING_SCHEME="$dialog_out" ;; esac UNSAVED_CHANGES=true @@ -711,6 +737,26 @@ function PARTITIONING_SCHEME_menu() { fi } +function PARTITIONING_BOOT_TYPE_tag() { echo " ├ Boot type"; } +function PARTITIONING_BOOT_TYPE_label() { echo " ├ ($PARTITIONING_BOOT_TYPE)"; } +function PARTITIONING_BOOT_TYPE_show() { [[ $PARTITIONING_SCHEME != "custom" ]]; } +function PARTITIONING_BOOT_TYPE_help() { echo "Select whether to use EFI or BIOS boot."; } +function PARTITIONING_BOOT_TYPE_menu() { + if menu_radiolist \ + "Select boot type" \ + "Select whether your want to use EFI or BIOS boot." \ + "$PARTITIONING_BOOT_TYPE" \ + "${PARTITIONING_BOOT_TYPES[@]}" + then + # Set timezone + PARTITIONING_BOOT_TYPE="$dialog_out" + UNSAVED_CHANGES=true + else + # Return to menu + true + fi +} + function PARTITIONING_USE_SWAP_tag() { echo " ├ Use swap"; } function PARTITIONING_USE_SWAP_label() { on_off_label "$PARTITIONING_USE_SWAP" " ├ "; } function PARTITIONING_USE_SWAP_show() { [[ $PARTITIONING_SCHEME != "custom" ]]; } @@ -753,6 +799,123 @@ function PARTITIONING_ROOT_FS_menu() { fi } +function PARTITIONING_USE_LUKS_tag() { echo " ├ Use LUKS"; } +function PARTITIONING_USE_LUKS_label() { on_off_label "$PARTITIONING_USE_LUKS" " ├ "; } +function PARTITIONING_USE_LUKS_show() { [[ $PARTITIONING_SCHEME != "custom" ]] && one_of "$PARTITIONING_SCHEME" "classic_single_disk" "btrfs_centric"; } +function PARTITIONING_USE_LUKS_help() { echo "Determines if LUKS will be used to encrypt your root partition."; } +function PARTITIONING_USE_LUKS_menu() { + on_off_toggle "PARTITIONING_USE_LUKS" + UNSAVED_CHANGES=true +} + +function PARTITIONING_ZFS_ENCRYPTION_tag() { echo " ├ ZFS Encryption"; } +function PARTITIONING_ZFS_ENCRYPTION_label() { on_off_label "$PARTITIONING_ZFS_ENCRYPTION" " ├ "; } +function PARTITIONING_ZFS_ENCRYPTION_show() { [[ $PARTITIONING_SCHEME != "custom" ]] && one_of "$PARTITIONING_SCHEME" "zfs_centric"; } +function PARTITIONING_ZFS_ENCRYPTION_help() { echo "Determines if ZFS encryption will be used to encrypt your root partition."; } +function PARTITIONING_ZFS_ENCRYPTION_menu() { + on_off_toggle "PARTITIONING_ZFS_ENCRYPTION" + UNSAVED_CHANGES=true +} + +function PARTITIONING_ZFS_POOL_TYPE_tag() { echo " ├ Pool type"; } +function PARTITIONING_ZFS_POOL_TYPE_label() { echo " ├ ($PARTITIONING_ZFS_POOL_TYPE)"; } +function PARTITIONING_ZFS_POOL_TYPE_show() { [[ $PARTITIONING_SCHEME != "custom" ]] && one_of "$PARTITIONING_SCHEME" "zfs_centric"; } +function PARTITIONING_ZFS_POOL_TYPE_help() { echo "Determines the pool type of the created zfs pool (stripe / mirror)."; } +function PARTITIONING_ZFS_POOL_TYPE_menu() { + if menu_radiolist \ + "Select ZFS pool type" \ + "Select which ZFS pool type you want to use. By default pools are striping in ZFS." \ + "$PARTITIONING_ZFS_POOL_TYPE" \ + "${PARTITIONING_ZFS_POOL_TYPES[@]}" + then + # Set timezone + PARTITIONING_ZFS_POOL_TYPE="$dialog_out" + UNSAVED_CHANGES=true + else + # Return to menu + true + fi +} + +function PARTITIONING_BTRFS_RAID_TYPE_tag() { echo " ├ Btrfs raid type"; } +function PARTITIONING_BTRFS_RAID_TYPE_label() { echo " ├ ($PARTITIONING_BTRFS_RAID_TYPE)"; } +function PARTITIONING_BTRFS_RAID_TYPE_show() { [[ $PARTITIONING_SCHEME != "custom" ]] && one_of "$PARTITIONING_SCHEME" "btrfs_centric"; } +function PARTITIONING_BTRFS_RAID_TYPE_help() { echo "Determines the type of the btrfs pool."; } +function PARTITIONING_BTRFS_RAID_TYPE_menu() { + if menu_radiolist \ + "Select raid type" \ + "Select which raid type to use for the btrfs pool." \ + "$PARTITIONING_BTRFS_RAID_TYPE" \ + "${PARTITIONING_BTRFS_RAID_TYPES[@]}" + then + # Set timezone + PARTITIONING_BTRFS_RAID_TYPE="$dialog_out" + UNSAVED_CHANGES=true + else + # Return to menu + true + fi +} + +function PARTITIONING_DEVICE_tag() { echo " └ Device"; } +function PARTITIONING_DEVICE_label() { + if [[ -e "$PARTITIONING_DEVICE" ]]; then + echo " └ ($PARTITIONING_DEVICE)" + else + echo " └ (\Z1$PARTITIONING_DEVICE\Zn)" + fi +} +function PARTITIONING_DEVICE_show() { [[ $PARTITIONING_SCHEME != "custom" ]] && one_of "$PARTITIONING_SCHEME" "classic_single_disk"; } +function PARTITIONING_DEVICE_help() { echo "The block device to which the layout will be applied."; } +function PARTITIONING_DEVICE_menu() { + dialog \ + --title "Select device" \ + --inputbox "Enter the path of the device which you want to partition. (e.g. /dev/sda)." \ + "${INPUTBOX_SIZE[@]}" "$PARTITIONING_DEVICE" + PARTITIONING_DEVICE="$dialog_out" + UNSAVED_CHANGES=true +} + +function PARTITIONING_DEVICES_tag() { echo " └ Devices"; } +function PARTITIONING_DEVICES_label() { + local invalid=0 + for dev in "${PARTITIONING_DEVICES[@]}"; do + [[ -e "$dev" ]] \ + || ((++invalid)) + done + + if [[ "$invalid" -gt 0 ]]; then + echo " └ (${#PARTITIONING_DEVICES[@]} devices, \Z1$invalid invalid\Zn)" + elif [[ "${#PARTITIONING_DEVICES[@]}" -eq 1 && "$PARTITIONING_SCHEME" == "raid0_luks" ]]; then + echo " └ (${#PARTITIONING_DEVICES[@]} devices, \Z1need at least 2\Zn)" + elif [[ "${#PARTITIONING_DEVICES[@]}" -eq 0 ]]; then + echo " └ (${#PARTITIONING_DEVICES[@]} devices, \Z1need at least 1\Zn)" + else + echo " └ (${#PARTITIONING_DEVICES[@]} devices)" + fi +} +function PARTITIONING_DEVICES_show() { [[ $PARTITIONING_SCHEME != "custom" ]] && one_of "$PARTITIONING_SCHEME" "raid0_luks" "zfs_centric" "btrfs_centric"; } +function PARTITIONING_DEVICES_help() { echo "The block devices to which the layout will be applied."; } +function PARTITIONING_DEVICES_menu() { + local invalid=() + for dev in "${PARTITIONING_DEVICES[@]}"; do + [[ -e "$dev" ]] \ + || invalid+=("$dev") + done + + local invalid_line="" + if [[ "${#invalid[@]}" -gt 0 ]]; then + invalid_line="\n\nInvalid devices: \Z1${invalid[*]}\Zn" + fi + + dialog \ + --title "Select devices" \ + --inputbox "Enter the path of all devices which you want to partition, separated by space. (e.g. /dev/sda /dev/sdb).$invalid_line" \ + "${INPUTBOX_SIZE[@]}" "${PARTITIONING_DEVICES[*]}" + PARTITIONING_DEVICES=($dialog_out) + UNSAVED_CHANGES=true +} + function HOSTNAME_tag() { echo "Hostname"; } function HOSTNAME_label() { echo "($HOSTNAME)"; } function HOSTNAME_show() { return 0; }