#!/bin/sh
#
#
# smt-daily
# This script runs organizational commands for the SMT service.
# It syncs the local SMT with the Novell NCC, creates a daily report
# and updates the mirrored installation and update sources.

PATH="/sbin:/usr/sbin:/usr/bin:/bin"

SMTCMD=/usr/sbin/smt
. /etc/smt.d/smt-cron.conf

while read line ; do
    case "$line" in
    \#*|"") continue ;;
    esac
    eval val=${line#*=}
    case "$line" in
    PROXY_ENABLED=*)
        PROXY_ENABLED="${val}"
        ;;
    HTTP_PROXY=*)
        test -n "$val" || continue
        http_proxy="${val}"
        export http_proxy
        ;;
    HTTPS_PROXY=*)
        test -n "$val" || continue
        https_proxy="${val}"
        export https_proxy
        ;;
        esac
done < /etc/sysconfig/proxy
unset sys line val

if test "$PROXY_ENABLED" != "yes" ; then
    unset http_proxy https_proxy
fi
unset PROXY_ENABLED

SCC_SYNC_RC=0
if [ -x ${SMTCMD}-sync ]
then
    ${SMTCMD}-sync ${SCC_SYNC_PARAMS}
    SCC_SYNC_RC=$?
else
    echo "WARNING: Could not find the SMT binary ${SMTCMD}-sync"
    echo "         Please make sure SMT is properly installed."
fi

if [ $SCC_SYNC_RC -ne 0 ]
then
    echo "WARNING: smt-sync exited with error."
fi

if [ -x ${SMTCMD}-report ]
then
    ${SMTCMD}-report --dailycheck ${REPORT_PARAMS}
else
    echo "WARNING: Could not find the SMT binary ${SMTCMD}-report"
    echo "         Please make sure SMT is properly installed."
fi

if [ -x ${SMTCMD}-mirror ]
then
    if [ $SCC_SYNC_RC -eq 0 ]
    then
        ${SMTCMD}-mirror ${MIRROR_PARAMS}
    else
        echo "Skipping smt-mirror because previous run of smt-sync failed."
    fi
else
    echo "WARNING: Could not find the SMT binary ${SMTCMD}-mirror"
    echo "         Please make sure SMT is properly installed."
fi


# in cronjobs always do an exit 0 - even on errors - exit 1 only in case of real panic
exit 0
