Created
May 9, 2022 19:12
-
-
Save Felix-Kyun/0545718f08f0815b81f9e84e2ec4c343 to your computer and use it in GitHub Desktop.
battery charge limiter for termux, NEEDS ROOT!
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /usr/bin/env bash | |
# TODO: add a light weight loader | |
MIN=70 | |
MAX=85 | |
CONTROL_FIlE=/sys/class/power_supply/battery/charging_enabled | |
REFRESH_INTERVAL=60 | |
BIN=termux-battery-info | |
command -v $BIN || echo -e "\n$BIN not found \n! PLEASE INSTALL TERMUX API ..." && exit 0 | |
while true ;do | |
CURRENT_LEVEL=$($BIN | grep percentage | cut -d " " -f4 | sed 's/,//') | |
if [[ $CURRENT_LEVEL > $MAX ]]; then | |
sudo echo 0 > $CONTROL_FIlE | |
done | |
if [[ $CURRENT_LEVEL < $MIN ]]; then | |
sudo echo 1 > $CONTROL_FIlE | |
done | |
sleep $REFRESH_INTERVAL | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment