# License: MIT
# Version: -0.7
-set -euo pipefail
-
### constants ###
PRGN="${0##*/}" # program name
DLDR="${BOLLUX_DOWNDIR:-.}" # where to download
### utility functions ###
# a better echo
-put() { printf '%s\n' "$*"; }
+put() { printf '%s\n' "$*" >&3; }
# conditionally log events to stderr
# lower = more important
log 5 "serv: $serv"
log 5 "addr: $addr"
- t="$(mktemp)"
-
sslcmd=(openssl s_client -crlf -ign_eof -quiet -connect "$serv")
log "${sslcmd[@]}"
- "${sslcmd[@]}" <<<"$addr" 2>"$t"
-
- ((LOGL > 4)) && cat "$t"
- rm "$t"
+ "${sslcmd[@]}" <<<"$addr" 2>/dev/null
}
# handle the response
# cf. gemini://gemini.circumlunar.space/docs/spec-spec.txt
-handle() { # handle < RESPONSE ## needs $URL in state
- head="$(sed 1q)"
+handle() { # handle URL < RESPONSE
+ URL="$1"
+ while read -r head; do
+ break # wait to read the first line
+ done
code="$(awk '{print $1}' <<<"$head")"
meta="$(awk '{for(i=2;i<=NF;i++)printf "%s ",$i;printf "\n"}' <<<"$head")"
### main entry point ###
bollux() {
+ bollux_setup
+
if (($# == 1)); then
URL="$1"
else
- read -rp "GO> " URL
+ read -r -u 3 -p "GO> " URL
fi
log 5 "URL : $URL"
- log 5 "addr: $(_address "$URL")"
- log 5 "serv: $(_server "$URL")"
- request "$URL" | handle
+ request "$URL" >.resource &
+ handle "$URL" <.resource
+
+ bollux_cleanup
+}
+
+bollux_setup() {
+ mkfifo .resource
+ trap bollux_cleanup INT QUIT TERM EXIT
+}
+bollux_cleanup() {
+ echo
+ rm -f .resource
}
if [[ "${BASH_SOURCE[0]}" == "$0" ]]; then
+ set -euo pipefail # strict mode
# requirements here -- so they're only checked once
require awk
require dd