Skip to content

Instantly share code, notes, and snippets.

@swissmanu
Last active December 17, 2015 15:09
Show Gist options
  • Save swissmanu/5629414 to your computer and use it in GitHub Desktop.
Save swissmanu/5629414 to your computer and use it in GitHub Desktop.
create.sh creates a git repository which automatically publishs its contents over a webserver when receiving changes from its remotes. It's like gh-pages, but on your own server and without an extra branch.
#!/bin/bash
if [ -z "$1" ]; then
echo "Supply a name for the repo/site to publish"
exit 1;
fi
URLROOT=gitpages.mydomain.com
ROOT=/home/www/gitpages.mydomain.com
REPOS=$ROOT/repositories
HTDOCS=$ROOT/htdocs
NAME=$1
REMOTEREPO=$REPOS/$NAME
LIVEREPO=$HTDOCS/$NAME
[email protected]
echo "== Publish Git based Site on $URLROOT =="
echo "-- Create remote repository $NAME"
mkdir $REMOTEREPO
cd $REMOTEREPO
git init --bare
echo "-- Create post-update hook for $NAME"
cat <<EOF > $REMOTEREPO/hooks/post-update
#!/bin/sh
echo
echo "**** Pulling changes into $NAME Live [$URLROOT post-update hook]"
echo
cd $LIVEREPO || exit
unset GIT_DIR
git pull
exec git-update-server-info
EOF
chmod +x $REMOTEREPO/hooks/post-update
echo "-- Clone live repository for $NAME"
cd $HTDOCS
git clone $REMOTEREPO $NAME
cd $LIVEREPO
git pull
echo ""
echo "== Site $NAME published! =="
echo "Clone the remote repository, commit some files and you're good to go"
echo ""
echo "-- Site available on: $URLROOT/$NAME"
echo "-- Clone this: $GITUSERANDHOST:$REMOTEREPO"
# nginx configuration example
server {
listen 80;
server_name gitpages.mydomain.com;
root /home/www/gitpages.mydomain.com/htdocs;
index index.html;
access_log /home/www/gitpages.mydomain.com/logs/access.log;
error_log /home/www/gitpages.mydomain.com/logs/error.log;
location ~ .git {
deny all;
return 404;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment