Dialog is nice. Proof of concept menu added.
This commit is contained in:
parent
23a5d33790
commit
3ab705d2b0
|
@ -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"
|
||||
|
|
218
menu.sh
218
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 <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() {
|
||||
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 <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() {
|
||||
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
|
||||
# <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
|
||||
}
|
||||
|
||||
|
||||
dialog_menu
|
||||
while true; do
|
||||
menu
|
||||
done
|
||||
|
|
Loading…
Reference in New Issue