#!/bin/sh

COLOR='yellow'
# strip CR and domain
MACHINE=`echo $MACHINE | sed -e 's/[,.].*$//'`

# Debug safeguard
if [ -z "$BBTMP" ]; then
    BBTMP=/tmp
fi

which yum > /dev/null 2>&1 || exit 0

sudo yum check-update > $BBTMP/yum.out 2>&1
EXIT="$?"

[ "$EXIT" = "0" ] && COLOR='green'
grep -Eiq '^(Error|Cannot)|(^|[^-])\bErrno\b| (not trusted|impossible to connect) ' $BBTMP/yum.out && COLOR="red"

( echo status $MACHINE.yum $COLOR `date`;
  cat $BBTMP/yum.out ) | if [ -n "$BB" ]; then $BB $BBDISP @; else cat; fi

rm $BBTMP/yum.out
