#!/bin/bash
clear
basedir=$(pwd)
servn=$1



chmod -R 777 /etc/apache2/sites-available/

echo "Virtual host creation" 
echo "#### VHOST FOR $servn
<VirtualHost *:80>
DocumentRoot $basedir
ServerName $servn
ServerAlias www.$servn
<Directory $basedir>
AllowOverride All
Order allow,deny
allow from all
</Directory>
ErrorLog /var/log/apache2/$servn-error_log
CustomLog /var/log/apache2/$servn-access_log common
</VirtualHost>" > /etc/apache2/sites-available/$servn.conf
if ! echo -e /etc/apache2/sites-available/$servn.conf; then 
echo "--FAIL to create Virtual for $servn created !"
else
echo "--Virtual host for $servn created !"  
fi

echo "Web activation" 
sudo a2ensite $servn.conf
sudo systemctl restart apache2
echo "DONE" 

chmod -R 755 /etc/apache2/sites-available/



echo "SSL Activation" 
sudo certbot -d $servn --apache --agree-tos -m amin.uzan@gmail.com --no-eff-email --redirect
sudo systemctl status certbot.timer
#sudo certbot renew --dry-run
echo "DONE"
