#!/bin/bash dir=$(dirname "$(readlink -e "${0}")") url='https://eckner.net/computer-time-limit.php' lock_file=~/.computer-time-limit.lock if [ -d "${dir}"'/.git' ] && [ $# -eq 0 ] && [ "$(stat -c%U "${dir}"'/.git')" = "$(whoami)" ]; then timeout 60 git -C "${dir}" fetch --all -p 2>/dev/null if [ -z "$(git -C "${dir}" status --porcelain)" ]; then git -C "${dir}" pull --ff-only 2>/dev/null exec "$0" '-' fi fi exec 9> "${lock_file}" if ! flock -n 9; then exit fi . /etc/computer-time-limit.conf sende_msg() { data="$(uname -n) $1" curl \ -s \ -X POST \ --data "msg=${data}" \ --data "sig=$( echo "${data}" \ | signify -S -s "${key}" -m /dev/stdin -x /dev/stdout \ | base64 -w0 )" \ 'https://eckner.net/computer-time-limit.php' } wie_lange_noch() { if [ ! -f "${key}" ]; then noch=0 ab=$(date +%s) return fi home=$(getent passwd "${user}" | cut -d: -f6) if [ -d "${home}" ]; then cd "${home}" for i in {30..0}; do if [ ! -f '.shared_secret' ] \ || [ ! -f '/usr/src/skripte/ykverify/verify.py' ] \ || '/usr/src/skripte/ykverify/verify.py'; then break fi if [ "${i}" -eq 0 ]; then noch=0 ab=$(date +%s) cd - >/dev/null return fi sleep 1 done cd - >/dev/null fi erg=$( sende_msg start ) if [ -n "${erg}" ] && ! echo "${erg}" | grep -qvx '[0-9]\+'; then noch="${erg}" ab=$(date +%s) else noch=$((ab+noch-$(date +%s))) ab=$(date +%s) fi } check_time() { if [ "${noch}" -le 0 ]; then sende_msg stop >/dev/null loginctl terminate-user "${user}" ( sleep 1m if is_logged_in "${user}"; then poweroff fi )& fi if [ "${noch}" -lt 3630 ] && [ "${noch}" -gt 3570 ]; then espeak-ng -vde -w /tmp/stunde.wav 'noch eine Stunde' xmessage -nearmouse 'Noch 1 Stunde' & play /tmp/stunde.wav sleep 1m fi if [ "${noch}" -lt 1830 ] && [ "${noch}" -gt 1770 ]; then espeak-ng -vde -w /tmp/halbe_stunde.wav 'noch eine halbe Stunde' xmessage -nearmouse 'Noch 1/2 Stunde' & play /tmp/halbe_stunde.wav sleep 1m fi if [ "${noch}" -lt 630 ] && [ "${noch}" -gt 570 ]; then espeak-ng -vde -w /tmp/zehn.wav 'noch zehn Minuten' xmessage -nearmouse 'Noch 10 Minuten' & play /tmp/zehn.wav sleep 1m fi if [ "${noch}" -lt 330 ] && [ "${noch}" -gt 270 ]; then espeak-ng -vde -w /tmp/fuenf.wav 'noch fünf Minuten' xmessage -nearmouse 'Noch 5 Minuten' & play /tmp/fuenf.wav sleep 1m fi if [ "${noch}" -lt 90 ] && [ "${noch}" -gt 30 ]; then espeak-ng -vde -w /tmp/eins.wav 'noch eine Minute' xmessage -nearmouse 'Noch 1 Minute' & play /tmp/eins.wav sleep 1m fi } is_logged_in() { if users | grep -qwF "${user}"; then return 0 fi if loginctl list-users -l | sed -n '2,/^$/p' | awk '{print $2}' | grep -qxF "${user}"; then return 0 fi return 1 } stop_all() { for user in "${!keys[@]}"; do key="${keys["${user}"]}" sende_msg stop >/dev/null done } trap 'stop_all' EXIT noch=0 ab=$(date +%s) while true; do for user in "${!keys[@]}"; do key="${keys["${user}"]}" if is_logged_in; then wie_lange_noch check_time else sende_msg stop >/dev/null fi done [ ${noch} -lt 0 ] && noch=0 sleep $((15 + ((noch + 15) % 30))) done