From 0ca88cf2e8a21b54172a9117bf69966d5b2d961f Mon Sep 17 00:00:00 2001 From: fgozzini <49639209+fgozzini@users.noreply.github.com> Date: Tue, 14 Jun 2022 17:35:27 +0200 Subject: [PATCH 1/3] Allow user to run anacron jobs on battery The user can allow running anacron jobs on battery by adding the string `ANACRON_RUN_ON_BATTERY_POWER=yes` to the file `/etc/default/anacron`. --- contrib/0anacron | 37 +++++++++++++++++++++++++------------ 1 file changed, 25 insertions(+), 12 deletions(-) diff --git a/contrib/0anacron b/contrib/0anacron index c2b0302..98a6608 100644 --- a/contrib/0anacron +++ b/contrib/0anacron @@ -7,19 +7,32 @@ if [ `date +%Y%m%d` = "$day" ]; then exit 0 fi -# Do not run jobs when on battery power -online=1 -for psupply in /sys/class/power_supply/* ; do - if [ `cat "$psupply/type" 2>/dev/null`x = Mainsx ] && [ -f "$psupply/online" ]; then - if [ `cat "$psupply/online" 2>/dev/null`x = 1x ]; then - online=1 - break - else - online=0 +# Check whether run on battery should be allowed +check_online=1 +if test -r /etc/default/anacron; then + run_on_battery=`grep ANACRON_RUN_ON_BATTERY_POWER /etc/default/anacron | awk -F'=' '{print $2}'` + if [ $run_on_battery = "yes" ]; then + check_online=0 + fi +fi + +if [ $check_online = 1 ]; then + + # Do not run jobs when on battery power + online=1 + for psupply in /sys/class/power_supply/* ; do + if [ `cat "$psupply/type" 2>/dev/null`x = Mainsx ] && [ -f "$psupply/online" ]; then + if [ `cat "$psupply/online" 2>/dev/null`x = 1x ]; then + online=1 + break + else + online=0 + fi fi + done + if [ $online = 0 ]; then + exit 0 fi -done -if [ $online = 0 ]; then - exit 0 + fi /usr/sbin/anacron -s From 252f6da1b39e91ad260e7f1e43051ddd1295016d Mon Sep 17 00:00:00 2001 From: fgozzini <49639209+fgozzini@users.noreply.github.com> Date: Wed, 15 Jun 2022 12:11:06 +0200 Subject: [PATCH 2/3] Source directly from `/etc/default/anacron` --- contrib/0anacron | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/contrib/0anacron b/contrib/0anacron index 98a6608..7cdefad 100644 --- a/contrib/0anacron +++ b/contrib/0anacron @@ -8,15 +8,9 @@ if [ `date +%Y%m%d` = "$day" ]; then fi # Check whether run on battery should be allowed -check_online=1 -if test -r /etc/default/anacron; then - run_on_battery=`grep ANACRON_RUN_ON_BATTERY_POWER /etc/default/anacron | awk -F'=' '{print $2}'` - if [ $run_on_battery = "yes" ]; then - check_online=0 - fi -fi +. /etc/default/anacron -if [ $check_online = 1 ]; then +if [ $ANACRON_RUN_ON_BATTERY_POWER != "yes" ]; then # Do not run jobs when on battery power online=1 From 14f9f9fc4e522d5e4244ecb31aa03d46c7d8f956 Mon Sep 17 00:00:00 2001 From: fgozzini <49639209+fgozzini@users.noreply.github.com> Date: Fri, 17 Jun 2022 09:55:06 +0200 Subject: [PATCH 3/3] Added double quotes --- contrib/0anacron | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/contrib/0anacron b/contrib/0anacron index 7cdefad..090219a 100644 --- a/contrib/0anacron +++ b/contrib/0anacron @@ -10,7 +10,7 @@ fi # Check whether run on battery should be allowed . /etc/default/anacron -if [ $ANACRON_RUN_ON_BATTERY_POWER != "yes" ]; then +if [ "$ANACRON_RUN_ON_BATTERY_POWER" != "yes" ]; then # Do not run jobs when on battery power online=1