New script : control game session time
A script to limit gameplay to 1h per day (per default), and kill the game when the limit is reach (1-minute warning)
This commit is contained in:
parent
1565b90bd9
commit
44e90fbefb
42
mcTimer.sh
Normal file
42
mcTimer.sh
Normal file
@ -0,0 +1,42 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
#install rss-glx
|
||||||
|
#echo 2025-08-31T3000 >> $HOME/mcMilo
|
||||||
|
wget -o /tmp/Minecraft.deb https://launcher.mojang.com/download/Minecraft.deb &
|
||||||
|
update ; install default-jre default-jdk
|
||||||
|
sudo apt install /tmp/Minecraft.deb
|
||||||
|
|
||||||
|
user=Milo # Milo | Ayana
|
||||||
|
exec="/usr/libexec/xscreensaver/hyperspace"
|
||||||
|
notify="notify-send"
|
||||||
|
limit="3600" # seconds / day
|
||||||
|
logfile="$HOME/mc$user"
|
||||||
|
|
||||||
|
today="$(date -I)"
|
||||||
|
start="$(date +%s)"
|
||||||
|
last="$(tail -n 1 $logfile)"
|
||||||
|
remaining="$(bc <<< "$limit - 0$(grep -q "$today" <<< "$last" && cut -d "T" -f 2 <<< "$last")")"
|
||||||
|
|
||||||
|
test "$remaining" -le "0" && "$notify" "Temps dépassé pour aujourd'hui" && exit 1
|
||||||
|
|
||||||
|
function conclude() {
|
||||||
|
end="$(date +%s)"
|
||||||
|
|
||||||
|
grep -q "$today" <<< "$last" && end="$(bc <<< "$(cut -d "T" -f 2 <<< "$last") + "$end"")"
|
||||||
|
|
||||||
|
time="$(bc <<< "$end - $start")"
|
||||||
|
|
||||||
|
echo "$start $end $time"
|
||||||
|
|
||||||
|
echo "${today}T${time}" >> "$logfile"
|
||||||
|
}
|
||||||
|
|
||||||
|
"$exec" &
|
||||||
|
pid="$!"
|
||||||
|
|
||||||
|
( sleep "$remaining" ; "$notify" "Limite de temps atteinte. Extinction dans 1 minute" ; sleep 60 ; kill "$pid" ; conclude ) &
|
||||||
|
killer="$!"
|
||||||
|
|
||||||
|
wait "$pid"
|
||||||
|
conclude
|
||||||
|
kill "$killer"
|
Loading…
Reference in New Issue
Block a user