#!/bin/bash

. ~/.bashrc

if [ "$1" = "scp" ]; then
    scp debian/cronjob xyzzy.ryan52.info:
    exit 0
fi

D=$(mktemp -d)
FULL_0=$(readlink -f $0)
cd $D
git clone -q git://git.debian.org/collab-maint/irssi-scripts.git 2>/dev/null >/dev/null
cd irssi-scripts
SRC=$(dpkg-parsechangelog | awk '/^Source: /{print $2}')
if ! diff ./debian/cronjob $FULL_0 >/dev/null; then
   echo "Please update $FULL_0 on $(hostname) to match the latest version in the $SRC git respository" | mail -s "outdated $SRC cronjob script" $USER
   exit 0
fi
./update-scripts check >/dev/null
RET=$?
MAILTO=$SRC@packages.qa.debian.org
if [ "$(wc -c update-scripts.log | awk '{print $1}')" != "0" ]; then
   SRC=$(dpkg-parsechangelog | awk '/^Source: /{print $2}')
   REPLYTO=$SRC@packages.debian.org mail -a "X-PTS-Approved: yes" -s "upstream changes in $SRC" $MAILTO < update-scripts.log
fi
cd /
rm -fr $D
exit $RET
