From 8fcec90fd02cfa4c970f24f6ee29607b4a69e318 Mon Sep 17 00:00:00 2001 From: Leo Vivier Date: Sun, 23 Oct 2022 18:28:09 +0200 Subject: Overhaul script --- 2022/organizers-notebook/index.org | 68 ++++++++++++++++++++++++++------------ 1 file changed, 46 insertions(+), 22 deletions(-) diff --git a/2022/organizers-notebook/index.org b/2022/organizers-notebook/index.org index e722c41f..8de46eb1 100644 --- a/2022/organizers-notebook/index.org +++ b/2022/organizers-notebook/index.org @@ -3586,49 +3586,73 @@ Throw an error if ERROR is non-nil, skip otherwise." #+begin_src sh :eval no :tangle prerecs-wait-new.sh #!/usr/bin/env sh -set -eu +sleep_duration=600 -sleep_duration=1800 - -data=prerec-wait-new.data +data="$(basename "$0" ".sh").data" touch "$data" -plural() { +plural () { if [ "$2" = 1 ] || [ "$2" = -1 ]; then echo "${1}" else case $1 in "is" ) - "are" + echo "are" ;; - ,* ) - "${1}s" + * ) + echo "${1}s" esac fi } +current_time() { + date +"[%T]" +} + +log() { + printf "%s $1\n" "$(current_time)" +} + +color_green="\e[32m" +color_white="\e[0m" + +log2() { + log "${color_green}$1${color_white}" +} + notify() { - echo "$1" - notify-send -t 0 "EmacsConf" "$1" + log2 "$1" + notify-send -t 0 "EmacsConf" "$(log "$1")" } -echo "Currently waiting for prerec" +_sleep() { + log "Checking again in ${sleep_duration}s" + sleep "$sleep_duration" +} -prerecs_number_past=$(cat "$data") -diff=0 +log2 "Currently waiting for prerec" while true; do - prerecs_number_current="$(TERM=xterm ssh orga@media.emacsconf.org -- ls -1 /srv/upload | wc -l)" - diff=$((prerecs_number_current - prerecs_number_past)) - if [ $diff -gt 0 ]; then - break - fi - sleep "$sleep_duration" -done + prerecs_number_past=$(cat "$data") + diff=0 -notify "Yay~, $diff new $(plural "prerec" $diff) $(plural "is" $diff) available!" + while true; do + log "Checking..." + prerecs_number_current="$(TERM=xterm ssh orga@media.emacsconf.org -- ls -1 /srv/upload | wc -l)" + diff=$((prerecs_number_current - prerecs_number_past)) + if [ $diff -gt 0 ]; then + break + fi + log "No new prerec." + _sleep + done + + notify "$diff new $(plural "prerec" $diff) $(plural "is" $diff) available!" -echo "$prerecs_number_current" > "$data" + echo "$prerecs_number_current" > "$data" + + _sleep +done #+end_src -- cgit v1.2.3