Skip to content

Instantly share code, notes, and snippets.

@MathieuLescure
Last active December 22, 2015 20:19
Show Gist options
  • Save MathieuLescure/6525561 to your computer and use it in GitHub Desktop.
Save MathieuLescure/6525561 to your computer and use it in GitHub Desktop.
A shell script to add and configure a new web site on a Linode with Debian 7. A Git repository with a hook to automatically deploy the site is also created. Prerequisite: The folder /srv/www_git exist The user belongs to the group "developers" (sudo groupadd developers && sudo usermod -G developers -a [username]) Usage: sudo newsite.sh www.mydom…
#!/bin/sh
WWW_ROOT_DIR=/srv/www/$1
WWW_LOGS_DIR=${WWW_ROOT_DIR}/logs
WWW_HTML_DIR=${WWW_ROOT_DIR}/public_html
mkdir $WWW_ROOT_DIR
mkdir $WWW_LOGS_DIR
mkdir $WWW_HTML_DIR
chown root:developers $WWW_HTML_DIR
chmod g+w $WWW_HTML_DIR
WWW_GIT_DIR=/srv/www_git/${1}.git
mkdir $WWW_GIT_DIR
cd $WWW_GIT_DIR
git init --bare --shared
chown -R root:developers $WWW_GIT_DIR
chmod -R g+w $WWW_GIT_DIR
GIT_POST_RECEIVE=${WWW_GIT_DIR}/hooks/post-receive
cat > $GIT_POST_RECEIVE << EOF
#!/bin/sh
GIT_WORK_TREE=$WWW_HTML_DIR git checkout -f
EOF
chmod 775 $GIT_POST_RECEIVE
cat > /etc/apache2/sites-available/$1 << EOF
<VirtualHost *:80>
ServerAdmin [email protected]
ServerName $1
DocumentRoot $WWW_HTML_DIR
ErrorLog ${WWW_LOGS_DIR}/error.log
CustomLog ${WWW_LOGS_DIR}/access.log combined
</VirtualHost>
EOF
a2ensite $1
service apache2 reload
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment