💾 Archived View for tilde.club › ~filip › tech › script › gemini_guestbook › gemini_guestbook captured on 2022-07-16 at 14:09:27.
-=-=-=-=-=-=-
#!/usr/bin/env bash GUESTBOOK_PATH="" # GUESTBOOK relative path GUESTBOOK_URL="" # GUESTBOOK URL GUESTBOOK_MESSAGES_START_LINE= # the line of the GUESTBOOK at which the messages are to be inserted MAX_MESSAGES= # maximal number of messages in GUESTBOOK decode_percent_encoding(){ echo "$1" | sed 's@+@ @g;s@%@\\x@g' | xargs -0 printf "%b" } if [[ "$QUERY_STRING" != "" ]]; then message=$(decode_percent_encoding "$QUERY_STRING") date=$(date +%Y-%m-%d) tmpfile=$(mktemp) if (( $(wc -l "$GUESTBOOK_PATH" | cut -d' ' -f1) < GUESTBOOK_MESSAGES_START_LINE + MAX_MESSAGES )); then cat <(head -n$((GUESTBOOK_MESSAGES_START_LINE - 1)) "$GUESTBOOK_PATH") <(echo "$date - $message") <(tail -n +"$GUESTBOOK_MESSAGES_START_LINE" "$GUESTBOOK_PATH") > "$tmpfile" cat "$tmpfile" > "$GUESTBOOK_PATH" printf "30 $GUESTBOOK_URL\r\n" fi else printf "10 Leave a message.\r\n" fi