summaryrefslogtreecommitdiffstats
path: root/lass/2configs
diff options
context:
space:
mode:
authorlassulus <lassulus@lassul.us>2021-01-07 15:48:13 +0100
committerlassulus <lassulus@lassul.us>2021-01-07 15:48:13 +0100
commit7def09c525e85aaac87ea1dccbc914249af147b7 (patch)
treeb84f73d84a11c9f498d75aaca2fa17eca3c38cae /lass/2configs
parent1a066ef070aae21f831ab070fbc383b693a435f1 (diff)
l go: quote everything, cleanup
Diffstat (limited to 'lass/2configs')
-rw-r--r--lass/2configs/go.nix31
1 files changed, 16 insertions, 15 deletions
diff --git a/lass/2configs/go.nix b/lass/2configs/go.nix
index b1c9ed81..7ff27a61 100644
--- a/lass/2configs/go.nix
+++ b/lass/2configs/go.nix
@@ -31,11 +31,11 @@
}
STATEDIR=$HOME
- mkdir -p $STATEDIR/items
+ mkdir -p "$STATEDIR/items"
case "$Method $Request_URI" in
"GET /"*)
- if item=$(find_item ''${Request_URI#/}); then
+ if item=$(find_item "''${Request_URI#/}"); then
uri=$(cat "$item")
printf 'HTTP/1.1 302 Found\r\n'
printf 'Content-Type: text/plain\r\n'
@@ -45,26 +45,27 @@
exit
fi
;;
- "POST /") #{ "uri": "http://nixos.org" }
+ "POST /")
uri=$(mktemp -t htgen.$$.content.XXXXXXXX)
- trap "rm $uri >&2" EXIT
+ trap 'rm $uri >&2' EXIT
- head -c $req_content_length \
+ head -c "$req_content_length" \
| grep -Eo 'https?:\/\/(www\.)?[-a-zA-Z0-9@:%._\+~#=]{1,256}\.[a-zA-Z0-9()]{1,6}\b([-a-zA-Z0-9()@:%_\+.~#?&//=]*)' \
+ | head -1 \
> $uri
- sha256=$(sha256sum -b $uri | cut -d\ -f1)
- base32=$(${pkgs.nixStable}/bin/nix-hash --to-base32 --type sha256 $sha256)
- item=$STATEDIR/items/$base32
- ref=http://$req_host/$base32
+ sha256=$(sha256sum -b "$uri" | cut -d\ -f1)
+ base32=$(${pkgs.nixStable}/bin/nix-hash --to-base32 --type sha256 "$sha256")
+ item="$STATEDIR/items/$base32"
+ ref="http://$req_host/$base32"
- if ! test -e $item; then
- mkdir -v -p $STATEDIR/items >&2
- cp -v $uri $item >&2
+ if ! test -e "$item"; then
+ mkdir -v -p "$STATEDIR/items" >&2
+ cp -v $uri "$item" >&2
fi
- base32short=$(echo $base32 | cut -b-7)
- if item=$(find_item $base32short); then
- ref=$(echo "http://$req_host/$base32short")
+ base32short=$(echo "$base32" | cut -b-7)
+ if item=$(find_item "$base32short"); then
+ ref="http://$req_host/$base32short"
fi
printf 'HTTP/1.1 200 OK\r\n'