#!/bin/sh
#
# commitwatch
# watches for new commits
# usually executed from "cron"
#
# note / wish : replace this script and functionality in "post commit"
#               document the configuration
#               current, june 2016, purpose of this script
#               is making visible what happens on server 'november'
#
# 2011-2016 (C) Geert Stappers <stappers@stappers.nl>
# GNU General Public License
#
#
NOTIFY=stappers@stappers.nl
NOTIFY=breda@losc.nl
NOTIFY=loscbreda@toonvissers.nl

whichversion ()
{
  git log | head -n 1 | awk '{print $2}'
}

if [ `hostname` = november ] ; then
  cd ~/loscweb
  # want daar staat een checkout van deze git repository
  # voor deze (web)server
fi

if [ -f scripts/since.stamp ] ; then
  SINCE=$( cat scripts/since.stamp )
else
  whichversion > scripts/since.stamp
  # ready for the next run
  exit 0
fi

git pull > /dev/null 2>&1 || true
CURRENT=$( whichversion )

if [ ${CURRENT} = ${SINCE} ] ; then
  # nothing to do
  exit 0
else
  touch scripts/updatewebsite.flag
  rm -f 00*.patch
  git format-patch ${SINCE} > /dev/null
  git send-email \
      --from="Commit Watch <wsbreda@november.losc.nl>" \
      --to=${NOTIFY} \
      --suppress-cc=all \
      --chain-reply-to \
    00*.patch > /dev/null
  if [ `hostname` = november ] ; then
    # ook de git http server bijwerken
    cd /srv/apache/losc.nl/Breda/loscweb
    git pull > /dev/null 2>&1
    git update-server-info
    cd ~/loscweb  # weer terug
  fi
  whichversion > scripts/since.stamp
fi

# l l
