summaryrefslogtreecommitdiff
path: root/debian/apt.systemd.daily
diff options
context:
space:
mode:
authorJulian Andres Klode <jak@debian.org>2017-05-04 22:52:01 +0200
committerJulian Andres Klode <jak@debian.org>2017-05-04 22:52:01 +0200
commit6bc40ffd444affd870e0053fa349575faa4d586f (patch)
tree13646d56868729ca730c1a4c674859de028de0f2 /debian/apt.systemd.daily
parent6ff527b4f8c88ac406effb1d88fdb3c9ab42967b (diff)
parent496313fb8e83af2ba71f6ce3d729be687c293dfd (diff)
Merge branch 'lp1686470'
Diffstat (limited to 'debian/apt.systemd.daily')
-rwxr-xr-xdebian/apt.systemd.daily163
1 files changed, 94 insertions, 69 deletions
diff --git a/debian/apt.systemd.daily b/debian/apt.systemd.daily
index 03d41bae5..22cbbded6 100755
--- a/debian/apt.systemd.daily
+++ b/debian/apt.systemd.daily
@@ -292,6 +292,16 @@ debug_echo()
# ------------------------ main ----------------------------
+# Maintain a lock on fd 3, so we can't run the script twice at the same
+# time.
+LOCKFD=3
+eval $(apt-config shell StateDir Dir::State/d)
+exec 3>${StateDir}/daily_lock
+if ! flock -w 3600 $LOCKFD; then
+ echo "E: Could not acquire lock" >&2
+ exit 1
+fi
+
if test -r /var/lib/apt/extended_states; then
# Backup the 7 last versions of APT's extended_states file
# shameless copy from dpkg cron
@@ -384,97 +394,112 @@ if [ $UpdateInterval -eq 0 ] &&
exit 0
fi
-# deal with BackupArchiveInterval
-do_cache_backup $BackupArchiveInterval
+if [ "$1" = "update" -o -z "$1" ] ; then
+ # deal with BackupArchiveInterval
+ do_cache_backup $BackupArchiveInterval
-# include default system language so that "apt-get update" will
-# fetch the right translated package descriptions
-if [ -r /etc/default/locale ]; then
- . /etc/default/locale
- export LANG LANGUAGE LC_MESSAGES LC_ALL
-fi
+ # include default system language so that "apt-get update" will
+ # fetch the right translated package descriptions
+ if [ -r /etc/default/locale ]; then
+ . /etc/default/locale
+ export LANG LANGUAGE LC_MESSAGES LC_ALL
+ fi
-# update package lists
-UPDATED=0
-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 2>&1 && pidof dbus-daemon >/dev/null 2>&1; then
- if dbus-send --system / app.apt.dbus.updated boolean:true ; then
- debug_echo "send dbus signal (success)"
+ # update package lists
+ UPDATED=0
+ 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 2>&1 && pidof dbus-daemon >/dev/null 2>&1; 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 "send dbus signal (error)"
+ debug_echo "dbus signal not send (command not available)"
fi
+ update_stamp $UPDATE_STAMP
+ UPDATED=1
else
- debug_echo "dbus signal not send (command not available)"
+ debug_echo "download updated metadata (error)"
fi
- update_stamp $UPDATE_STAMP
- UPDATED=1
else
- debug_echo "download updated metadata (error)"
+ debug_echo "download updated metadata (not run)."
fi
-else
- debug_echo "download updated metadata (not run)."
-fi
-
-# download all upgradeable packages (if it is requested)
-DOWNLOAD_UPGRADEABLE_STAMP=/var/lib/apt/periodic/download-upgradeable-stamp
-if [ $UPDATED -eq 1 ] && check_stamp $DOWNLOAD_UPGRADEABLE_STAMP $DownloadUpgradeableInterval; then
- if [ $Debdelta -eq 1 ]; then
- debdelta-upgrade >/dev/null 2>&1 || true
+
+ # download all upgradeable packages (if it is requested)
+ DOWNLOAD_UPGRADEABLE_STAMP=/var/lib/apt/periodic/download-upgradeable-stamp
+ if [ $UPDATED -eq 1 ] && check_stamp $DOWNLOAD_UPGRADEABLE_STAMP $DownloadUpgradeableInterval; then
+ if [ $Debdelta -eq 1 ]; then
+ debdelta-upgrade >/dev/null 2>&1 $LOCKFD>&- || true
+ fi
+ if eval apt-get $XAPTOPT -y -d dist-upgrade $XSTDERR $LOCKFD>&-; then
+ update_stamp $DOWNLOAD_UPGRADEABLE_STAMP
+ debug_echo "download upgradable (success)"
+ else
+ debug_echo "download upgradable (error)"
+ fi
+ else
+ debug_echo "download upgradable (not run)"
fi
- if eval apt-get $XAPTOPT -y -d dist-upgrade $XSTDERR; then
- update_stamp $DOWNLOAD_UPGRADEABLE_STAMP
- debug_echo "download upgradable (success)"
+
+ if which unattended-upgrade >/dev/null 2>&1 && check_stamp $DOWNLOAD_UPGRADEABLE_STAMP $UnattendedUpgradeInterval; then
+ if unattended-upgrade -d $XUUPOPT $LOCKFD>&-; then
+ update_stamp $DOWNLOAD_UPGRADEABLE_STAMP
+ debug_echo "unattended-upgrade -d (success)"
+ else
+ debug_echo "unattended-upgrade -d (error)"
+ fi
else
- debug_echo "download upgradable (error)"
+ debug_echo "unattended-upgrade -d (not run)"
fi
-else
- debug_echo "download upgradable (not run)"
fi
-# auto upgrade all upgradeable packages
-UPGRADE_STAMP=/var/lib/apt/periodic/upgrade-stamp
-if which unattended-upgrade >/dev/null 2>&1 && check_stamp $UPGRADE_STAMP $UnattendedUpgradeInterval; then
- if unattended-upgrade $XUUPOPT; then
- update_stamp $UPGRADE_STAMP
- debug_echo "unattended-upgrade (success)"
+if [ "$1" = "install" -o -z "$1" ] ; then
+ # auto upgrade all upgradeable packages
+ UPGRADE_STAMP=/var/lib/apt/periodic/upgrade-stamp
+ if which unattended-upgrade >/dev/null 2>&1 && check_stamp $UPGRADE_STAMP $UnattendedUpgradeInterval; then
+ if unattended-upgrade $XUUPOPT $LOCKFD>&-; then
+ update_stamp $UPGRADE_STAMP
+ debug_echo "unattended-upgrade (success)"
+ else
+ debug_echo "unattended-upgrade (error)"
+ fi
else
- debug_echo "unattended-upgrade (error)"
+ debug_echo "unattended-upgrade (not run)"
fi
-else
- debug_echo "unattended-upgrade (not run)"
-fi
-# clean package archive
-CLEAN_STAMP=/var/lib/apt/periodic/clean-stamp
-if check_stamp $CLEAN_STAMP $CleanInterval; then
- if eval apt-get $XAPTOPT -y clean $XSTDERR; then
- debug_echo "clean (success)."
- update_stamp $CLEAN_STAMP
+ # clean package archive
+ CLEAN_STAMP=/var/lib/apt/periodic/clean-stamp
+ if check_stamp $CLEAN_STAMP $CleanInterval; then
+ if eval apt-get $XAPTOPT -y clean $XSTDERR; then
+ debug_echo "clean (success)."
+ update_stamp $CLEAN_STAMP
+ else
+ debug_echo "clean (error)"
+ fi
else
- debug_echo "clean (error)"
+ debug_echo "clean (not run)"
fi
-else
- debug_echo "clean (not run)"
-fi
-# autoclean package archive
-AUTOCLEAN_STAMP=/var/lib/apt/periodic/autoclean-stamp
-if check_stamp $AUTOCLEAN_STAMP $AutocleanInterval; then
- if eval apt-get $XAPTOPT -y autoclean $XSTDERR; then
- debug_echo "autoclean (success)."
- update_stamp $AUTOCLEAN_STAMP
+ # autoclean package archive
+ AUTOCLEAN_STAMP=/var/lib/apt/periodic/autoclean-stamp
+ if check_stamp $AUTOCLEAN_STAMP $AutocleanInterval; then
+ if eval 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 (error)"
+ debug_echo "autoclean (not run)"
fi
-else
- debug_echo "autoclean (not run)"
-fi
-# check cache size
-check_size_constraints
+ # check cache size
+ check_size_constraints
+fi
#
# vim: set sts=4 ai :