5dc7db0d6c021b6d57cda42f02b35d9cad77001f
[apt-update.git] / apt-update
1 #!/bin/sh
2 #
3 # apt-update
4 #
5 # Simple wrapper script for cron to use - check for updated packages
6 # and mail admin with any recommended upgrades.
7
8 # Assumes that apt is configured correctly before we start...
9 #
10 # Steve McIntyre 26/09/2001
11
12 unset LANGUAGE
13 unset LANG
14 unset LC_ALL
15
16 TMPFILE=/etc/apt/update.tmp
17
18 . /etc/apt/update.conf
19
20 for CHROOT in $CHROOTS
21 do
22   if [ $CHROOT = / ] ; then
23       CHR=""
24   else
25       CHR="chroot $CHROOT"
26   fi
27   $CHR apt-get update > $TMPFILE 2>&1
28   error=$?
29   if [ $error -ne 0 ] ; then
30       echo $CHR update failed with error $error
31       echo
32   fi
33   # And also check for warnings:
34   grep -q ^W $TMPFILE
35   if [ $? -eq 0 ] ; then
36       echo "$CHR update gave the following warnings:"
37       grep ^W $TMPFILE
38   fi
39   rm -f $TMPFILE
40
41   THIS_LIST=`$CHR apt-get -s -u dist-upgrade | awk '/^Inst/ {print $2}'`
42   if [ "$THIS_LIST"x != ""x ] ; then
43       UPDATE_LIST="$UPDATE_LIST\n$CHROOT:\n"
44       for PKG in $THIS_LIST
45       do
46           UPDATE_LIST="$UPDATE_LIST $PKG\n"
47       done
48       CHROOT_UPDATED="$CHROOT_UPDATED $CHROOT"
49   fi
50 done
51
52 if [ "$UPDATE_LIST"x != ""x ] ; then
53     # If we've been configured to download packages, grab them now
54     # before we finish
55     if [ "$DOWNLOAD_DEBS"x = "yes"x ] ; then
56         for CHROOT in $CHROOT_UPDATED
57             do
58             if [ $CHROOT = / ] ; then
59                 CHR=""
60             else
61                 CHR="chroot $CHROOT"
62             fi
63             $CHR apt-get -d -y dist-upgrade > /dev/null
64             error=$?
65             if [ $error -ne 0 ] ; then
66                 echo $CHR package download failed with error $error
67             fi
68         done
69         UPDATE_LIST="$UPDATE_LIST\n\nPackage(s) downloaded and ready to install\n"
70     fi
71
72     printf "$UPDATE_LIST\n"
73 fi
74