scripts for my gemini capsule
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
#!/bin/sh
# Place this script in your /cgi-bin to get your own bookmark writing script!

# Have your host key put here for yourself.
authorized="SHA256:09CC327F3DDB21AE3BA4D0F38A6757236C8C2965A90539C640E14EB087955071 Gerbil@laptop
SHA256:DBF363CB8BB8CBCBEAC72D65ABF1D845319B404E856217166E1B6138FA8B83A8 gerbil@pp"

# Authorization guard.
if ! test "$TLS_CLIENT_HASH"; then
	printf '60 Try again with a client cert!\r\n'
	exit
elif ! test "$(printf "$authorized" | grep "^$TLS_CLIENT_HASH ")"; then
	printf '20 text/plain\r\n'
	# Or, look, I did it for you!
	cat "$0" | sed "s/^authorized=.*/authorized=\"$TLS_CLIENT_HASH $REMOTE_USER\"/g"
	exit
fi

# Input guard.
if ! test "$QUERY_STRING"; then
	printf '10 Enter URL and title\r\n'
	exit
fi

dirname="$(dirname "$(realpath "$0")")"

echo "=>$QUERY_STRING" >> "$dirname/../bookmarks.gmi"

printf '30 ../bookmarks.gmi\r\n'