#!/bin/sh # # apt-update # # Simple wrapper script for cron to use - check for updated packages # and mail admin with any recommended upgrades. # # Assumes that apt is configured correctly before we start... # # Copyright 2001-2019 Steve McIntyre # GPL-2+ unset LANGUAGE unset LANG unset LC_ALL TMPFILE=/etc/apt/update.tmp . /etc/apt/update.conf for CHROOT in $CHROOTS do case $CHROOT in /) CHR="";; /*) CHR="chroot $CHROOT";; *) CHR="schroot -c $CHROOT --";; esac # Work out a simple version number for comparisons, using the major # and minor versions. Ignore the third component, as we might see # things like "1.8.0~rc3" APT_VER=$($CHR apt-get --version | awk \ '/^apt/ { FULL=$2 split(FULL, VERS, ".") printf("%d\n", VERS[1]*100 + VERS[2]*1); }') APT_OPTIONS="" if [ $APT_VER -gt 105 ]; then APT_OPTIONS="--allow-releaseinfo-change" fi $CHR apt-get update $APT_OPTIONS > $TMPFILE 2>&1 error=$? if [ $error -ne 0 ] ; then echo $CHR update failed with error $error echo fi # And also check for warnings: grep -q ^W $TMPFILE if [ $? -eq 0 ] ; then echo "$CHR update gave the following warnings:" grep ^W $TMPFILE fi rm -f $TMPFILE THIS_LIST=`$CHR apt-get -s -u dist-upgrade | awk '/^Inst/ {print $2}'` if [ "$THIS_LIST"x != ""x ] ; then UPDATE_LIST="$UPDATE_LIST\n$CHROOT:\n" for PKG in $THIS_LIST do UPDATE_LIST="$UPDATE_LIST $PKG\n" done CHROOT_UPDATED="$CHROOT_UPDATED $CHROOT" fi done if [ "$UPDATE_LIST"x != ""x ] ; then # If we've been configured to download packages, grab them now # before we finish if [ "$DOWNLOAD_DEBS"x = "yes"x ] ; then for CHROOT in $CHROOT_UPDATED do case $CHROOT in /) CHR="";; /*) CHR="chroot $CHROOT";; *) CHR="schroot -c $CHROOT --";; esac $CHR apt-get -d -y dist-upgrade > /dev/null error=$? if [ $error -ne 0 ] ; then echo $CHR package download failed with error $error fi done UPDATE_LIST="$UPDATE_LIST\n\nPackage(s) downloaded and ready to install\n" fi printf "$UPDATE_LIST\n" fi