From 44e90fbefb9bc02827996e5b18b6ce38794096af Mon Sep 17 00:00:00 2001 From: Pieds-Nus Date: Sun, 31 Aug 2025 16:38:57 +0000 Subject: [PATCH] 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) --- mcTimer.sh | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 mcTimer.sh diff --git a/mcTimer.sh b/mcTimer.sh new file mode 100644 index 0000000..00d5234 --- /dev/null +++ b/mcTimer.sh @@ -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"