From c463be70a242da8c70ab3dc2e9fba435f5f4ce33 Mon Sep 17 00:00:00 2001 From: Matthew Saunders Brown Date: Thu, 30 Mar 2023 14:57:07 -0700 Subject: [PATCH] username can be between 3 and 12 characters --- bin/vhost-deploy.sh | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/bin/vhost-deploy.sh b/bin/vhost-deploy.sh index 0fce5c4..8ea283d 100755 --- a/bin/vhost-deploy.sh +++ b/bin/vhost-deploy.sh @@ -37,7 +37,7 @@ if [[ -d /srv/www/$domain ]] || [[ -f /etc/apache2/sites-available/$domain.conf exit 1 fi -# check for and set username +# check for and set username (length between 3 and 12 characters) if [[ -z "$username" ]]; then strippeddomain=`echo $domain | sed 's|\.||'` strippeddomain=`echo $strippeddomain | sed 's|-||'` @@ -64,8 +64,19 @@ if [[ -z "$username" ]]; then # username already exists, try another username=`echo ${strippeddomain:0:12}` if grep -q "^$username:" /etc/passwd; then - echo "trouble setting unique username, specify '-u USERNAME' to use an existing username" - exit 1 + # username already exists, try another + username=`echo ${strippeddomain:0:4}` + if grep -q "^$username:" /etc/passwd; then + # username already exists, try another + username=`echo ${strippeddomain:0:3}` + if grep -q "^$username:" /etc/passwd; then + # username already exists, try another + if grep -q "^$username:" /etc/passwd; then + echo "trouble setting unique username, specify '-u USERNAME' to use an existing username" + exit 1 + fi + fi + fi fi fi fi