1
0
mirror of https://github.com/kmein/niveum synced 2026-03-16 10:11:08 +01:00

feat(tarot): use scriptFile option

This commit is contained in:
2022-12-13 09:36:59 +01:00
parent 7aee4b566c
commit 99bc72eb29
2 changed files with 28 additions and 30 deletions

8
flake.lock generated
View File

@@ -211,11 +211,11 @@
"stockholm": { "stockholm": {
"flake": false, "flake": false,
"locked": { "locked": {
"lastModified": 1669968392, "lastModified": 1670868652,
"narHash": "sha256-yXdKNYrOFpueTu6lFpm624rVri4rK6ad4qJqoUkc9vY=", "narHash": "sha256-Y5kEs6GsKMvkLe+q+rAQDTIpLwmbt51lB07JLGbi4f8=",
"ref": "refs/heads/master", "ref": "refs/heads/master",
"rev": "645c3564f75589531abcf17fd3c3f920d93a394a", "rev": "3884243448869bdf09f6434b385e532c7c26ae88",
"revCount": 10987, "revCount": 11077,
"type": "git", "type": "git",
"url": "https://cgit.lassul.us/stockholm" "url": "https://cgit.lassul.us/stockholm"
}, },

View File

@@ -20,32 +20,30 @@ in {
krebs.htgen.tarot = { krebs.htgen.tarot = {
port = tarotPort; port = tarotPort;
user.name = "radio"; user.name = "radio";
script = ''. ${ scriptFile = pkgs.writers.writeDash "tarot" ''
pkgs.writers.writeDash "tarot" '' case "$Method $Request_URI" in
case "$Method $Request_URI" in "GET /")
"GET /") if item=$(${pkgs.findutils}/bin/find ${toString tarotFiles} -type f | ${pkgs.coreutils}/bin/shuf -n1); then
if item=$(${pkgs.findutils}/bin/find ${toString tarotFiles} -type f | ${pkgs.coreutils}/bin/shuf -n1); then card=$(mktemp --tmpdir tarot.XXX)
card=$(mktemp --tmpdir tarot.XXX) trap 'rm $card' EXIT
trap 'rm $card' EXIT reverse=$(${pkgs.coreutils}/bin/shuf -i0-1 -n1)
reverse=$(${pkgs.coreutils}/bin/shuf -i0-1 -n1) if [ "$reverse" -eq 1 ]; then
if [ "$reverse" -eq 1 ]; then ${pkgs.imagemagick}/bin/convert -rotate 180 "$item" "$card"
${pkgs.imagemagick}/bin/convert -rotate 180 "$item" "$card" else
else ${pkgs.coreutils}/bin/cp "$item" "$card"
${pkgs.coreutils}/bin/cp "$item" "$card" fi
fi printf 'HTTP/1.1 200 OK\r\n'
printf 'HTTP/1.1 200 OK\r\n' printf 'Content-Type: %s\r\n' "$(${pkgs.file}/bin/file -ib "$card")"
printf 'Content-Type: %s\r\n' "$(${pkgs.file}/bin/file -ib "$card")" printf 'Server: %s\r\n' "$Server"
printf 'Server: %s\r\n' "$Server" printf 'Connection: close\r\n'
printf 'Connection: close\r\n' printf 'Content-Length: %d\r\n' $(${pkgs.coreutils}/bin/wc -c < "$card")
printf 'Content-Length: %d\r\n' $(${pkgs.coreutils}/bin/wc -c < "$card") printf '\r\n'
printf '\r\n' cat "$card"
cat "$card" exit
exit fi
fi ;;
;; esac
esac '';
''
}'';
}; };
niveum.passport.services = [ niveum.passport.services = [