From 145a0add3451945096005b3833197c429a1b8b98 Mon Sep 17 00:00:00 2001 From: Marvin Roman Date: Fri, 19 Nov 2021 21:45:04 -0800 Subject: [PATCH] validate username before using in the script --- 1-setup.sh | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/1-setup.sh b/1-setup.sh index 73904f1..535d0b5 100755 --- a/1-setup.sh +++ b/1-setup.sh @@ -236,7 +236,19 @@ fi echo -e "\nDone!\n" if ! source install.conf; then - read -p "Please enter username:" username + # Loop through user input until the user gives a valid username + valid_username=false + while [[ "$valid_username" = false ]]; do + read -p "Please enter username:" username + # username regex per response here https://unix.stackexchange.com/questions/157426/what-is-the-regex-to-validate-linux-users + if [[ "$username" =~ ^[a-z_]([a-z0-9_-]{0,31}|[a-z0-9_-]{0,30}\$)$ ]] + then + valid_username=true + else + echo "You haven't entered a valid username." + fi + done + echo "username=$username" >> ${HOME}/ArchTitus/install.conf fi if [ $(whoami) = "root" ];