dotfiles/.local/bin/auto-poweroff.sh

45 lines
655 B
Bash
Raw Normal View History

2022-11-10 00:55:04 +01:00
#!/bin/bash
2021-02-04 17:44:55 +01:00
# 1: Temps en minutes
# 2: Type dextinction
2023-06-17 11:56:49 +02:00
#reset-dpms() {
# xset dpms 600 600 600
# exit
#}
2022-11-10 00:55:04 +01:00
trap 'exit' INT TERM
2022-04-15 13:05:19 +02:00
touch /dev/shm/mccount
2023-06-17 11:56:49 +02:00
#xset dpms 10 10 10
#xset dpms force standby
2021-02-04 17:44:55 +01:00
while true
do
2022-08-20 20:23:03 +02:00
mcpid="$(pgrep -nu minecraft java)"
mcstatus="$(ps -q "${mcpid}" -o state --no-headers 2>/dev/null)"
2021-02-04 17:44:55 +01:00
if [[ "$mcstatus" == "T" ]]
then
echo . >> /dev/shm/mccount
else
2022-11-10 00:55:04 +01:00
echo "Joueur(s) connecté(s), réinitialisation du compteur"
2022-08-20 20:23:03 +02:00
> /dev/shm/mccount
2021-02-04 17:44:55 +01:00
fi
time=$(wc -l /dev/shm/mccount | cut -d" " -f1)
2022-11-10 00:55:04 +01:00
echo "$time"/"${1:-5}"
2021-02-04 17:44:55 +01:00
if [[ "$time" -ge "${1:-5}" ]]
then
> /dev/shm/mccount
systemctl "${2:-suspend}"
fi
2022-11-10 00:55:04 +01:00
sleepcount -c 60
2021-02-04 17:44:55 +01:00
done