From 4c69decdadb5ffb60c21f70e0b6346b18fcc4e2f Mon Sep 17 00:00:00 2001 From: teldra Date: Mon, 7 Feb 2022 03:58:13 +0100 Subject: [PATCH] progress --- functions | 44 ++++++++++++++++++++++++++++++++++++++++++-- main.sh | 14 +++++++------- 2 files changed, 49 insertions(+), 9 deletions(-) diff --git a/functions b/functions index 7264bb9..8d11242 100644 --- a/functions +++ b/functions @@ -4,7 +4,7 @@ err() { exit 1 } -input() { +input_old() { local input local found="0" echo "$1 $2" @@ -40,4 +40,44 @@ reset() { if [ "$1" == "packages" ]; then function packages() { :; } fi -} \ No newline at end of file +} + +input() { + output="" + echo "${1}" + read -r -p "[${2}]: " output + test -z "${output}" && output="${2}" + return 0 +} + +#multiplechoice "networksystem" "dhcpcd" "networkmanager" "iwd" "none" + +multiplechoice() { + output="" + local done="" + local input=("${@}") + for i in $(seq 1 "$(( ${#input[@]} - 1 ))"); do + if [[ "${i}" == "1" ]]; then + choices="${input[$i]}" + use="${input[$i]}" + else + choices="${choices}|${input[$i]}" + use+=" ${input[$i]}" + fi + done + while input "[${choices}]: " "${input[1]}"; do + for i in $(seq 1 "$(( ${#input[@]} - 1 ))"); do + if [[ "${output}" == "${input[$i]}" ]] || [[ "${output}" == "${input[$i]:0:2}" ]]; then + echo setconf add "${1}" "${input[$i]}" + done=1 + fi + done + if [[ -z "${done}" ]]; then + echo wronginput "${output}" + echo use these: "${use}" + else + break + fi + + done +} diff --git a/main.sh b/main.sh index a733163..69f7ac1 100644 --- a/main.sh +++ b/main.sh @@ -20,7 +20,7 @@ target_phy_disk() { local output DISKS_DETAILS=$(lsblk -l -o KNAME,TYPE,SIZE,MODEL,WWN|grep disk) echo "$DISKS_DETAILS" - input "which one?" "$(echo "$DISKS_DETAILS"|awk '{print $1}'|tr '\n' ' ')" "not found." + input_old "which one?" "$(echo "$DISKS_DETAILS"|awk '{print $1}'|tr '\n' ' ')" "not found." TARGET_PHY_DISK="/dev/${output}" } @@ -64,7 +64,7 @@ encryption_style() { echo "c)no keyfile (double pw enter)" #bios: 1 uefi: 2 echo "d)keyfile on usb" #bios: 1 uefi: ? echo "e)unencrypted boot" #bios: 2 uefi: 2 - input "how to encrypt?" "a b c d e" "wrong input" + multiplechoice "a" "b" "c" "d" "e" ENCRYPTION_STYLE="$output" } @@ -162,7 +162,7 @@ base() { } gfx() { - input "Which GFX System?" "amd nvidia intel" "unknown error" + input_old "Which GFX System?" "amd nvidia intel" "unknown error" GFX=$output . ./etc/gfx/$GFX packages @@ -170,7 +170,7 @@ gfx() { } soundsystem() { - input "Which Soundsystem" "pulseaudio pipewire" "unknown error" + input_old "Which Soundsystem" "pulseaudio pipewire" "unknown error" SOUNDSYSTEM=$output . ./etc/soundsystem/$SOUNDSYSTEM packages @@ -178,7 +178,7 @@ soundsystem() { } de() { - input "Which Desktop Environment?" "plasma gnome minimal" "unknown error" + input_old "Which Desktop Environment?" "plasma gnome minimal" "unknown error" DE=$output if ! [ "$DE" == "minimal" ]; then gfx @@ -190,14 +190,14 @@ de() { } printing() { - input "Do you want printing?" "yes no" "unknown error" + input_old "Do you want printing?" "yes no" "unknown error" if [ "$output" == "yes" ]; then addpkg cups fi } lang() { - input "Which language?" "de en" "unknown error" + input_old "Which language?" "de en" "unknown error" LANGUAGE=$output if [ "$LANGUAGE" == "de" ]; then L1=de_DE