summaryrefslogtreecommitdiff
path: root/debian/apt.apt-compat.cron.daily
diff options
context:
space:
mode:
authorNicolas Le Cam <niko.lecam@gmail.com>2016-06-22 21:39:38 +0200
committerJulian Andres Klode <jak@debian.org>2016-08-31 13:13:41 +0200
commitd06d38bcc3335ee6bb448add9b91952e640dae05 (patch)
treef5ec410be128d363f9351e18eadb49e9055e1b9c /debian/apt.apt-compat.cron.daily
parenta55db465eca2c4d9f0cb6f36640ee6a70634052d (diff)
Use the ConditionACPower feature of systemd in the apt-daily service
.. instead of hardcoding the functionnality in the apt.systemd.daily script. Also make the compatibility cron job provide the same functionnality for systems that do not use systemd. Closes: #827930 (cherry picked from commit 51d659e7d8cdce59f910eceeee68e2c2afdb70d4)
Diffstat (limited to 'debian/apt.apt-compat.cron.daily')
-rw-r--r--debian/apt.apt-compat.cron.daily24
1 files changed, 23 insertions, 1 deletions
diff --git a/debian/apt.apt-compat.cron.daily b/debian/apt.apt-compat.cron.daily
index 1ea843008..095a44c4a 100644
--- a/debian/apt.apt-compat.cron.daily
+++ b/debian/apt.apt-compat.cron.daily
@@ -11,6 +11,23 @@ if [ -d /run/systemd/system ]; then
exit 0
fi
+check_power()
+{
+ # laptop check, on_ac_power returns:
+ # 0 (true) System is on main power
+ # 1 (false) System is not on main power
+ # 255 (false) Power status could not be determined
+ # Desktop systems always return 255 it seems
+ if which on_ac_power >/dev/null 2>&1; then
+ on_ac_power
+ POWER=$?
+ if [ $POWER -eq 1 ]; then
+ return 1
+ fi
+ fi
+ return 0
+}
+
# sleep for a random interval of time (default 30min)
# (some code taken from cron-apt, thanks)
random_sleep()
@@ -28,6 +45,11 @@ random_sleep()
sleep $TIME
}
-# run daily job
+# delay the job execution by a random amount of time
random_sleep
+
+# ensure we don't do this on battery
+check_power || exit 0
+
+# run daily job
exec /usr/lib/apt/apt.systemd.daily