Last active
January 21, 2018 19:38
-
-
Save jasonbronson/6ae5d43f558471dcc3f1487aaa66851d to your computer and use it in GitHub Desktop.
build the apache2 conf files from list of web directory
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
#find /web/ -maxdepth 1 -type d > domainlist.csv | |
find /web/ -maxdepth 1 -type d | sed 's/\/web\///g' > domainlist.csv | |
apachelogdir=/var/log/apache2/ | |
if [ "$(whoami)" != 'root' ]; then | |
echo "You have to execute this script as root user" | |
exit 1; | |
fi | |
while read p; do | |
echo $p | |
echo "#### $p | |
<VirtualHost *:80> | |
ServerName $p | |
ServerAlias www.$p | |
DocumentRoot /web/$p | |
<Directory /web/$p> | |
Options Indexes FollowSymLinks MultiViews | |
AllowOverride All | |
Order allow,deny | |
Allow from all | |
Require all granted | |
</Directory> | |
ErrorLog $apachelogdir/$p_error.log | |
CustomLog $apachelogdir/$p_access.log combined | |
</VirtualHost>" > /etc/apache2/sites-enabled/$p.conf | |
if ! echo -e /etc/apache2/sites-enabled/$p.conf; then | |
echo "Virtual host wasn't created !" | |
else | |
echo "Virtual host created !" | |
fi | |
done<domainlist.csv | |
echo "Testing configuration" | |
service apache2 configtest | |
echo "Would you like me to restart the server [y/n]? " | |
read q | |
if [[ "${q}" == "yes" ]] || [[ "${q}" == "y" ]]; then | |
service apache2 restart | |
fi | |
echo "======================================" | |
echo "All works done! " | |
echo "" | |
echo "Wanna contribute to improve this script? Found a bug? https://gist.github.com/jasonbronson/6ae5d43f558471dcc3f1487aaa66851d" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment