diff --git a/gentoo.conf b/gentoo.conf index 3ff4e43..e072f26 100644 --- a/gentoo.conf +++ b/gentoo.conf @@ -132,7 +132,7 @@ luks_getkeyfile() { # System configuration # Enter the desired system hostname here, -# be aware that when creating raid arrays, this value will be +# 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. HOSTNAME="gentoo" diff --git a/menu.sh b/menu.sh index e3769a7..88c7d86 100755 --- a/menu.sh +++ b/menu.sh @@ -1,4 +1,5 @@ #!/bin/bash +set -o pipefail ################################################ # Script setup @@ -10,7 +11,11 @@ echo "Please install dialog on your system to use the configurator" ################################################ # Configuration storage +UNSAVED_CHANGES=false +SAVE_AS_FILENAME="gentoo.conf" + HOSTNAME="gentoo" +# TODO get from current system TIMEZONE="Europe/London" KEYMAP="us" KEYMAP_INITRAMFS="$KEYMAP" @@ -35,31 +40,39 @@ INSTALL_SSHD=true ROOT_SSH_AUTHORIZED_KEYS="" -I_HAVE_READ_AND_EDITED_THE_CONFIG_PROPERLY=false - - ################################################ -# Menu +# Menu definition -dialog_save() { - true +MENU_ITEMS=( + "HOSTNAME" + "TIMEZONE" + "KEYMAP" + "LOCALE" + "INIT_SYSTEM" + "KEYFILE" +) + +function HOSTNAME_tag() { echo "Hostname"; } +function HOSTNAME_label() { echo "($HOSTNAME)"; } +function HOSTNAME_menu() { + local sel + sel="$(dialog --clear \ + --help-button --help-label "Menu" \ + --ok-label "Next" --cancel-label "Exit" \ + --extra-button --extra-label "Back" \ + --title "Select hostname" \ + --inputbox "Enter the hostname for your new system." \ + 8 72 "$HOSTNAME" 3>&2 2>&1 1>&3 3>&-)" + UNSAVED_CHANGES=true } -dialog_cancel() { - # TODO really cancel and discard changes? - true -} +function TIMEZONE_tag() { echo "Timezone"; } +function TIMEZONE_label() { echo "($TIMEZONE)"; } +function TIMEZONE_help() { echo "ajajaejaejgj jagj etjghoajf iajgpiajroianer goinaeirogn oairg arga lnaorignap ojkjaprogj iarrgona og"; } -dialog_intro() { - # TODO hi there, in the following configure. - true -} - -dialog_hostname() { - HOSTNAME="$(dialog --clear --help-button --help-label "Menu" --ok-label "Next" --cancel-label "Exit" --extra-button --extra-label "Back" --title "Select hostname" --inputbox "Enter the hostname for your new system." 8 72 "$HOSTNAME" 3>&2 2>&1 1>&3 3>&-)" -} - -dialog_keymap() { +function KEYMAP_tag() { echo "Keymap"; } +function KEYMAP_label() { echo "($KEYMAP)"; } +function KEYMAP_menu() { local items=() local map for map in $(find /usr/share/keymaps/ /usr/share/kbd/keymaps/ -type f -iname '*.map.gz' -printf "%f\n" 2>/dev/null | sort -u); do @@ -70,82 +83,127 @@ dialog_keymap() { items+=("${map}" "off") fi done - KEYMAP="$(dialog --clear --help-button --help-label "Menu" --ok-label "Next" --cancel-label "Exit" --extra-button --extra-label "Back" --noitem --title "Select keymap" --radiolist "Select which keymap to use in the vconsole." 16 72 8 "${items[@]}" 3>&2 2>&1 1>&3 3>&-)" - dialog --title "Not ok" --msgbox "not ok bro" 10 62 - echo $? $KEYMAP + + local sel + sel="$(dialog --clear \ + --help-button --help-label "Menu" \ + --ok-label "Next" --cancel-label "Exit" \ + --extra-button --extra-label "Back" \ + --noitem \ + --title "Select keymap" \ + --radiolist "Select which keymap to use in the vconsole." \ + 16 72 8 "${items[@]}" 3>&2 2>&1 1>&3 3>&-)" } -#create_btrfs_raid_layout swap=8GiB luks=true /dev/sdX -#luks_getkeyfile() { -# case "$1" in -# #'my_luks_partition') echo -n '/path/to/my_luks_partition_keyfile' ;; -# *) echo -n "/path/to/luks-keyfile" ;; -# esac -#} +function LOCALE_tag() { echo "Locale"; } +function LOCALE_label() { echo "($LOCALE)"; } -#dialog_hostname -#dialog_keymap -echo -echo $HOSTNAME -echo $KEYMAP +function INIT_SYSTEM_tag() { echo "Init system"; } +function INIT_SYSTEM_label() { echo "($INIT_SYSTEM)"; } -MENU_ITEMS=( - "HOSTNAME" - "TIMEZONE" - "KEYMAP" - "LOCALE" - "INIT_SYSTEM" -) +function KEYFILE_tag() { echo "Key file"; } +function KEYFILE_label() { echo "($KEYFILE)"; } -HOSTNAME_tag() { - echo "Hostname" + +################################################ +# Menu functions + +# $1: filename +function save() { + echo save to "$1" } -HOSTNAME_item() { - echo "($HOSTNAME)" +function msgbox_help() { + dialog --clear \ + --msgbox "$1" \ + 8 66 3>&2 2>&1 1>&3 3>&- } -TIMEZONE_tag() { - echo "Timezone" +function menu_exit() { + if [[ $UNSAVED_CHANGES == "true" ]]; then + local sel + sel="$(dialog --clear \ + --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)." \ + 8 66 3>&2 2>&1 1>&3 3>&-)" + + local diag_exit="$?" + if [[ $diag_exit == 0 ]]; then + # + save "gentoo.conf" + exit 0 + elif [[ $diag_exit == 1 ]]; then + # + exit 0 + else + # Back to menu (, ) + true + fi + else + # Nothing was changed. Exit immediately. + exit 0 + fi } -TIMEZONE_item() { - echo "($TIMEZONE)" +function menu_save_as() { + local sel + sel="$(dialog --clear \ + --ok-label "Save" \ + --inputbox "Enter a filename to which this configuration should be saved.\n(Press , or choose to abort)." \ + 8 66 "$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 } -KEYMAP_tag() { - echo "Keymap" -} - -KEYMAP_item() { - echo "($KEYMAP)" -} - -LOCALE_tag() { - echo "Locale" -} - -LOCALE_item() { - echo "($LOCALE)" -} - -INIT_SYSTEM_tag() { - echo "Init system" -} - -INIT_SYSTEM_item() { - echo "($INIT_SYSTEM)" -} - -dialog_menu() { +function menu() { local item + local item_tag local tag_item_list=() + declare -A reverse_lookup + + # Create menu list for item in "${MENU_ITEMS[@]}"; do - tag_item_list+=("$(${item}_tag)" "$(${item}_item)") + item_tag="$("${item}_tag")" + tag_item_list+=("$item_tag" "$("${item}_label")") + reverse_lookup["$item_tag"]="$item" done - dialog --clear --title "Gentoo configuration" --ok-label "Select" --cancel-label "Exit" --menu "Main config menu" 16 72 8 "${tag_item_list[@]}" - # TODO double escape -> same as exit -> confirm dialog + + local sel + sel="$(dialog --clear \ + --title "Gentoo configuration" \ + --extra-button --extra-label "Exit" \ + --help-button \ + --ok-label "Select" --cancel-label "Save" \ + --menu "Main config menu" \ + 16 72 8 "${tag_item_list[@]}" 3>&2 2>&1 1>&3 3>&-)" + + local diag_exit="$?" + if [[ $diag_exit == 0 ]]; then + #