Skip to content

Commit

Permalink
Allow user to run anacron jobs on battery
Browse files Browse the repository at this point in the history
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`.
  • Loading branch information
fgozzini authored and t8m committed Jan 9, 2023
1 parent 7575e75 commit cc2903f
Showing 1 changed file with 25 additions and 12 deletions.
37 changes: 25 additions & 12 deletions contrib/0anacron
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit cc2903f

Please sign in to comment.