check for user in vhost and user creation

This commit is contained in:
Bachir Soussi Chiadmi 2018-04-07 12:47:24 +02:00
parent 6e5433b041
commit c5a8b8b87b
3 changed files with 77 additions and 25 deletions

View File

@ -7,29 +7,29 @@ _cwd="$(pwd)"
while [ "$_bare_name" = "" ]
do
read -p "enter the bare repos folder name ? " _bare_name
if [ "$_bare_name" != "" ]; then
read -p "is bare folder name $_bare_name correcte [y|n] " validated
if [ "$validated" = "y" ]; then
break
else
_bare_name=""
read -p "enter the bare repos folder name ? " _bare_name
if [ "$_bare_name" != "" ]; then
read -p "is bare folder name $_bare_name correcte [y|n] " validated
if [ "$validated" = "y" ]; then
break
else
_bare_name=""
fi
fi
fi
done
while [ "$_prod_folder_path" = "" ]
do
read -p "enter the prod folder path (must be a public_html parent's) ? " _prod_folder_path
if [ "$_prod_folder_path" != "" ]; then
# TODO check if path exists
read -p "is prod folder path $_prod_folder_path correcte [y|n] " validated
if [ "$validated" = "y" ]; then
break
else
_prod_folder_path=""
read -p "enter the prod folder path (must be a public_html parent's) ? " _prod_folder_path
if [ "$_prod_folder_path" != "" ]; then
# TODO check if path exists
read -p "is prod folder path $_prod_folder_path correcte [y|n] " validated
if [ "$validated" = "y" ]; then
break
else
_prod_folder_path=""
fi
fi
fi
done
# ask for simple php conf or drupal conf

View File

@ -16,10 +16,28 @@ fi
sleep 3
# TODO check if root
echo -n "Enter user name: "
read user
while [ "$user" = "" ]
do
read -p "enter a user name ? " user
if [ "$user" != "" ]; then
# check if user already exists
if id "$user" >/dev/null 2>&1; then
echo "user $user alreday exists, you must provide a non existing user name."
user=""
else
read -p "is user name $user correcte [y|n] " validated
if [ "$validated" = "y" ]; then
break
else
user=""
fi
fi
fi
done
# read -p "Continue? (Y/N): " confirm && [[ $confirm == [yY] || $confirm == [yY][eE][sS] ]] || exit 1
adduser "$user"
echo "adding $user to admin group and limiting su to the admin group"

View File

@ -9,9 +9,9 @@ echo '\033[35m
echo "\033[35;1mNginx VHOST install \033[0m"
while [ "$vh" != "y" ] && [ "$vh" != "n" ]
do
echo -n "Should we install a vhost? [y|n] "
read vh
# vh=${vh:-y}
echo -n "Should we install a vhost? [y|n] "
read vh
# vh=${vh:-y}
done
if [ "$vh" = "y" ]; then
@ -84,10 +84,44 @@ if [ "$vh" = "y" ]; then
# create a shortcut to the site
# TODO ask for $user name if not existing
mkdir /home/"$user"/www/
chown "$user":admin /home/"$user"/www/
ln -s /var/www/"$_domain" /home/"$user"/www/"$_domain"
echo -n "Should we install a shortcut for a user? [Y|n] "
read yn
yn=${yn:-y}
if [ "$yn" = "y" ]; then
if [ -z ${user+x} ]; then
echo -n "Enter an existing user name: "
read user
while [ "$user" = "" ]
do
read -p "enter a user name ? " user
if [ "$user" != "" ]; then
check if user already exists
if id "$user" >/dev/null 2>&1; then
read -p "is user name $user correcte [y|n] " validated
if [ "$validated" = "y" ]; then
break
else
user=""
fi
else
echo "user $user doesn't exists, you must provide an existing user"
user=""
fi
fi
done
fi
echo "shortcut will be installed for '$user'";
sleep 3
mkdir /home/"$user"/www/
chown "$user":admin /home/"$user"/www/
ln -s /var/www/"$_domain" /home/"$user"/www/"$_domain"
else
echo 'no shortcut installed'
fi
# activate the vhost
ln -s /etc/nginx/sites-available/"$_domain".conf /etc/nginx/sites-enabled/"$_domain".conf