Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow user to run anacron jobs on battery #115

Merged
merged 3 commits into from
Jan 9, 2023
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
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`.
  • Loading branch information
fgozzini committed Jun 14, 2022
commit 0ca88cf2e8a21b54172a9117bf69966d5b2d961f
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}'`
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about just sourcing in the file? i.e., . /etc/default/anacron

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point, as I said I am no expert in bash scripting. I pushed your suggestion into the branch.

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