====== Automatische Online-Updates per Cron ======
Mit dem Major Release Wechsel von opensuse 15.6 zu opensuse 16.0 ist das automatische online update Modul via Yast weggefallen. Damit einhergehend fehlen auch die Skripte zur Durchführung der Updates. Kontinuierliche Updates sind aber eine wesentliche Säule für sichere Systeme. Entweder werden diese nun regelmäßig manuell durchgeführt und hoffentlich keines vergessen oder es muss eine automatisierte Lösung her. Hier habe ich anhand meines bisherigen offline-Updates für Mobilgeräte und den bisherigen Skripten von opensuse 15.6 eine Lösung zusammengestellt, die mit wenig Aufwand zu bewerkstelligen ist.
Damit weiterhin Updates automatisch installiert werden, müssen zwei Dateien erzeugt und ein Link erstellt werden:
Zur Ausführung des Zypper Online-Updates wird folgendes Skript benötigt:
#!/bin/bash
if [ -f /etc/profile.d/profile.sh ]; then
. /etc/profile.d/profile.sh
fi
zyppercmd="/usr/bin/zypper"
zcmd="/bin/false"
syscfgfile="/etc/sysconfig/zypper-online-update"
if [ -x ${zyppercmd} ]
then
zcmd="${zyppercmd} --non-interactive --quiet patch"
else
echo "zypper is not installed. Can not run online update."
exit 1
fi
if [ -f ${syscfgfile} ]
then
. ${syscfgfile}
fi
if [ ! "$ZYPPER_ONLINE_UPDATE_ENABLE_CRONJOB" = "yes" ]
then
echo "Online Update is disabled in ${syscfgfile}. Will not run update."
exit 0
fi
if [ "${ZYPPER_ONLINE_UPDATE_SKIP_INTERACTIVE_PATCHES}" = "yes" ] ; then
zcmd="$zcmd --skip-interactive"
else
zcmd="$zcmd --with-interactive"
fi
if [ "${ZYPPER_ONLINE_UPDATE_AUTO_AGREE_WITH_LICENSES}" = "yes" ] ; then
zcmd="$zcmd --auto-agree-with-licenses"
fi
if [ "${ZYPPER_ONLINE_UPDATE_RECOMMENDS}" = "yes" ] ; then
zcmd="$zcmd --recommends"
else
zcmd="$zcmd --no-recommends"
fi
function runzypper {
# run passed arguments
"$@"
local status=$?
# the return code 103 indicates a succesful patch of the zypper package
# other patches might stil be waiting
if [ $status -eq 103 ]; then
echo "The Zypper package was patched, rerunning update to apply remaining patches."
# rerun passed zypper command and use new status as return value
"$@"
status=$?
fi
return $status
}
# trim whitespaces
ZYPPER_ONLINE_UPDATE_PATCH_CATEGORIES=`echo $ZYPPER_ONLINE_UPDATE_PATCH_CATEGORIES`
# run the update
if [ -z "$ZYPPER_ONLINE_UPDATE_PATCH_CATEGORIES" ] ; then
runzypper $zcmd
else
# handle errors for multiple categories
ret=0
for cat in $ZYPPER_ONLINE_UPDATE_PATCH_CATEGORIES ; do
runzypper $zcmd --category "$cat" || ret=$?
done
exit $ret
fi
Zur Konfiguration und Steuerung gibt es eine Konfigurationsdatei:
# Confiuration for installing online updates via cron
# Enable cron job
# yes or no
ZYPPER_ONLINE_UPDATE_ENABLE_CRONJOB="yes"
# Skip interactive patches during an automatic
# online update run.
# yes or no
ZYPPER_ONLINE_UPDATE_SKIP_INTERACTIVE_PATCHES="yes"
# Automatically agree with licenses.
# yes or no
ZYPPER_ONLINE_UPDATE_AUTO_AGREE_WITH_LICENSES="yes"
# Include recommended patches
# yes or no
ZYPPER_ONLINE_UPDATE_RECOMMENDS=no
# Only install patches of these categories.
# Space separated list of categories.
# Most prominent categories are: (security recommended optional pkgmanager feature document)
# Leave empty to install all categories
ZYPPER_ONLINE_UPDATE_PATCH_CATEGORIES=""
Nachdem beide Dateien angelegt wurden, fehlt nun noch ein passender Link z.B. in /etc/cron.daily:
cd /etc/cron.daily
ln -s /usr/local/bin/zypper-online-update.sh zypper-online-update