From 8769e3909ae33b7e847d77401b75c15fda53b7da Mon Sep 17 00:00:00 2001 From: Leon van Kammen Date: Tue, 11 Nov 2025 21:07:14 +0100 Subject: [PATCH] =?UTF-8?q?=F0=9F=94=A7=20master:=20work=20in=20progress?= =?UTF-8?q?=20[might=20break]?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 10 +++++++++ janusxr | 62 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 72 insertions(+) create mode 100644 README.md create mode 100755 janusxr diff --git a/README.md b/README.md new file mode 100644 index 0000000..4d3850d --- /dev/null +++ b/README.md @@ -0,0 +1,10 @@ +# JanusXR cli + +Swiss-army knife to automate janusXR / JML things. + +# Awk? + +Why not some superfancy scripting for this task? + +* awk is great for all things text and templating usecases +* lightweight diff --git a/janusxr b/janusxr new file mode 100755 index 0000000..d751f8a --- /dev/null +++ b/janusxr @@ -0,0 +1,62 @@ +#!/usr/bin/env -S awk -f + +function usage() { + print "Usage: ./janusxr --health \n" + exit 1 +} + +# ------------------------------ +# Core dispatcher +# ------------------------------ +BEGIN { + if (ARGC < 2) usage() + command = ARGV[1] + if (command == "--health") { + health() + } else { + printf("Unknown command: %s\n", command) + usage() + } +} + +function health( tmpfile, line, attr, check, u) { + url = ARGV[2] + if (url == "") { + print "❌ Missing URL argument." + usage() + } + rooturl = url + sub(/\/[^\/]+$/, "", rooturl) + tmpfile = "/tmp/out.html" + + # Fetch HTML page using curl + cmd = "curl -s \"" url "\" -o " tmpfile + if (system(cmd) != 0) { print "❌ Failed to fetch " url; exit 1; } + + # Parse attributes from src= or url= + while ((getline line < tmpfile) > 0) { + while (match(line, /(src|url)="[^"]+"/)) { + attr = substr(line, RSTART, RLENGTH) + sub(/^[^=]+="/, "", attr) + sub(/"$/, "", attr) + links[attr] = 1 + line = substr(line, RSTART + RLENGTH) + } + } + close(tmpfile) + + # Check each extracted links + nlinks = 0 + nlinksok = 0 + for (u in links) { + if( substr(u,1,1) == "/" ) u = rooturl""u + check = "curl -I -s \"" u "\" > /dev/null" + if (system(check) == 0){ + nlinksok++ + printf("✅ %s\n", u) + }else printf("❌ %s\n", u) + nlinks+=1 + } + print "⚕️ health: "(( 100/nlinks )*nlinksok)"%" +} +