среда, 15 февраля 2012 г.

Virtuala hosta izveidosanas script

 mv /etc/apache2/sites-enabled/wordpress2 /var/www/.vhost.tmp            faila parvietosana

#!/bin/bash
vhost=$1
vhostsdir="/var/vhosts/"
apacheconf="/etc/apache2/sites-enabled/"
shablon="/var/www/.conf.tpl"

cd $vhostsdir
pwd
mkdir $vhost -m 755 -v
echo "<h1>This is $vhost</h1>" > $vhost/$vhost.html

cd $apacheconf
pwd
# -d vai ir, un ka ir katalogs
# -f vai ir tads fails
# -r | -w | -x
# -e vai ir objekts
if [ -f $shablon ]
then
        echo "Fails atrasts $shablon"
else
        echo -e "\n\tFails nav atrasts $shablon\n"
        exit
fi
# http://www.cyberciti.biz/faq/unix-linux-replace-string-words-in-many-files/
sed "s/{wordpress}/$vhost/g" $shablon > $vhost

cp -v /etc/hosts /etc/hosts_bak_$(date +%Y-%m-%d_%H-%M-%S)

echo -e "127.0.0.1\t$vhost" >> /etc/hosts
echo "+-----------------------------------+"
echo -e "Ir pielikts:\n\n\t127.0.0.1\t$vhost"
echo "+-----------------------------------+"
echo

# ekvivalents DOS pause komandai
# http://stackoverflow.com/questions/92802/what-is-the-linux-equivalent-to-dos-pause
read -n1 -r -p "Press any key to continue..." key

nano /etc/hosts
/etc/init.d/apache2 restart
echo -e "\n\nHosti:\n"
ls /var/vhosts/


Комментариев нет:

Отправить комментарий