Advertisement
imShara

XAMPP gen vhosts and toggle

Feb 28th, 2013
521
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 1.19 KB | None | 0 0
  1. #!/bin/bash
  2. # Shara 2012
  3. # free4all
  4.  
  5. sitesDir="/home/shara/Sites"
  6. hostsFile="/etc/hosts"
  7. xamppVHosts="/opt/lampp/etc/extra/httpd-vhosts.conf"
  8.  
  9. if [[ "$(pgrep httpd)" && "$(pgrep mysql)" && "$(pgrep ftpd)" ]]
  10.     then
  11.  
  12.         action="XAMPP stoped..."
  13.         answer=`/opt/lampp/lampp stop`
  14.  
  15.     else
  16.  
  17.         # Clear hostsFile
  18.         clearhosts=`sed '/#XAMPP virtual hosts/ {N; /.*\n.*/d}' $hostsFile`
  19.         echo "$clearhosts" > $hostsFile
  20.  
  21.         # Set hostsFile
  22.         cd $sitesDir
  23.         siteNames=`ls -d *`
  24.         hostsLine="127.0.0.1 $siteNames"
  25.         echo -e "#XAMPP virtual hosts\n"$hostsLine"\n" >> $hostsFile
  26.  
  27.         # Delete xamppVHosts
  28.         rm $xamppVHosts
  29.  
  30.         # Set xamppVHosts
  31.         addrarr=($siteNames)
  32.         for address in "${addrarr[@]}"
  33.         do
  34.      echo -e "<VirtualHost 127.0.0.1:80>
  35.         DocumentRoot $sitesDir/$address
  36.         ServerName $address
  37.         ServerAlias www.$address
  38.         ErrorLog $sitesDir/$address/$address.error.log
  39.         CustomLog $sitesDir/$address/$address.access.log common
  40.         <Directory $sitesDir/$address>
  41.            Require all granted
  42.         </Directory>    
  43.     </VirtualHost>\n" >> $xamppVHosts
  44.         done
  45.  
  46.         action="XAMPP started..."
  47.         answer=`/opt/lampp/lampp start`
  48.  
  49.     fi
  50.  
  51. notify-send -t 5500 "$action" "$answer"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement