]> git.armaanb.net Git - bin.git/blobdiff - slink
slink: add program
[bin.git] / slink
diff --git a/slink b/slink
new file mode 100755 (executable)
index 0000000..40b8828
--- /dev/null
+++ b/slink
@@ -0,0 +1,31 @@
+#!/usr/bin/env sh
+
+awk -v path=$PATH_INFO '
+BEGIN {
+               if (path == "/") {
+                               print "Content-type: text/plain\n \
+You'\''ve reached Armaan'\''s link shortner. Not much to see here on the index"
+                               cut = 1
+                               exit 1
+               }
+}
+
+path == $1 {
+               printf "Content-type: text/html\n \
+<!DOCTYPE html><html lang=\"en\"><head> \
+<meta http-equiv=\"refresh\" content=\"0; URL=%s\"> \
+</head><body> \
+<p>If you are not redirected automatically, please follow this link: \
+<a href=\"%s\">%s</a>.</p> \
+</body></html>\n", $2, $2, $2
+               cut = 1
+               exit 0
+}
+
+END {
+               if (cut) exit 0
+               print "Status: 404 \
+Content-type: text/plain\n \
+Path not found."
+}
+' ${1:-/etc/slink}