username can be between 3 and 12 characters

This commit is contained in:
Matthew Saunders Brown 2023-03-30 14:57:07 -07:00
parent e4e4d4e47a
commit c463be70a2

View File

@ -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|-||'`
@ -63,6 +63,14 @@ if [[ -z "$username" ]]; then
if grep -q "^$username:" /etc/passwd; then
# username already exists, try another
username=`echo ${strippeddomain:0:12}`
if grep -q "^$username:" /etc/passwd; then
# 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
@ -75,6 +83,9 @@ if [[ -z "$username" ]]; then
fi
fi
fi
fi
fi
fi
if ! grep -q "^$username:" /etc/passwd; then
# check for and set password