dot

packages and services management
Log | Files | Refs | README

commit da8344fdff3a9e16eeec1912f426649205be5d84
parent fc52d08271e797274fa0c482afc164ea8ce0cd92
Author: Josuah Demangeon <mail@josuah.net>
Date:   Fri,  9 Feb 2018 21:29:02 +0100

[add] add utilities from srv back into etc/bin

Diffstat:
Abin/collectd-ploot | 35+++++++++++++++++++++++++++++++++++
Abin/git-gph | 28++++++++++++++++++++++++++++
Abin/gopher-proxy | 107+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Mdaemon/quark | 2+-
4 files changed, 171 insertions(+), 1 deletion(-)

diff --git a/bin/collectd-ploot b/bin/collectd-ploot @@ -0,0 +1,35 @@ +#!/bin/sh -e + +mkdir -p stat + +for host in "${VAR}/collectd"/* +do + h="${host#${VAR}/collectd/}" + printf '[0|%s|/stat/%s|server|port]\n' "${h}" "${h}" + { + printf '\n' + + sed '1 d; s/,/ /' \ + "${host}/cpu/percent-idle-$(date +%Y-%m-%d)" | + ploot -o 10 -t 'cpu idle %' + + sed '1 d; s/,/ /' \ + "${host}/cpu/percent-user-$(date +%Y-%m-%d)" | + ploot -o 10 -t 'cpu user %' + + sed '1 d; s/,/ /' \ + "${host}/cpu/percent-system-$(date +%Y-%m-%d)" | + ploot -o 10 -t 'cpu system %' + + sed '1 d; s/,/ /' \ + "${host}/cpu/percent-interrupt-$(date +%Y-%m-%d)" | + ploot -o 10 -t 'cpu interrupt %' + + sed '1 d; s/,/ /g' \ + "${host}/load/load-relative-$(date +%Y-%m-%d)" | + cut -d' ' -f1-2 | ploot -o 10 -t 'load average' + + printf '\n' + + } > "stat/${h}" +done diff --git a/bin/git-gph b/bin/git-gph @@ -0,0 +1,28 @@ +#!/bin/sh +# add index.gph and commit/%H.txt inside of a git bare repository +# usage: cd "$REPO_DIR" && git-index absolute/path/to/bare/repo.git + +p=$(printf '%s/commit/' "$1" | sed 's/[\&/]/\\&/g') +cat << EOF > index.gph + +----= $(basename "$PWD") =---- + + git clone git://josuah.net:9000/$(basename "$PWD") + +$(git ls-tree -r --name-only master | sort | sed 's/^/ /') + +$(git log --graph --all --date=short --decorate --tags --branches --remotes \ + --format='%H %ad %an <%ae>%n %s%n' | sed -r ' +/[0-9a-f]{40}/ { +s/\|/\\&/g +s/(.*)([0-9a-f]{8})([0-9a-f]{32})(.*)/[0|\1\2\4|'"$p"'\2\3.txt|server|port]/ +}') +EOF + +mkdir -p commit +for commit in $(git log --format=%H) +do + [ -f "commit/$commit.txt" ] && continue + printf '%s\n' "$commit" 1>&2 + git show --stat -U3 "$commit" --color=never > "commit/$commit.txt" +done diff --git a/bin/gopher-proxy b/bin/gopher-proxy @@ -0,0 +1,107 @@ +#!/bin/sh +# proxy from gopher to http and html for use with inetd +# +# /etc/inetd.conf: +# gopher-proxy stream tcp nowait root /path/gopher-proxy gopher-proxy host + +#--- parse url ----------------------------------------------------------------- + +# host[:port][/flag/path] +IFS=' ' read host port flag path << EOF +$(awk '{ + sub("^GET /(gopher://)?", ""); sub(" HTTP/[0-9].*$", ""); + gsub(" ", "%20"); + gsub("\t", "%0b"); + gsub("\\\\", "%5c"); + + host = $0 + if (sub("^[^:]*:", ":")) { + sub(":.*", "", host); + } else if (sub("[^/]*/", "/")) { + sub("/.*", "", host); + } else { + $0 = ""; + } + + port = $0 + if (sub("^:[0-9]+:", "") || sub("^:[0-9]+/", "/")) { + sub(":", "", port); + sub("[:/].*", "", port); + } else if (sub("^:[0-9]+$", "")) { + sub(":", "", port); + } else { + port = "70"; + } + + flag = $0; + if (sub("^/.", "")) { + sub("^/", "", flag); + sub("/.*", "", flag); + } else { + flag = "."; + } + + path = $0; + + printf("%s\t%s\t%s\t%s", host, port, flag, path); + exit; +}') +EOF + +#--- content ------------------------------------------------------------------- + +printf '/%s\n' "$path" | nc -w 2 -- "$host" "$port" | +awk -v HOST="$1" -v FLAG="$flag" ' + +function esc(str) +{ + gsub("&", "\\&amp;", str); + gsub("<", "\\&lt;", str); + gsub(">", "\\&gt;", str); + gsub("\"", "\\&quot;", str); + return str; +} + +function url(f) +{ + if (sub("^URL:", "", f[2])) + return f[2]; + return sprintf("http://%s/%s:%s/%s%s", HOST, f[3], f[4], f[0], f[2]); +} + +function link(type, f) +{ + return sprintf("<a href=\"%s\">%s</a> %s", url(f), type, esc(f[1])); +} + +BEGIN { + print("HTTP/1.1 200 OK\r"); + print("Content-Encoding: UTF-8\r"); + print("Content-Type: text/html; charset=UTF-8\r"); + print("\r"); + print("<!doctype html><title>gopher proxy</title><pre>"); +} + +FLAG == "0" { + print(esc($0)); + next; +} + +FLAG == "1" || FLAG == "." { + sub("\r$", ""); + split($0, f, "\t"); + f[0] = substr(f[1], 1, 1); + sub(".", "", f[1]); +} + +f[0] == "i" { printf(" %s\n", esc(f[1])); next; } +f[0] == "0" { print(link("txt", f)); next; } +f[0] == "1" { print(link("dir", f)); next; } +f[0] == "8" { print(link("net", f)); next; } +f[0] == "h" { print(link("url", f)); next; } +f[0] == "g" { print(link("img", f)); next; } +f[0] == "I" { print(link("img", f)); next; } + +END { + print("</pre>"); +}' diff --git a/daemon/quark b/daemon/quark @@ -3,7 +3,7 @@ path="${1:-${HOME}/srv}" exec quark \ - -h 0.0.0.0 \ + -h localhost \ -d "${path}" \ -V \ 1>> "${LOG}/quark" \