summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorErich Eckner <git@eckner.net>2024-11-05 21:26:26 +0100
committerErich Eckner <git@eckner.net>2024-11-05 21:26:26 +0100
commit5512876eb77b3fc1e8871ff39f06886d4758bfab (patch)
treea81a891976aa974eab19df81e0047c88d9ede87e
parent663e7fdf0590fb6c9007d8c9b8bce7380627d75e (diff)
downloadcomputer-time-limit-5512876eb77b3fc1e8871ff39f06886d4758bfab.tar.xz
do not reference arguments by number, rather use global variables
* makes it better readable and actually removes a bug
-rwxr-xr-xcomputer-time-limit29
1 files changed, 15 insertions, 14 deletions
diff --git a/computer-time-limit b/computer-time-limit
index 7732728..84e2eb9 100755
--- a/computer-time-limit
+++ b/computer-time-limit
@@ -28,19 +28,19 @@ sende_msg() {
--data "msg=${data}" \
--data "sig=$(
echo "${data}" \
- | signify -S -s "$2" -m /dev/stdin -x /dev/stdout \
+ | signify -S -s "${key}" -m /dev/stdin -x /dev/stdout \
| base64 -w0
)" \
'https://eckner.net/computer-time-limit.php'
}
wie_lange_noch() {
- if [ ! -f "$1" ]; then
+ if [ ! -f "${key}" ]; then
noch=0
ab=$(date +%s)
return
fi
- home=$(getent passwd "$1" | cut -d: -f6)
+ home=$(getent passwd "${user}" | cut -d: -f6)
if [ -d "${home}" ]; then
cd "${home}"
if [ -f '.shared_secret' ] \
@@ -54,7 +54,7 @@ wie_lange_noch() {
cd -
fi
erg=$(
- sende_msg start "$2"
+ sende_msg start
)
if [ -n "${erg}" ] && ! echo "${erg}" | grep -qvx '[0-9]\+'; then
noch="${erg}"
@@ -67,8 +67,8 @@ wie_lange_noch() {
check_time() {
if [ "${noch}" -le 0 ]; then
- sende_msg stop "$2" >/dev/null
- loginctl terminate-user "$1"
+ sende_msg stop >/dev/null
+ loginctl terminate-user "${user}"
(
sleep 1m
if is_logged_in "${user}"; then
@@ -109,18 +109,19 @@ check_time() {
}
is_logged_in() {
- if users | grep -qwF "$1"; then
+ if users | grep -qwF "${user}"; then
return 0
fi
- if loginctl list-users -l | sed -n '2,/^$/p' | awk '{print $2}' | grep -qxF "$1"; then
+ if loginctl list-users -l | sed -n '2,/^$/p' | awk '{print $2}' | grep -qxF "${user}"; then
return 0
fi
return 1
}
stop_all() {
- for key_file in "${keys[@]}"; do
- sende_msg stop "${key_file}" >/dev/null
+ for user in "${!keys[@]}"; do
+ key="${keys["${user}"]}"
+ sende_msg stop >/dev/null
done
}
@@ -131,11 +132,11 @@ ab=$(date +%s)
while true; do
for user in "${!keys[@]}"; do
key="${keys["${user}"]}"
- if is_logged_in "${user}"; then
- wie_lange_noch "${user}" "${key}"
- check_time "${user}" "${key}"
+ if is_logged_in; then
+ wie_lange_noch
+ check_time
else
- sende_msg stop "${key}" >/dev/null
+ sende_msg stop >/dev/null
fi
done
[ ${noch} -lt 0 ] && noch=0