#! /bin/bash

mkdir -p /tmp/check4contribsupdates.$$
TMPFILE=`mktemp /tmp/check4contribsupdates.$$/XXXXXXXXXX` || exit 1
TMP1=`mktemp /tmp/check4contribsupdates.$$/XXXXXXXXXX` || exit 1

MAILADDR=admin-yum

yum -e 0 -d 0 check-update --disablerepo=* --enablerepo=smecontribs > $TMP1
if [ $? = 100 ]; then
  echo -e "===\n=== yum reports available updates for Contribs :\n===" >> $TMPFILE
  cat $TMP1 >> $TMPFILE
 echo -e "\n    To apply all these updates, you can log on your server and run the following command :\n
    yum update --enablerepo=smecontribs\n" >> $TMPFILE
fi

if [ -s $TMPFILE ]; then
  if [ "$1" = "-m" ]; then
    mail -s "SME Server Contribs Updates available for `hostname`" $MAILADDR < $TMPFILE
  else
    echo "SME Server Contribs Updates available for `hostname`"
    cat $TMPFILE
  fi
fi

rm -f $TMPFILE $TMP1
rm -fr /tmp/check4contribsupdates.*
