#!/bin/sh

logfile="/var/log/dextrose-updater"
stampfile="/var/lib/dextrose-updater"

if [ -f ${stampfile} ]; then
    current_ts=$(date +%F)
    check_ts=$(ls ${stampfile} -l --time-style=+%F | awk '{print $6}')

    if [ ${current_ts} == ${check_ts} ]; then
        echo "Daily check already happened, call 'sugar-client -d update' to ignore it."
        exit 0
    fi
fi

sugar-client -d update "$@" >> ${logfile} 2>&1
RETVAL=$?

[ $RETVAL -eq 0 ] && touch ${stampfile}
exit $RETVAL
