More bugfixes. Should clear some free time, now.
This commit is contained in:
parent
bcc66b501d
commit
8ce0479ff2
46
mcTimer.sh
46
mcTimer.sh
@ -1,46 +0,0 @@
|
||||
#!/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"
|
40
timeout.sh
Normal file
40
timeout.sh
Normal file
@ -0,0 +1,40 @@
|
||||
#!/bin/bash
|
||||
|
||||
exec="/usr/local/bin/factorio"
|
||||
|
||||
notify="notify-send"
|
||||
limit="3600" #seconds / day
|
||||
logfile="$HOME/.timeout-$(basename "$exec")"
|
||||
|
||||
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")")"
|
||||
|
||||
if test "$remaining" -le "0" ; then
|
||||
"$notify" "Time limit exceeded for today" &
|
||||
exit 1
|
||||
fi
|
||||
|
||||
function conclude() {
|
||||
end="$(date +%s)"
|
||||
|
||||
grep -q "$today" <<< "$last" && end="$(bc <<< "$(cut -d "T" -f 2 <<< "$last") + "$end"")"
|
||||
|
||||
time="$(bc <<< "$end - $start")"
|
||||
|
||||
echo "${today}T${time}" >> "$logfile"
|
||||
}
|
||||
|
||||
"$exec" &
|
||||
|
||||
while test "$(wc -l <<< "$pid")" -le 1 ; do
|
||||
pid="$(pgrep factorio)"
|
||||
done
|
||||
|
||||
( sleep "$remaining" ; "$notify" "Time limit reached." "1 minute to extinction." & sleep 60 ; kill $(tr "\n" " " <<< "$pid") ; conclude ) &
|
||||
killer="$!"
|
||||
|
||||
wait "$(head -n2 | tail -n1 <<< "$pid")"
|
||||
conclude
|
||||
kill "$killer"
|
Loading…
Reference in New Issue
Block a user