#!/bin/bash

# source the profile to get proper proxy settings, bnc#(678888)
. /etc/profile.d/profile.sh

zyppercmd="/usr/bin/zypper"
upcmd="/bin/false"
syscfgfile="/etc/sysconfig/automatic_online_update"
skipInteractive="--skip-interactive"
autoAgreeWithLicenses=""

if [ -x ${zyppercmd}  ]
then
    upcmd=${zyppercmd}
else
    echo "zypper is not installed. Can not run online update."
    exit 1
fi


if [ -f ${syscfgfile} ]
then
    . ${syscfgfile}
fi


if [ ! "x$AOU_ENABLE_CRONJOB" = "xtrue" ]
then
    echo "Online Update is disabled in ${syscfgfile}. Will not run update."
    exit 0
fi



if [ "x${AOU_SKIP_INTERACTIVE_PATCHES}" = "xtrue"  ]
then
    skipInteractive="--skip-interactive"
else
    skipInteractive=
fi


if [ "x${AOU_AUTO_AGREE_WITH_LICENSES}" = "xtrue"  ]
then
    autoAgreeWithLicenses="--auto-agree-with-licenses"
else
    autoAgreeWithLicenses=
fi


# run the update
${upcmd} --quiet up -y -t patch  ${skipInteractive}  ${autoAgreeWithLicenses}

