47 lines
1.1 KiB
Bash
47 lines
1.1 KiB
Bash
#!/bin/bash
|
|
|
|
user=Milo # Milo | Ayana
|
|
|
|
exec="/usr/bin/minecraft-launcher"
|
|
test -x "$exec" || (
|
|
wget -O /tmp/Minecraft.deb https://launcher.mojang.com/download/Minecraft.deb &
|
|
dl="$!"
|
|
sudo aptitude update ; sudo aptitude upgrade -y
|
|
sudo aptitude install -y default-jre default-jdk
|
|
wait "$dl"
|
|
sudo apt install -y /tmp/Minecraft.deb
|
|
)
|
|
|
|
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"
|