Created
October 14, 2011 15:40
-
-
Save nedmas/1287451 to your computer and use it in GitHub Desktop.
Just a simple bash script for adding new sites on an apache server
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 | |
while getopts ":h:p:a:d:l:" opt; do | |
case $opt in | |
h) | |
HOST="$OPTARG" | |
;; | |
p) | |
PORT="$OPTARG" | |
;; | |
a) | |
SERVER_ADMIN="$OPTARG" | |
;; | |
d) | |
DOCUMENT_ROOT="$OPTARG" | |
;; | |
l) | |
LOG_DIR="$OPTARG" | |
;; | |
\?) | |
echo "Invalid option: -$OPTARG" >&2 | |
exit 1 | |
;; | |
:) | |
echo "Option -$OPTARG requires an argument." >&2 | |
exit 1 | |
;; | |
*) | |
echo "$OPTARG" >&2 | |
;; | |
esac | |
done | |
shift $((OPTIND-1)) | |
if [ $# -lt 1 ] | |
then | |
echo "Usage : $0 [url]" | |
exit | |
fi | |
DIR=$(pwd) | |
IP=$(ifconfig | grep 'inet addr:' | grep -v '127.0.0.1' | cut -d: -f2 | awk '{print $1}') | |
HOST="${HOST:=$IP}" | |
PORT="${PORT:=80}" | |
SERVER_ADMIN="${SERVER_ADMIN:[email protected]}" | |
SERVER_NAME="${SERVER_NAME:=$1}" | |
SERVER_ALIAS="${SERVER_ALIAS:=www.$1}" | |
DOCUMENT_ROOT="${DOCUMENT_ROOT:=$DIR/$SERVER_NAME/public/}" | |
LOG_DIR="${LOG_DIR:=$DIR/$SERVER_NAME/logs/}" | |
ERROR_LOG="${LOG_DIR}error.log" | |
CUSTOM_LOG="${LOG_DIR}access.log combined" | |
FILE="/etc/apache2/sites-available/$SERVER_NAME" | |
echo "<VirtualHost $HOST:$PORT>" >> $FILE | |
echo " ServerAdmin $SERVER_ADMIN" >> $FILE | |
echo " ServerName $SERVER_NAME" >> $FILE | |
echo " ServerAlias $SERVER_ALIAS" >> $FILE | |
echo " DocumentRoot $DOCUMENT_ROOT" >> $FILE | |
echo " ErrorLog $ERROR_LOG" >> $FILE | |
echo " CustomLog $CUSTOM_LOG" >> $FILE | |
echo "</VirtualHost>" >> $FILE | |
mkdir -p $DOCUMENT_ROOT | |
FILE="${DOCUMENT_ROOT}index.html" | |
echo "<html>" >> $FILE | |
echo " <head>" >> $FILE | |
echo " <title>Site created</title>" >> $FILE | |
echo " </head>" >> $FILE | |
echo " <body>" >> $FILE | |
echo " <h1>Site created</h1>" >> $FILE | |
echo " <h2>$SERVER_NAME</h2>" >> $FILE | |
echo " </body>" >> $FILE | |
echo "</html>" >> $FILE | |
chown -R www-data:dev $DOCUMENT_ROOT | |
chmod -R 774 $DOCUMENT_ROOT | |
mkdir -p $LOG_DIR | |
chown -R www-data:dev $LOG_DIR | |
chmod -R 740 $LOG_DIR | |
a2ensite $SERVER_NAME | |
service apache2 reload |
cheers dude, line 43 is a bunch of cmds to get the current ip address of the box, whilst 36 to 40 checks for a default param e.g. siteadd example.com or siteadd -a [email protected] example.com
Ahh I see now, lovely! I shall adapt and use come Monday!
…On 15 Oct 2011 18:26, "Tom Densham" < ***@***.***> wrote:
cheers dude, line 43 is a bunch of cmds to get the current ip address of
the box, whilst 36 to 40 checks for a default param e.g. siteadd
example.com or siteadd -a ***@***.*** example.com
##
Reply to this email directly or view it on GitHub:
https://gist.github.com/1287451
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
mate this looks nice and tidy :) I don't get line 43... what's it doing? Or 36 ti 40...probably being thick.