#/bin/bash red=`tput setaf 1` green=`tput setaf 2` yellow=`tput setaf 3` bold=`tput bold` blue=`tput setaf 4` reset=`tput sgr0` MY_PATH="`dirname \"$0\"`" # relative MY_PATH="`( cd \"$MY_PATH\" && pwd )`" # absolutized and normalized sslRedir="$MY_PATH/ssl-bloc-redirect.txt" tplVHost="$MY_PATH/templates/vhost.txt" ### # Get Arguments ### args="$@" domain="$1" ip="$2" port="$3" parseArgs(){ i=0 for cmd in $args; do arg[$i]=$cmd [[ ${arg[$i]} =~ "domain=" ]] && domain=$(echo ${arg[$i]} | grep "\ /dev/null sudo sed -i -e 's/$domain/'"$domain"'/g' $newVHost } if [[ -e $newVHost ]]; then echo "${yellow}Le virtualhost existe déjà${reset}" if [[ -z $(grep "ssl_certificate_key" $newVHost) ]]; then echo "Certificat SSL non présent" if [[ $ssl =~ ^(1|true|oui)$ ]]; then echo "Installation du certificat SSL ..." addSSL sudo service nginx reload && echo "${green}Le domaine $domain à bien été créé et configuré =)${reset}" || echo "${red}Impossible de recharger nginx${reset}" exit 0 else echo "${yellow}Aucune action n'a été effectué${reset}" exit 0 fi else echo "${yellow}Le SSL est déjà configuré sur le VHost${reset}" exit 0 fi fi create_vhost(){ echo "${yellow}Génération du nouveau VirtualHost...${reset}" sudo cp $tplVHost $newVHost sudo sed -i -e 's/$_DOMAIN/'"$domain"'/g' $newVHost sudo sed -i -e 's/$_IP/'"$ip"'/g' $newVHost sudo sed -i -e 's/$_PORT/'"$port"'/g' $newVHost if [[ $ssl =~ ^(1|true|oui)$ ]]; then printf "${yellow}Configuration SSL du VHost...${reset}" addSSL && echo "${green}OK${reset}" || echo "${red}KO${reset}" else echo "${yellow}Aucune configuration SSL ne sera effectué.${reset}" fi sudo service nginx reload && echo "${green}Le domaine $domain à bien été créé et configuré =)${reset}" || echo "${red}Impossible de recharger nginx${reset}" } echo "Nous allons créer le domaine ${blue}$domain ${reset}qui sera lié au port ${blue}$port ${reset}de l'IP ${blue}$ip.${reset}" if [[ $p2vmProvided != 1 ]]; then read -p "${bold}Confirmez-vous cette action ?${reset} (${green}y${reset} ou ${red}n${reset}) : " yn case $yn in [Yy]* ) create_vhost break;; [Nn]* ) echo "${red}Fermeture du script${reset}" && exit;; * ) echo "Merci de sélectionner yes ou no";; esac else create_vhost fi exit 0