Dialog is nice. Proof of concept menu added.

This commit is contained in:
oddlama 2021-04-21 14:23:55 +02:00
parent 23a5d33790
commit 3ab705d2b0
No known key found for this signature in database
GPG Key ID: 14EFE510775FE39A
2 changed files with 139 additions and 81 deletions

View File

@ -132,7 +132,7 @@ luks_getkeyfile() {
# System configuration # System configuration
# Enter the desired system hostname here, # 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 # recorded in metadata block. If you change it later, you should
# also update the metadata. # also update the metadata.
HOSTNAME="gentoo" HOSTNAME="gentoo"

218
menu.sh
View File

@ -1,4 +1,5 @@
#!/bin/bash #!/bin/bash
set -o pipefail
################################################ ################################################
# Script setup # Script setup
@ -10,7 +11,11 @@ echo "Please install dialog on your system to use the configurator"
################################################ ################################################
# Configuration storage # Configuration storage
UNSAVED_CHANGES=false
SAVE_AS_FILENAME="gentoo.conf"
HOSTNAME="gentoo" HOSTNAME="gentoo"
# TODO get from current system
TIMEZONE="Europe/London" TIMEZONE="Europe/London"
KEYMAP="us" KEYMAP="us"
KEYMAP_INITRAMFS="$KEYMAP" KEYMAP_INITRAMFS="$KEYMAP"
@ -35,31 +40,39 @@ INSTALL_SSHD=true
ROOT_SSH_AUTHORIZED_KEYS="" ROOT_SSH_AUTHORIZED_KEYS=""
I_HAVE_READ_AND_EDITED_THE_CONFIG_PROPERLY=false
################################################ ################################################
# Menu # Menu definition
dialog_save() { MENU_ITEMS=(
true "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() { function TIMEZONE_tag() { echo "Timezone"; }
# TODO really cancel and discard changes? function TIMEZONE_label() { echo "($TIMEZONE)"; }
true function TIMEZONE_help() { echo "ajajaejaejgj jagj etjghoajf iajgpiajroianer goinaeirogn oairg arga lnaorignap ojkjaprogj iarrgona og"; }
}
dialog_intro() { function KEYMAP_tag() { echo "Keymap"; }
# TODO hi there, in the following configure. function KEYMAP_label() { echo "($KEYMAP)"; }
true function KEYMAP_menu() {
}
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() {
local items=() local items=()
local map 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 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") items+=("${map}" "off")
fi fi
done 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 local sel
echo $? $KEYMAP 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 function LOCALE_tag() { echo "Locale"; }
#luks_getkeyfile() { function LOCALE_label() { echo "($LOCALE)"; }
# case "$1" in
# #'my_luks_partition') echo -n '/path/to/my_luks_partition_keyfile' ;;
# *) echo -n "/path/to/luks-keyfile" ;;
# esac
#}
#dialog_hostname function INIT_SYSTEM_tag() { echo "Init system"; }
#dialog_keymap function INIT_SYSTEM_label() { echo "($INIT_SYSTEM)"; }
echo
echo $HOSTNAME
echo $KEYMAP
MENU_ITEMS=( function KEYFILE_tag() { echo "Key file"; }
"HOSTNAME" function KEYFILE_label() { echo "($KEYFILE)"; }
"TIMEZONE"
"KEYMAP"
"LOCALE"
"INIT_SYSTEM"
)
HOSTNAME_tag() {
echo "Hostname" ################################################
# Menu functions
# $1: filename
function save() {
echo save to "$1"
} }
HOSTNAME_item() { function msgbox_help() {
echo "($HOSTNAME)" dialog --clear \
--msgbox "$1" \
8 66 3>&2 2>&1 1>&3 3>&-
} }
TIMEZONE_tag() { function menu_exit() {
echo "Timezone" 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 <ESC><ESC>, or choose <Back> to continue gentoo configuration)." \
8 66 3>&2 2>&1 1>&3 3>&-)"
local diag_exit="$?"
if [[ $diag_exit == 0 ]]; then
# <Save>
save "gentoo.conf"
exit 0
elif [[ $diag_exit == 1 ]]; then
# <Discard>
exit 0
else
# Back to menu (<ESC><ESC>, <Back>)
true
fi
else
# Nothing was changed. Exit immediately.
exit 0
fi
} }
TIMEZONE_item() { function menu_save_as() {
echo "($TIMEZONE)" local sel
sel="$(dialog --clear \
--ok-label "Save" \
--inputbox "Enter a filename to which this configuration should be saved.\n(Press <ESC><ESC>, or choose <Cancel> to abort)." \
8 66 "$SAVE_AS_FILENAME" 3>&2 2>&1 1>&3 3>&-)"
local diag_exit="$?"
if [[ $diag_exit == 0 ]]; then
# <Save>
SAVE_AS_FILENAME="$sel"
save "$SAVE_AS_FILENAME"
UNSAVED_CHANGES=false
else
# Back to menu (<ESC><ESC>, <Cancel>)
true
fi
} }
KEYMAP_tag() { function menu() {
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() {
local item local item
local item_tag
local tag_item_list=() local tag_item_list=()
declare -A reverse_lookup
# Create menu list
for item in "${MENU_ITEMS[@]}"; do 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 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
# <Select>
"${reverse_lookup[$sel]}_menu"
elif [[ $diag_exit == 1 ]]; then
# <Save>
menu_save_as
elif [[ $diag_exit == 2 ]]; then
# <Help>
msgbox_help "$("${reverse_lookup[${sel#HELP }]}_help")"
else
# Exit (<ESC><ESC>, <Exit>)
menu_exit
true
fi
} }
while true; do
dialog_menu menu
done