Autosvc
This commit is contained in:
parent
96751acaab
commit
eeb061a032
4 changed files with 167 additions and 1 deletions
39
termux/scripts/autosvc
Executable file
39
termux/scripts/autosvc
Executable file
|
@ -0,0 +1,39 @@
|
|||
#!/data/data/com.termux/files/usr/bin/bash
|
||||
#
|
||||
# Start services based on phone state
|
||||
#
|
||||
|
||||
function act() {
|
||||
# Services that should be always on
|
||||
|
||||
service sshd start
|
||||
service autosvc start
|
||||
|
||||
# Services that should be on depending on battery
|
||||
|
||||
bat="$(termux-battery-status | jq -r '.status')"
|
||||
|
||||
if [[ "$bat" == "FULL" || "$bat" == "CHARGING" ]]
|
||||
then
|
||||
service syncthing start
|
||||
else
|
||||
service syncthing stop
|
||||
fi
|
||||
}
|
||||
|
||||
if [ "$1" == "-d" ]
|
||||
then
|
||||
# Daemon mode
|
||||
while true
|
||||
do
|
||||
echo 29
|
||||
act &>> $HOME/.local/log/autosvc.log
|
||||
echo 31
|
||||
sleep 60
|
||||
done
|
||||
else
|
||||
# One shot mode
|
||||
# TODO Soft-code the log destination & the program arguments
|
||||
act
|
||||
fi
|
||||
|
|
@ -3,4 +3,9 @@
|
|||
# Substitution for sudo
|
||||
#
|
||||
|
||||
echo "$@" | tsu
|
||||
if [ "$(whoami)" != 'root' ]
|
||||
then
|
||||
echo "$@" | tsu
|
||||
else
|
||||
"$@"
|
||||
fi
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue