Created
September 23, 2012 13:16
-
-
Save zbroyar/3770840 to your computer and use it in GitHub Desktop.
Automatic code deployment via github email service hook
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
#!/usr/local/bin/zsh | |
# Need flock | |
zmodload zsh/system | |
lfn=/tmp/.github | |
git=/usr/local/bin/git | |
prefix=/path/to/clones | |
secret=your_secret | |
user=mailnull | |
chown=/usr/sbin/chown | |
if [[ $1 = "mail" ]] then | |
fn=/tmp/tmp.$$ | |
cat > $fn | |
r=`cat $fn | grep '^Received: from.*github' | wc -l` | |
a=`cat $fn | grep "^Approved: $secret" | wc -l` | |
if [[ $r -gt 0 && $a -gt 0 ]] then | |
touch $lfn | |
zsystem flock $lfn | |
branch=`cat $fn | grep 'Branch: refs/' | sed -E 's"^.*/([^/]+)$"\1"'` | |
echo $branch >> $lfn | |
echo "Branch $branch set for update." | |
fi | |
rm $fn | |
elif [[ $1 = "cron" ]] then | |
if [[ ! ( -e $lfn ) ]] then | |
touch $lfn | |
$chown $user $lfn | |
fi | |
zsystem flock $lfn | |
list=(`cat $lfn | sort -u`) | |
for branch in $list | |
do | |
echo "Trying to update $branch branch ..." | |
bpath=$prefix/$branch | |
if [[ -d $bpath ]] then | |
cd $bpath && $git pull origin $branch | |
else | |
echo "Error: $bpath does not exist" | |
fi | |
done | |
echo -n '' >! $lfn | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment