Skip to content

Instantly share code, notes, and snippets.

@rubensanroman
Created September 30, 2012 13:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rubensanroman/3806704 to your computer and use it in GitHub Desktop.
Save rubensanroman/3806704 to your computer and use it in GitHub Desktop.
Add New Website in CentOS
#!/bin/bash
HTMLPATH="/var/www/html"
VHOSTPATH="/etc/httpd/conf.d"
LOGPATH="/var/log/httpd"
BITBUCKETUSERNAME="username"
if [ $1 = "add" ]; then
# Create html dir
if [ ! -d $HTMLPATH/$2 ]; then
mkdir $HTMLPATH/$2
cd $HTMLPATH/$2
git init
git remote add origin ssh://git@bitbucket.org/$BITBUCKETUSERNAME/$2.git
git pull origin master
else
echo "Error: $HTMLPATH/$2 directory doesn't exists."
exit
fi
# Create logs files
if [ ! -d $LOGPATH/$2 ]; then
mkdir $LOGPATH/$2
touch $LOGPATH/$2/access_log
touch $LOGPATH/$2/error_log
else
echo "Error: $LOGPATH/$2 directory doesn't exists."
exit
fi
# Create the virtual host conf file
if [ ! -f $VHOSTPATH/$2.conf ]; then
echo -e "<VirtualHost *:80>\nServerAdmin root@$2\nDocumentRoot /var/www/html/$2\nServerName $2\nServerAlias www.$2\nCustomLog $LOGPATH/$2/access_log common\nErrorLog $LOGPATH/$2/error_log\n</VirtualHost>" > $VHOSTPATH/$2.conf
else
echo "Error: $VHOSTPATH/$2.conf file doesn't exists."
exit
fi
fi
if [ $1 = "remove" ]; then
read -ep "Are you sure you want to delete $2 ? " -n 1 -r
if [[ $REPLY =~ ^[YySs]$ ]]; then
if [ -d $HTMLPATH/$2 ]; then
rm -rf $HTMLPATH/$2
fi
if [ -d $LOGPATH/$2 ]; then
rm -rf $LOGPATH/$2
fi
if [ -f $VHOSTPATH/$2.conf ]; then
rm $VHOSTPATH/$2.conf
fi
else
exit
fi
fi
# Restart apache
/etc/init.d/httpd restart
/etc/init.d/mysqld restart
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment