From 5ac4e936f7a53447080db973ed3c3338ee039284 Mon Sep 17 00:00:00 2001 From: Matthew Saunders Brown Date: Tue, 3 May 2022 16:44:00 -0700 Subject: [PATCH] reduce redundant username generation code --- bin/vhost-deploy.sh | 34 ++++++++++------------------------ 1 file changed, 10 insertions(+), 24 deletions(-) diff --git a/bin/vhost-deploy.sh b/bin/vhost-deploy.sh index e71baf1..1c7b8d3 100755 --- a/bin/vhost-deploy.sh +++ b/bin/vhost-deploy.sh @@ -38,44 +38,30 @@ fi # check for and set username if [[ -z "$username" ]]; then - username=`echo $domain | sed 's|\.||'` - username=`echo $username | sed 's|-||'` - username=`echo ${username:0:8}` + stippeddomain=`echo $domain | sed 's|\.||'` + stippeddomain=`echo $stippeddomain | sed 's|-||'` + username=`echo ${stippeddomain:0:8}` if grep -q "^$username:" /etc/passwd; then # username already exists, try another - username=`echo $domain | sed 's|\.||'` - username=`echo $username | sed 's|-||'` - username=`echo ${username:0:7}` + username=`echo ${stippeddomain:0:7}` if grep -q "^$username:" /etc/passwd; then # username already exists, try another - username=`echo $domain | sed 's|\.||'` - username=`echo $username | sed 's|-||'` - username=`echo ${username:0:6}` + username=`echo ${stippeddomain:0:6}` if grep -q "^$username:" /etc/passwd; then # username already exists, try another - username=`echo $domain | sed 's|\.||'` - username=`echo $username | sed 's|-||'` - username=`echo ${username:0:5}` + username=`echo ${stippeddomain:0:5}` if grep -q "^$username:" /etc/passwd; then # username already exists, try another - username=`echo $domain | sed 's|\.||'` - username=`echo $username | sed 's|-||'` - username=`echo ${username:0:9}` + username=`echo ${stippeddomain:0:9}` if grep -q "^$username:" /etc/passwd; then # username already exists, try another - username=`echo $domain | sed 's|\.||'` - username=`echo $username | sed 's|-||'` - username=`echo ${username:0:10}` + username=`echo ${stippeddomain:0:10}` if grep -q "^$username:" /etc/passwd; then # username already exists, try another - username=`echo $domain | sed 's|\.||'` - username=`echo $username | sed 's|-||'` - username=`echo ${username:0:11}` + username=`echo ${stippeddomain:0:11}` if grep -q "^$username:" /etc/passwd; then # username already exists, try another - username=`echo $domain | sed 's|\.||'` - username=`echo $username | sed 's|-||'` - username=`echo ${username:0:12}` + username=`echo ${stippeddomain:0:12}` if grep -q "^$username:" /etc/passwd; then echo "trouble setting unique username, specify '-u USERNAME' to use an existing username" exit 1