Begin cleaning disk definitions, finish all menu points except disk.

This commit is contained in:
oddlama 2021-04-23 01:33:46 +02:00
parent d446af1d6a
commit 5f7acc58c5
No known key found for this signature in database
GPG Key ID: 14EFE510775FE39A
3 changed files with 172 additions and 73 deletions

131
configure vendored
View File

@ -63,9 +63,9 @@ function get_timezone() {
echo "$timezone" echo "$timezone"
else else
# compare files by contents # compare files by contents
# https://stackoverflow.com/questions/12521114/getting-the-canonical-time-zone-name-in-shell-script#comment88637393_12523283 find /usr/share/zoneinfo -type f -exec cmp -s {} /etc/localtime \; -print \
find /usr/share/zoneinfo -type f ! -regex ".*/Etc/.*" -exec \ | sed -e 's,.*/zoneinfo/,,' \
cmp -s {} /etc/localtime \; -print | sed -e 's@.*/zoneinfo/@@' | head -n1 | head -1
fi fi
} }
@ -94,6 +94,10 @@ function get_all_keymaps() {
done done
} }
function get_all_timezones() {
readarray -t ALL_TIMEZONES < <(find /usr/share/zoneinfo -type f -printf "%P\n" | sort -u)
}
function recalculate_locales() { function recalculate_locales() {
LOCALES="" LOCALES=""
N_LOCALES=0 N_LOCALES=0
@ -117,19 +121,33 @@ function recalculate_locales() {
LOCALES="${LOCALES:1}" LOCALES="${LOCALES:1}"
} }
ALL_PARTITIONING_SCHEMES=("single_disk" "raid0_luks" "btrfs_raid" "zfs_raid") ALL_PARTITIONING_SCHEMES=(
PARTITIONING_SCHEME="single_disk" "classic_single_disk" "Classic single disk layout (boot, swap, root)"
"zfs_centric" "ZFS centric (optional raid0/1 and encryption via zfs)"
"btrfs_centric" "Btrfs centric (optional raid0/1 via btrfs)"
"raid0_luks" "Raid0 (N>=2 disks) and luks for root"
"custom" "Custom (edit the config manually later)"
)
PARTITIONING_SCHEME="zfs_centric"
function create_btrfs_raid_layout() { function create_single_disk_layout() {
PARTITIONING_SCHEME="btrfs_raid" create_classic_single_disk_layout
}
function create_classic_single_disk_layout() {
PARTITIONING_SCHEME="classic_single_disk"
} }
function create_raid0_luks_layout() { function create_raid0_luks_layout() {
PARTITIONING_SCHEME="raid0_luks" PARTITIONING_SCHEME="classic_single_disk"
} }
function create_single_disk_layout() { function create_btrfs_raid_layout() {
PARTITIONING_SCHEME="single_disk" create_btrfs_centric_layout
}
function create_btrfs_centric_layout() {
PARTITIONING_SCHEME="btrfs_centric"
} }
@ -137,6 +155,7 @@ function create_single_disk_layout() {
# Configuration constants # Configuration constants
get_all_keymaps get_all_keymaps
get_all_timezones
INIT_SYSTEMS=("systemd" "OpenRC") INIT_SYSTEMS=("systemd" "OpenRC")
ALL_GENTOO_ARCHS=("x86" "amd64" "arm" "arm64") ALL_GENTOO_ARCHS=("x86" "amd64" "arm" "arm64")
readarray -t SUPPORTED_LOCALES < /usr/share/i18n/SUPPORTED readarray -t SUPPORTED_LOCALES < /usr/share/i18n/SUPPORTED
@ -165,6 +184,8 @@ function load_selected_locales() {
} }
function process_config() { function process_config() {
disk_configuration
if [[ "$SYSTEMD" == true ]]; then if [[ "$SYSTEMD" == true ]]; then
INIT_SYSTEM="systemd" INIT_SYSTEM="systemd"
else else
@ -322,6 +343,67 @@ function menu_splitlist() {
fi fi
} }
# $1: title
# $2: description
# $3: default item
# $@: [tag label]...
function menu_radiolist_labeled() {
local title="$1"
local description="$2"
local default_item="$3"
shift 3
# Build option array
local items=()
local tag
local label
while [[ "$#" -gt 0 ]]; do
tag="$1"
label="$2"
shift 2
if [[ $tag == "$default_item" ]]; then
items+=("$tag" "$label" "on")
else
items+=("$tag" "$label" "off")
fi
done
# Show selection dialog
local sel
sel="$(dialog \
--no-tags \
--title "$title" \
--help-button \
--help-label "Select" \
--help-status \
--ok-label "OK" \
--default-item "$default_item" \
--default-button help \
--radiolist "$description\nUse <Select> to select the option under the cursor, or <OK> to use the option which is selected with an asterisk." \
"${RADIOLIST_SIZE[@]}" "${items[@]}" 3>&2 2>&1 1>&3 3>&-)"
local diag_exit="$?"
if [[ $diag_exit == 0 ]]; then
# <OK>
echo -n "$sel"
return 0
elif [[ $diag_exit == 1 ]]; then
# <Cancel>
return 1
elif [[ $diag_exit == 2 ]]; then
# <Select>
local sel="${sel#HELP }"
local sel_cur="${sel% *}"
#local sel_radio="${sel#* }"
echo -n "$sel_cur"
return 0
else
# <ESC><ESC>
return 1
fi
}
# $1: title # $1: title
# $2: description # $2: description
# $3: default item # $3: default item
@ -526,9 +608,9 @@ function PARTITIONING_SCHEME_show() { return 0; }
function PARTITIONING_SCHEME_help() { echo "Select the desired partitioning scheme."; } function PARTITIONING_SCHEME_help() { echo "Select the desired partitioning scheme."; }
function PARTITIONING_SCHEME_menu() { function PARTITIONING_SCHEME_menu() {
local sel local sel
if sel="$(menu_radiolist \ if sel="$(menu_radiolist_labeled \
"Select partitioning scheme" \ "Select partitioning scheme" \
"Select which partitioning scheme you want to follow. Have a look at the help text for this option (available in the menu) for details." \ "Select which partitioning scheme you want to follow. Have a look at the help text for this option (available in the menu) for more details.\n\nAll options support EFI/BIOS, swap and some form of encryption (luks/zfs).\n" \
"$PARTITIONING_SCHEME" \ "$PARTITIONING_SCHEME" \
"${ALL_PARTITIONING_SCHEMES[@]}")" "${ALL_PARTITIONING_SCHEMES[@]}")"
then then
@ -559,9 +641,20 @@ function TIMEZONE_label() { echo "($TIMEZONE)"; }
function TIMEZONE_show() { return 0; } function TIMEZONE_show() { return 0; }
function TIMEZONE_help() { echo "The timezone for the new system."; } function TIMEZONE_help() { echo "The timezone for the new system."; }
function TIMEZONE_menu() { function TIMEZONE_menu() {
# TODO local sel
true if sel="$(menu_radiolist \
UNSAVED_CHANGES=true "Select timezone" \
"Select which timezone to use." \
"$TIMEZONE" \
"${ALL_TIMEZONES[@]}")"
then
# Save timezone
TIMEZONE="$sel"
UNSAVED_CHANGES=true
else
# Return to menu
true
fi
} }
function KEYMAP_tag() { echo "Keymap"; } function KEYMAP_tag() { echo "Keymap"; }
@ -795,13 +888,7 @@ function save() {
################################################ ################################################
# Disk configuration # Disk configuration
create_btrfs_raid_layout swap=8GiB luks=true /dev/sdX $(define_disk_layout)
luks_getkeyfile() {
case "\$1" in
#'my_luks_partition') echo -n '/path/to/my_luks_partition_keyfile' ;;
*) echo -n "/path/to/luks-keyfile" ;;
esac
}
################################################ ################################################

View File

@ -15,53 +15,57 @@
# #
# Be sure to only define one layout! # Be sure to only define one layout!
# 1. create_single_disk_layout function disk_configuration() {
# create_classic_single_disk_layout swap=8GiB type=efi luks=true root_fs=ext4 /dev/sdX
# This layout creates the most common partitioning scheme on a single disk, i.e.
# one boot, one swap and one root partition. Swap can be disabled and the root
# partition can be luks encrypted. This is probably the layout you are most familiar with.
#
# Parameters:
# swap=<size> Create a swap partition with given size, or no swap
# at all if set to false
# type=[efi|bios] Selects the boot type. Defaults to efi if not given.
# luks=[true|false] Encrypt root partition. Defaults to false if not given.
# root_fs=[ext4|btrfs] Root filesystem
#create_single_disk_layout swap=8GiB type=efi luks=true root_fs=ext4 /dev/sdX
# 2. create_raid0_luks_layout # 1. create_classic_single_disk_layout
# #
# This layout creates the single disk layout on multiple disks and combines # This layout creates the most common partitioning scheme on a single disk, i.e.
# the swap and root partitions in separate raid0 arrays. Useful if you e.g. have # one boot, one swap and one root partition. Swap can be disabled and the root
# several nvme drives and want greater speed. Only one boot partition will actually # partition can be luks encrypted. This is probably the layout you are most familiar with.
# be used though. #
# # Parameters:
# Parameters: # swap=<size> Create a swap partition with given size, or no swap
# swap=<size> Create a swap partition with given size for each disk, # at all if set to false
# or no swap at all if set to false # type=[efi|bios] Selects the boot type. Defaults to efi if not given.
# type=[efi|bios] Selects the boot type. Defaults to efi if not given. # luks=[true|false] Encrypt root partition. Defaults to false if not given.
# root_fs=[ext4|btrfs] Root filesystem # root_fs=[ext4|btrfs] Root filesystem
# Careful: You will get N times the swap amount, so be sure to divide beforehand. #create_classic_single_disk_layout swap=8GiB type=efi luks=true root_fs=ext4 /dev/sdX
#create_raid0_luks_layout swap=4GiB type=efi root_fs=ext4 /dev/sd{X,Y}
# 3. create_btrfs_raid_layout # 2. create_raid0_luks_layout
# #
# This layout is the same as the single_disk_layout, but uses btrfs as the root # This layout creates the single disk layout on multiple disks and combines
# filesystem and allows you to put additional disks into the btrfs device pool. # the swap and root partitions in separate raid0 arrays. Useful if you e.g. have
# Only the first disk will have boot and swap partitions, the other disks will # several nvme drives and want greater speed. Only one boot partition will actually
# directly be used in the btrfs device pool. If encryption is enabled, all disks # be used though.
# must be encrypted separately, as btrfs doesn't support encryption itself. #
# Also works with a single device. # Parameters:
# # swap=<size> Create a swap partition with given size for each disk,
# Parameters: # or no swap at all if set to false
# swap=<size> Create a swap partition with given size, or no swap # type=[efi|bios] Selects the boot type. Defaults to efi if not given.
# at all if set to false # root_fs=[ext4|btrfs] Root filesystem
# type=[efi|bios] Selects the boot type. Defaults to efi if not given. # Careful: You will get N times the swap amount, so be sure to divide beforehand.
# luks=[true|false] Encrypt root partition and btrfs devices. Defaults #create_raid0_luks_layout swap=4GiB type=efi root_fs=ext4 /dev/sd{X,Y}
# to false if not given.
# raid_type=[raid0|raid1] Select raid type. Defaults to raid0. # 3. create_btrfs_centric_layout
#create_btrfs_raid_layout swap=8GiB luks=false raid_type=raid0 /dev/sd{X,Y} #
create_btrfs_raid_layout swap=8GiB luks=true /dev/sdX # This layout is the same as the single_disk_layout, but uses btrfs as the root
# filesystem and allows you to put additional disks into the btrfs device pool.
# Only the first disk will have boot and swap partitions, the other disks will
# directly be used in the btrfs device pool. If encryption is enabled, all disks
# must be encrypted separately, as btrfs doesn't support encryption itself.
# Also works with a single device.
#
# Parameters:
# swap=<size> Create a swap partition with given size, or no swap
# at all if set to false
# type=[efi|bios] Selects the boot type. Defaults to efi if not given.
# luks=[true|false] Encrypt root partition and btrfs devices. Defaults
# to false if not given.
# raid_type=[raid0|raid1] Select raid type. Defaults to raid0.
#create_btrfs_centric_layout swap=8GiB luks=false raid_type=raid0 /dev/sd{X,Y}
#create_btrfs_centric_layout swap=8GiB luks=true /dev/sdX
}
################################################ ################################################
@ -121,7 +125,7 @@ create_btrfs_raid_layout swap=8GiB luks=true /dev/sdX
# By default this function returns the same keyfile for all partitions. # By default this function returns the same keyfile for all partitions.
# If you want to make this more granular, run the install script and # If you want to make this more granular, run the install script and
# select here based on the id reported in the partitioning overview. # select here based on the id reported in the partitioning overview.
luks_getkeyfile() { function luks_getkeyfile() {
case "$1" in case "$1" in
#'my_luks_partition') echo -n '/path/to/my_luks_partition_keyfile' ;; #'my_luks_partition') echo -n '/path/to/my_luks_partition_keyfile' ;;
*) echo -n "/path/to/luks-keyfile" ;; *) echo -n "/path/to/luks-keyfile" ;;

View File

@ -252,13 +252,13 @@ expand_ids() {
done done
} }
# Example 1: Single disk, 3 partitions (efi, swap, root) # Single disk, 3 partitions (efi, swap, root)
# Parameters: # Parameters:
# swap=<size> Create a swap partition with given size, or no swap at all if set to false # swap=<size> Create a swap partition with given size, or no swap at all if set to false
# type=[efi|bios] Selects the boot type. Defaults to efi if not given. # type=[efi|bios] Selects the boot type. Defaults to efi if not given.
# luks=[true|false] Encrypt root partition. Defaults to false if not given. # luks=[true|false] Encrypt root partition. Defaults to false if not given.
# root_fs=[ext4|btrfs] Root filesystem # root_fs=[ext4|btrfs] Root filesystem
create_single_disk_layout() { create_classic_single_disk_layout() {
local known_arguments=('+swap' '?type' '?luks' '?root_fs') local known_arguments=('+swap' '?type' '?luks' '?root_fs')
local extra_arguments=() local extra_arguments=()
declare -A arguments; parse_arguments "$@" declare -A arguments; parse_arguments "$@"
@ -314,7 +314,11 @@ create_single_disk_layout() {
fi fi
} }
# Example 2: Multiple disks, with raid 0 and luks create_single_disk_layout() {
die "'create_single_disk_layout' is deprecated, please use 'create_classic_single_disk_layout' instead. It is fully option-compatible to the old version."
}
# Multiple disks, with raid 0 and luks
# - efi: partition on all disks, but only first disk used # - efi: partition on all disks, but only first disk used
# - swap: raid 0 → fs # - swap: raid 0 → fs
# - root: raid 0 → luks → fs # - root: raid 0 → luks → fs
@ -377,14 +381,14 @@ create_raid0_luks_layout() {
fi fi
} }
# Example 3: Multiple disks, up to 3 partitions on first disk (efi, maybe swap, dm-crypt for btrfs). # Multiple disks, up to 3 partitions on first disk (efi, optional swap, root with btrfs).
# Additional devices will be first encrypted and then put directly into btrfs array. # Additional devices will be first encrypted and then put directly into btrfs array.
# Parameters: # Parameters:
# swap=<size> Create a swap partition with given size, or no swap at all if set to false # swap=<size> Create a swap partition with given size, or no swap at all if set to false
# type=[efi|bios] Selects the boot type. Defaults to efi if not given. # type=[efi|bios] Selects the boot type. Defaults to efi if not given.
# luks=[true|false] Encrypt root partition and btrfs devices. Defaults to false if not given. # luks=[true|false] Encrypt root partition and btrfs devices. Defaults to false if not given.
# raid_type=[raid0|raid1] Select raid type. Defaults to raid0. # raid_type=[raid0|raid1] Select raid type. Defaults to raid0.
create_btrfs_raid_layout() { create_btrfs_centric_layout() {
local known_arguments=('+swap' '?type' '?raid_type' '?luks') local known_arguments=('+swap' '?type' '?raid_type' '?luks')
local extra_arguments=() local extra_arguments=()
declare -A arguments; parse_arguments "$@" declare -A arguments; parse_arguments "$@"
@ -449,3 +453,7 @@ create_btrfs_raid_layout() {
DISK_ID_ROOT_TYPE="btrfs" DISK_ID_ROOT_TYPE="btrfs"
DISK_ID_ROOT_MOUNT_OPTS="defaults,noatime,compress=zstd,subvol=/root" DISK_ID_ROOT_MOUNT_OPTS="defaults,noatime,compress=zstd,subvol=/root"
} }
create_btrfs_raid_layout() {
die "'create_btrfs_raid_layout' is deprecated, please use 'create_btrfs_centric_layout' instead. It is fully option-compatible to the old version."
}