unattended-upgrade in /etc/network/if-up.d
Leander Jedamus
ljedamus at googlemail.com
Mon Sep 24 13:12:19 UTC 2012
Hi!
I wrote a simple script for unattended-upgrade, which is run when an
interface (except loopback) is coming up.
It is modified from ntpdate in the same directory (/etc/network/if-up.d/).
Here it is:
----8<----8<----8<----8<----8<----8<----8<----
#!/bin/sh
# written by Leander Jedamus 24.09.2012
PATH=/sbin:/bin:/usr/sbin:/usr/bin
export PATH
# gives me German messages
LANG=de_DE.utf8
export LANG
SCRIPTNAME=unattended-upgrade
PROGRAMPATH=/usr/bin
PROGRAMNAME1=apt-get
PROGRAMNAME2=unattended-upgrade
PROGRAM1=$PROGRAMPATH/$PROGRAMNAME1
PROGRAM2=$PROGRAMPATH/$PROGRAMNAME2
if [ "$METHOD" = loopback ]; then
exit 0
fi
# Check whether unattended-upgrade was removed but not purged; it's
useless to
# wait for it in that case.
if [ ! -x $PROGRAM1 ] && [ -d $PROGRAMPATH ]; then
exit 0
fi
if [ ! -x $PROGRAM2 ] && [ -d $PROGRAMPATH ]; then
exit 0
fi
(
# This is for the case that /usr will be mounted later.
if [ -r /lib/udev/hotplug.functions ]; then
. /lib/udev/hotplug.functions
wait_for_file $PROGRAM1
wait_for_file $PROGRAM2
fi
LOCKFILE=/var/lock/$SCRIPTNAME-ifup
# Avoid running more than one at a time
if [ -x /usr/bin/lockfile-create ]; then
lockfile-create $LOCKFILE
lockfile-touch $LOCKFILE &
LOCKTOUCHPID="$!"
fi
# invoke-rc.d --quiet ntp stop >/dev/null 2>&1 || true
# run update again, when return code is not 0
RETCODE=1
while [ $RETCODE != 0 ]; do
$PROGRAM1 update 2>/dev/null >/dev/null && RETCODE=0
done
$PROGRAM2
# invoke-rc.d --quiet ntp start >/dev/null 2>&1 || true
if [ -x /usr/bin/lockfile-create ] ; then
kill $LOCKTOUCHPID
lockfile-remove $LOCKFILE
fi
) &
----8<----8<----8<----8<----8<----8<----8<----
This script will run apt-get install as root until it succeeds running
and then will run unattended-upgrade.
Logfile is in /var/log/unattended-upgrades/unattended-upgrades.log
I also wrote to the author of unattended-upgrade, but he has not
answered me for a week or so.
Perhaps somebody else can use it.
Greetings
Leander Jedamus
More information about the ubuntu-users
mailing list