summaryrefslogtreecommitdiffstats
path: root/2022
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--2022/organizers-notebook/index.org68
1 files 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