Created
April 27, 2012 06:24
-
-
Save ramainen/2506459 to your computer and use it in GitHub Desktop.
С форума денвера
This file contains 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 | |
if [ $UID -ne 0 ]; then | |
gksu -l "$0" | |
exit | |
fi | |
#config | |
hostDir="/home/$SUDO_USER/sites" | |
autoDisable=1 #auto disable all other sites that enabled in /etc/apache2/sites-enabled | |
#disable list | |
cd /etc/apache2/sites-enabled | |
disable=$(ls) | |
disable=${disable//"000-default"} | |
#add exclusion here, e.g: disable=${disable//site.com} | |
sitelist=""; | |
echo "sites available:"; | |
cd $hostDir | |
#get current dirs | |
dirlist=$(find . -maxdepth 1 -type d) | |
for direc in $dirlist ; do | |
if [ $direc == "." ]; then continue; fi | |
sitename=${direc#./} | |
sitelist="$sitelist"' '"$sitename"' '"www.$sitename" | |
subdmnVH="" | |
echo "$sitename with subdomains:" | |
#find subdomains | |
sdlist=$(find "$hostDir"/"$sitename" -maxdepth 1 -mindepth 1 -type d) | |
for sd in $sdlist ; do | |
subdmn=${sd#"$hostDir"/"$sitename"/} | |
echo " $subdmn.$sitename" | |
if [ "$subdmn" == "www" -o "$subdmn" == "cgi-bin" ]; then continue; fi | |
subdmnVH="$subdmnVH"$'\n'"<VirtualHost *:80> | |
ServerName $subdmn.$sitename | |
ServerAlias www.$subdmn.$sitename | |
DocumentRoot $hostDir/$sitename/$subdmn | |
CustomLog $hostDir/$sitename/access.log combined | |
ErrorLog $hostDir/$sitename/error.log | |
<Directory \"$hostDir/$sitename/$subdmn\"> | |
Options FollowSymLinks Includes MultiViews | |
AllowOverride All | |
Order allow,deny | |
Allow from all | |
</Directory> | |
ScriptAlias /cgi-bin/ \"$hostDir/$sitename/cgi-bin/\" | |
</VirtualHost>" | |
sitelist="$sitelist"' '"$subdmn"."$sitename" | |
done | |
#create main virtual host | |
out="<VirtualHost *:80> | |
ServerName $sitename | |
ServerAlias www.$sitename | |
DocumentRoot $hostDir/$sitename/www | |
CustomLog $hostDir/$sitename/access.log combined | |
ErrorLog $hostDir/$sitename/error.log | |
<Directory \"$hostDir/$sitename/www\"> | |
Options FollowSymLinks Includes MultiViews | |
AllowOverride All | |
Order allow,deny | |
Allow from all | |
</Directory> | |
ScriptAlias /cgi-bin/ \"$hostDir/$sitename/cgi-bin/\" | |
</VirtualHost>""$subdmnVH" | |
#tell apache about it | |
echo "$out" > /etc/apache2/sites-available/$sitename; | |
#enable if needed | |
if [ "${disable//$sitename}" == "$disable" ] | |
then a2ensite $sitename | |
fi | |
disable=${disable//$sitename} | |
#fi | |
done | |
#edit hosts | |
sed -n '1h;1!H;${;g;s/\n#AVHBEGIN.*#AVHEND//g;p;}' /etc/hosts > hst.tmp | |
mv -f hst.tmp /etc/hosts | |
echo '#AVHBEGIN' >> /etc/hosts | |
echo "127.0.0.1""$sitelist" >> /etc/hosts | |
echo '#AVHEND' >> /etc/hosts | |
#disable other | |
if [ $autoDisable == 1 ]; then | |
for dis in $disable ; do | |
a2dissite $dis | |
done | |
fi | |
echo "---------------------------------"; | |
#reload apache | |
/etc/init.d/apache2 reload |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment