+
+# package archive contnts removal down to $MaxSize
+if [ $MaxSize -ne 0 ]; then
+
+ MinAgeSec=$(($MinAge*24*60*60))
+
+ # reverse-sort by mtime
+ for file in $(ls -rt $Cache/*.deb 2>/dev/null); do
+ du=$(du -m -s $Cache)
+ size=${du%%/*}
+ # check if the cache is small enough
+ if [ $size -lt $MaxSize ]; then
+ debug_echo "end remove by archive size: size=$size < $MaxSize"
+ break
+ fi
+
+ # check for MinAge in second of the file
+ if [ $MinAgeSec -ne 0 ]; then
+ # check both ctime and mtime
+ mtime=$(stat -c %Y $file)
+ ctime=$(stat -c %Z $file)
+ if [ $mtime -gt $ctime ]; then
+ delta=$(($now-$mtime))
+ else
+ delta=$(($now-$ctime))
+ fi
+ if [ $delta -le $MinAgeSec ]; then
+ debug_echo "skip remove by archive size: $file, delta=$delta < $MinAgeSec"
+ else
+ # delete oldest file
+ debug_echo "remove by archive size: $file, delta=$delta >= $MinAgeSec (sec), size=$size >= $MaxSize"
+ rm -f $file
+ fi
+ fi
+
+ done
+fi
+
+# update package lists
+UPDATE_STAMP=/var/lib/apt/periodic/update-stamp
+if check_stamp $UPDATE_STAMP $UpdateInterval; then
+ if eval apt-get $XAPTOPT -y update $XSTDERR; then
+ debug_echo "download updated metadata (success)."
+ if which dbus-send >/dev/null; then
+ if dbus-send --system / app.apt.dbus.updated boolean:true ; then
+ debug_echo "send dbus signal (success)"
+ else
+ debug_echo "send dbus signal (error)"
+ fi
+ else
+ debug_echo "dbus signal not send (command not available)"
+ fi
+ update_stamp $UPDATE_STAMP
+ # download all upgradeable packages if it is requested
+ DOWNLOAD_UPGRADEABLE_STAMP=/var/lib/apt/periodic/download-upgradeable-stamp
+ if check_stamp $DOWNLOAD_UPGRADEABLE_STAMP $DownloadUpgradeableInterval; then
+ if eval apt-get $XAPTOPT -y -d dist-upgrade $XSTDERR; then
+ update_stamp $DOWNLOAD_UPGRADEABLE_STAMP
+ debug_echo "download upgradable (success)."
+ # auto upgrade all upgradeable packages
+ UPGRADE_STAMP=/var/lib/apt/periodic/upgrade-stamp
+ if which unattended-upgrade >/dev/null && check_stamp $UPGRADE_STAMP $UnattendedUpgradeInterval; then
+ if unattended-upgrade $XUUPOPT; then
+ update_stamp $UPGRADE_STAMP
+ debug_echo "unattended-upgrade (success)."
+ else
+ debug_echo "unattended-upgrade (error)."
+ fi
+ else
+ debug_echo "unattended-upgrade (not run)."
+ fi
+ else
+ debug_echo "download upgradable (error)."
+ fi
+ else
+ debug_echo "download upgradable (not run)."
+ fi
+ else
+ debug_echo "download updated metadata (error)."
+ fi
+else
+ debug_echo "download updated metadata (not run)."
+fi
+
+# autoclean package archive
+AUTOCLEAN_STAMP=/var/lib/apt/periodic/autoclean-stamp
+if check_stamp $AUTOCLEAN_STAMP $AutocleanInterval; then
+ if apt-get $XAPTOPT -y autoclean $XSTDERR; then
+ debug_echo "autoclean (success)."
+ update_stamp $AUTOCLEAN_STAMP
+ else
+ debug_echo "autoclean (error)."
+ fi
+else
+ debug_echo "autoclean (not run)."
+fi
+
+#
+# vim: set sts=4 ai :
+#
+