💾 Archived View for lyk.so › systems › gemini › scripts › tinylog-post.sh captured on 2021-12-06 at 14:29:53.

View Raw

More Information

⬅️ Previous capture (2021-11-30)

-=-=-=-=-=-=-

#!/usr/bin/env sh

set -e

# Example values. Supply your own.
log="~/documents/gemsite/tiny.gmi"
scpflags="-i ~/.ssh/xxxx.key -P 22"
scptarget="xxxx@10.0.0.1:/var/gemini/"

## IF YOU DON'T CARE ABOUT MIRRORING TO STATION, YOU CAN DELETE EVERYTHING FROM HERE...
stationpost="gemini://station.martinrue.com/xxxx/xxxx/post"
cert="~/.config/lagrange/idents/xxxx.crt"
key="~/.config/lagrange/idents/xxxx.key"

# Mirror to station.martinrue.com if the post is not a tinylog reply
if (! echo "$@" | head -n1 | grep -iq "^re: "); then
  urlencoded="$(echo -n "$@" | perl -MURI::Escape -ne 'print uri_escape($_)')"
  stationurl="$stationpost?$urlencoded"

  # Don't exceed the maximum post length on Station.
  urllen="$(printf "%s" "$stationurl" | wc -c)"

  if [ "$urllen" -gt "1024" ]; then
    >&2 echo "ERROR: The post URL exceeds 1024 bytes. The URL was $urllen bytes long. Trim down your post and try again."
    exit 1
  fi
  gemget --cert $cert --key $key $stationurl -o - > /dev/null
fi
## ...TO HERE.

ed $log <<EOF
/##
i
## $(date -u +'%F %H:%M UTC')
$@

.
w
q
EOF

SSH_AUTH_SOCK='' scp $scpflags $log $scptarget