diff options
author | Vlad Doster <mvdoster@gmail.com> | 2020-05-31 15:37:31 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-05-31 15:37:31 -0500 |
commit | 3cc8675993e78e2ed072d75a5773fddd7bd94be9 (patch) | |
tree | 7aa8cbc70de2308b1fb341a1a630d7c344b038d3 | |
parent | 6b88d36033ad517c2a22fad145aca6a994871291 (diff) |
reduce redundant code into 2 functions
- much easier to read
- reduce places to change
- reusable if ever need to add more inputs
-rw-r--r-- | larbs.sh | 14 |
1 files changed, 8 insertions, 6 deletions
@@ -34,6 +34,8 @@ else fi error() { clear; printf "ERROR:\\n%s\\n" "$1"; exit;} +input_box() { dialog --inputbox "$1" 10 60 3>&1 1>&2 2>&3 3>&1 } +password_box() { dialog --no-cancel --passwordbox "$1" 10 60 3>&1 1>&2 2>&3 3>&1 } welcomemsg() { \ dialog --title "Welcome!" --msgbox "Welcome to Luke's Auto-Rice Bootstrapping Script!\\n\\nThis script will automatically install a fully-featured Linux desktop, which I use as my main machine.\\n\\n-Luke" 10 60 @@ -47,16 +49,16 @@ selectdotfiles() { \ getuserandpass() { \ # Prompts user for new username an password. - name=$(dialog --inputbox "First, please enter a name for the user account." 10 60 3>&1 1>&2 2>&3 3>&1) || exit + name=$(input_box "First, please enter a name for the user account.") || exit while ! echo "$name" | grep "^[a-z_][a-z0-9_-]*$" >/dev/null 2>&1; do - name=$(dialog --no-cancel --inputbox "Username not valid. Give a username beginning with a letter, with only lowercase letters, - or _." 10 60 3>&1 1>&2 2>&3 3>&1) + name=$(input_box "Username not valid. Give a username beginning with a letter, with only lowercase letters, - or _.") done - pass1=$(dialog --no-cancel --passwordbox "Enter a password for that user." 10 60 3>&1 1>&2 2>&3 3>&1) - pass2=$(dialog --no-cancel --passwordbox "Retype password." 10 60 3>&1 1>&2 2>&3 3>&1) + pass1=$(password_box "Enter a password for that user.") + pass2=$(password_box "Retype password.") while ! [ "$pass1" = "$pass2" ]; do unset pass2 - pass1=$(dialog --no-cancel --passwordbox "Passwords do not match.\\n\\nEnter password again." 10 60 3>&1 1>&2 2>&3 3>&1) - pass2=$(dialog --no-cancel --passwordbox "Retype password." 10 60 3>&1 1>&2 2>&3 3>&1) + pass1=$(password_box "Passwords do not match.\\n\\nEnter password again.") + pass2=$(password_box "Retype password.") done ;} usercheck() { \ |