Skip to content

Instantly share code, notes, and snippets.

@evaisse
Last active August 29, 2015 14:25
Show Gist options
  • Save evaisse/fb295c126faae20bfc9a to your computer and use it in GitHub Desktop.
Save evaisse/fb295c126faae20bfc9a to your computer and use it in GitHub Desktop.
poll2build.sh
#!/bin/sh
# lockfile for script
LOCKFILE=/var/lock/poll2build.pid
# check lock file
[ -f $LOCKFILE ] && echo "script already running @ `cat /var/lock/poll2build.pid`" && exit 0;
# trap for cleanup lock file
trap "{ rm -f $LOCKFILE; exit 255; }" EXIT INT
# put pid in lock file
echo "$$" > /var/lock/poll2build.pid
# info
echo "poll2build `date`"
# go to build directory
cd $1
if [ ! -f prev_head ]; # initialize if this is the 1st poll
then
git rev-parse master > prev_head
fi
# fetch & merge, then inspect head
git fetch > build_log.txt 2>&1
if [ $? -eq 0 ]
then
echo "Fetch from git done";
git merge FETCH_HEAD >> build_log.txt 2>&1 ;
git rev-parse master > latest_head
if ! diff latest_head prev_head > /dev/null ;
then
echo "Merge via git done";
cat latest_head > prev_head # update stored HEAD
bash ./bin/install
# there has been a change, build
fi
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment