From e4378cd040533776ff18d7c793643a9ec01e5aaa Mon Sep 17 00:00:00 2001 From: Austin Horstman Date: Fri, 14 Jan 2022 19:17:48 -0600 Subject: [PATCH 1/7] Add input validation to diskpart --- startup.sh | 28 ++++++++++++++++++++-------- 1 file changed, 20 insertions(+), 8 deletions(-) diff --git a/startup.sh b/startup.sh index 5505e0e..392e9cf 100644 --- a/startup.sh +++ b/startup.sh @@ -125,19 +125,31 @@ esac # selection for disk type diskpart () { -# show disks present on system -lsblk -n --output TYPE,KNAME,SIZE | awk '$1=="disk"{print NR,"/dev/"$2" - "$3}' # show disks with /dev/ prefix and size echo -ne " ------------------------------------------------------------------------ - THIS WILL FORMAT AND DELETE ALL DATA ON THE DISK - Please make sure you know what you are doing because - after formating your disk there is no way to get data back + THIS WILL FORMAT AND DELETE ALL DATA ON THE DISK + Please make sure you know what you are doing because + after formating your disk there is no way to get data back ------------------------------------------------------------------------ -Please enter full path to disk: (example /dev/sda): " -read option -echo "DISK=$option" >> setup.conf + +PS3=' +Select the disk to install on: ' +options=($(lsblk -n --output TYPE,KNAME,SIZE | awk '$1=="disk"{print "/dev/"$2"|"$3}')) +select opt in "${options[@]}" +do + +# Positive check +if echo -e '%s\n' "${options[@]}" | grep -Fqw ${opt} 2> /dev/null; then + echo -e "\n${opt%|*} selected \n" + echo "DISK=${opt%|*}" >> setup.conf + break +else + echo -e "\nInvalid selection, please try again. \n" +fi + +done drivessd set_option DISK $option From 7e85502d8ae0e77516be666146ca2a2f89ab6bac Mon Sep 17 00:00:00 2001 From: Austin Horstman Date: Fri, 14 Jan 2022 21:22:40 -0600 Subject: [PATCH 2/7] Keymap input validation --- startup.sh | 53 +++++++++++++++++------------------------------------ 1 file changed, 17 insertions(+), 36 deletions(-) diff --git a/startup.sh b/startup.sh index 392e9cf..377252f 100644 --- a/startup.sh +++ b/startup.sh @@ -73,39 +73,22 @@ esac } keymap () { # These are default key maps as presented in official arch repo archinstall -echo -ne " +options=(-by -ca -cf -cz -de -dk -es -et -fa -fi -fr -gr -hu -il -it -lt -lv -mk -nl -no -pl -ro -ru -sg -ua -uk -us) +PS3=" Please select key board layout from this list - -by - -ca - -cf - -cz - -de - -dk - -es - -et - -fa - -fi - -fr - -gr - -hu - -il - -it - -lt - -lv - -mk - -nl - -no - -pl - -ro - -ru - -sg - -ua - -uk - -us " -read -p "Your key boards layout:" keymap -set_option KEYMAP $keymap +select keymap in "${options[@]}" +do +if echo -e '%s\n' "${options[@]}" | grep -Fqw -- $keymap 2> /dev/null; then + echo -e "\nYour key boards layout: ${keymap} \n" + set_option KEYMAP $keymap + break +else + echo -e "\nInvalid selection, please try again. \n" +fi + +done } drivessd () { @@ -137,13 +120,12 @@ echo -ne " PS3=' Select the disk to install on: ' options=($(lsblk -n --output TYPE,KNAME,SIZE | awk '$1=="disk"{print "/dev/"$2"|"$3}')) -select opt in "${options[@]}" +select disk in "${options[@]}" do -# Positive check -if echo -e '%s\n' "${options[@]}" | grep -Fqw ${opt} 2> /dev/null; then - echo -e "\n${opt%|*} selected \n" - echo "DISK=${opt%|*}" >> setup.conf +if echo -e '%s\n' "${options[@]}" | grep -Fqw ${disk} 2> /dev/null; then + echo -e "\n${disk%|*} selected \n" + set_option DISK ${disk%|*} break else echo -e "\nInvalid selection, please try again. \n" @@ -152,7 +134,6 @@ fi done drivessd -set_option DISK $option } userinfo () { read -p "Please enter your username: " username From 02dd6955471ff81f708f97f84d88ede1fa5f11b7 Mon Sep 17 00:00:00 2001 From: Austin Horstman Date: Fri, 14 Jan 2022 21:35:05 -0600 Subject: [PATCH 3/7] Fix mount options duplicating on rerun --- startup.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/startup.sh b/startup.sh index 377252f..6e289c1 100644 --- a/startup.sh +++ b/startup.sh @@ -99,9 +99,9 @@ read ssd_drive case $ssd_drive in y|Y|yes|Yes|YES) - echo "MOUNT_OPTIONS=noatime,compress=zstd,ssd,commit=120" >> setup.conf;; + set_option MOUNT_OPTIONS "noatime,compress=zstd,ssd,commit=120";; n|N|no|NO|No) - echo "MOUNT_OPTIONS=noatime,compress=zstd,commit=120" >> setup.conf;; + set_option MOUNT_OPTIONS "noatime,compress=zstd,commit=120";; *) echo "Wrong option. Try again";drivessd;; esac } From c2d23eb0e788770bf13b391fe074b916ac7a136c Mon Sep 17 00:00:00 2001 From: Austin Horstman Date: Fri, 14 Jan 2022 21:40:26 -0600 Subject: [PATCH 4/7] Code Commenting --- startup.sh | 2 ++ 1 file changed, 2 insertions(+) diff --git a/startup.sh b/startup.sh index 6e289c1..1370106 100644 --- a/startup.sh +++ b/startup.sh @@ -80,6 +80,7 @@ Please select key board layout from this list " select keymap in "${options[@]}" do +# check if selection is part of list, silence error output and use else block for output if echo -e '%s\n' "${options[@]}" | grep -Fqw -- $keymap 2> /dev/null; then echo -e "\nYour key boards layout: ${keymap} \n" set_option KEYMAP $keymap @@ -123,6 +124,7 @@ options=($(lsblk -n --output TYPE,KNAME,SIZE | awk '$1=="disk"{print "/dev/"$2"| select disk in "${options[@]}" do +# check if selection is part of list, silence error output and use else block for output if echo -e '%s\n' "${options[@]}" | grep -Fqw ${disk} 2> /dev/null; then echo -e "\n${disk%|*} selected \n" set_option DISK ${disk%|*} From 769c077bdbb1dc73419d0b0af632b3d24beb75b8 Mon Sep 17 00:00:00 2001 From: Austin Horstman Date: Fri, 14 Jan 2022 23:25:50 -0600 Subject: [PATCH 5/7] Password validation --- startup.sh | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/startup.sh b/startup.sh index 1370106..fbb231b 100644 --- a/startup.sh +++ b/startup.sh @@ -140,9 +140,20 @@ drivessd userinfo () { read -p "Please enter your username: " username set_option USERNAME ${username,,} # convert to lower case as in issue #109 -echo -ne "Please enter your password: \n" -read -s password # read password without echo -set_option PASSWORD $password +while true; do + echo -ne "Please enter your password: \n" + read -s password # read password without echo + + echo -ne "Please repeat your password: \n" + read -s password2 # read password without echo + + if [ "$password" = "$password2" ]; then + set_option PASSWORD $password + break + else + echo -e "\nPasswords do not match. Please try again. \n" + fi +done read -rep "Please enter your hostname: " nameofmachine set_option NAME_OF_MACHINE $nameofmachine } From 13b4ff1552b23f454bb09340431b23218f3d53ac Mon Sep 17 00:00:00 2001 From: Austin Horstman Date: Sat, 15 Jan 2022 16:32:39 -0600 Subject: [PATCH 6/7] Remove dash from keymaps --- startup.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/startup.sh b/startup.sh index fbb231b..9ef9a36 100644 --- a/startup.sh +++ b/startup.sh @@ -73,7 +73,7 @@ esac } keymap () { # These are default key maps as presented in official arch repo archinstall -options=(-by -ca -cf -cz -de -dk -es -et -fa -fi -fr -gr -hu -il -it -lt -lv -mk -nl -no -pl -ro -ru -sg -ua -uk -us) +options=(by ca cf cz de dk es et fa fi fr gr hu il it lt lv mk nl no pl ro ru sg ua uk us) PS3=" Please select key board layout from this list @@ -81,7 +81,7 @@ Please select key board layout from this list select keymap in "${options[@]}" do # check if selection is part of list, silence error output and use else block for output -if echo -e '%s\n' "${options[@]}" | grep -Fqw -- $keymap 2> /dev/null; then +if echo -e '%s\n' "${options[@]}" | grep -Fqw $keymap 2> /dev/null; then echo -e "\nYour key boards layout: ${keymap} \n" set_option KEYMAP $keymap break From d0d121bc1556d5b91d6a02931c7f158a4e5d7e80 Mon Sep 17 00:00:00 2001 From: Austin Horstman Date: Sun, 16 Jan 2022 15:18:59 -0600 Subject: [PATCH 7/7] Input validation on luks password, same as user password --- startup.sh | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/startup.sh b/startup.sh index 9ef9a36..76bf882 100644 --- a/startup.sh +++ b/startup.sh @@ -47,10 +47,22 @@ case $fs in 1) set_option FS btrfs;; 2) set_option FS ext4;; 3) -echo -ne "Please enter your luks password: " -read -s luks_password # read password without echo -set_option LUKS_PASSWORD $luks_password -set_option FS luks;; +while true; do + echo -ne "Please enter your luks password: \n" + read -s luks_password # read password without echo + + echo -ne "Please repeat your luks password: \n" + read -s luks_password2 # read password without echo + + if [ "$luks_password" = "$luks_password2" ]; then + set_option LUKS_PASSWORD $luks_password + set_option FS luks + break + else + echo -e "\nPasswords do not match. Please try again. \n" + fi +done +;; 0) exit ;; *) echo "Wrong option please select again"; filesystem;; esac