]> git.plutz.net Git - shellwiki/commitdiff
implement redirect pragma
authorPaul Hänsch <paul@plutz.net>
Thu, 10 Aug 2023 16:47:05 +0000 (18:47 +0200)
committerPaul Hänsch <paul@plutz.net>
Thu, 10 Aug 2023 16:47:05 +0000 (18:47 +0200)
handlers/20_redirect.sh [new file with mode: 0755]

diff --git a/handlers/20_redirect.sh b/handlers/20_redirect.sh
new file mode 100755 (executable)
index 0000000..9f3497e
--- /dev/null
@@ -0,0 +1,30 @@
+#!/bin/sh
+
+case $PATH_INFO in
+  *"/["*"]")
+    return 1;
+    ;;
+esac
+
+if acl_read ${PATH_INFO}; then
+  mdfile="$(mdfile "${PATH_INFO%/*}")"
+else
+  return 1
+fi
+
+if [ "$mdfile" ]; then
+  REDIRECT="$(
+    sed -nE '
+      s;^%redirect[ \t]+([[:graph:]][[:print:]]+)\r?$;\1;p; tQ;
+      b; :Q q;
+    ' "$mdfile"
+  )"
+else
+  return 1
+fi
+
+if [ "$REDIRECT" ]; then
+  REDIRECT "$REDIRECT"
+fi
+
+return 1