#!/bin/bash

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 [ ! $AOU_ENABLE_CRONJOB = "true" ]
then
    echo "Online Update is disabled in ${syscfgfile}. Will not run update."
    exit 0
fi


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


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


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

