Dabei ist folgendes Skript entstanden, das im Hook-Verzeichnis des Repositories als "post-receive" gespeichert wird:
#!/bin/bash
PROJ="$GL_REPO.git"
# $DIR MUST BE absolute!
DIR="/var/www/virtual/$GL_USER/html/example"
# Which branch do we have the last commit?
cd $HOME/repositories/$PROJ
BRANCH=`git show-branch -a HEAD | grep -A 1 "^--" | grep -v "^--" | cut -d "[" -f 2 | cut -d "]" -f 1`
cd $HOME
echo "Processing $0..."
case "$BRANCH" in
master)
if [ ! -d $DIR ] ; then
# Create publish directory
mkdir -p $DIR
cd $DIR
cd ..
rmdir $DIR
git clone -b $BRANCH $HOME/repositories/$PROJ $DIR
fi
cd $DIR
# Update publish dir
if [ -d .git ] ; then
git --work-tree="$DIR" --git-dir="$DIR/.git" pull origin $MYBRANCH
find $DIR -type d | xargs chmod 755
find $DIR -type f | xargs chmod 644
find $DIR/.git | xargs chmod 700
else
# Oops!
echo "No git directory in $DIR!"
fi
;;
*)
echo "Branch $BRANCH not configured. Doing nothing"
;;
esac
Das Skript kann man sicherlich prima erweitern, z.B. um bestimmte Repos per rsync auf andere Server zu packen, oder, oder, oder...
Kommentare