diff options
author | makefu <github@syntax-fehler.de> | 2015-08-28 23:39:37 +0200 |
---|---|---|
committer | makefu <github@syntax-fehler.de> | 2015-08-28 23:39:37 +0200 |
commit | 7eba4293714b9dce86c07ccf2fdaddaa11a4c3c7 (patch) | |
tree | 28fdc7158cd28e4b25cf5674ab54da8da8b69c1e /reaktor/commands | |
parent | 15026716ab3057998cf2f487742c2dd8e185335c (diff) |
Reaktor: add nix support, packaging
Diffstat (limited to 'reaktor/commands')
-rwxr-xr-x | reaktor/commands/badcommand | 1 | ||||
-rwxr-xr-x | reaktor/commands/caps | 13 | ||||
-rwxr-xr-x | reaktor/commands/hello | 2 | ||||
-rwxr-xr-x | reaktor/commands/identify | 22 | ||||
-rwxr-xr-x | reaktor/commands/licht_resolver | 37 | ||||
-rwxr-xr-x | reaktor/commands/nag | 68 | ||||
-rwxr-xr-x | reaktor/commands/reload | 2 | ||||
-rwxr-xr-x | reaktor/commands/respond | 2 | ||||
-rwxr-xr-x | reaktor/commands/rev | 2 | ||||
-rwxr-xr-x | reaktor/commands/say | 2 | ||||
-rwxr-xr-x | reaktor/commands/taken | 28 | ||||
-rwxr-xr-x | reaktor/commands/tell-on_join | 19 | ||||
-rwxr-xr-x | reaktor/commands/tell-on_privmsg | 17 | ||||
-rwxr-xr-x | reaktor/commands/uptime | 8 | ||||
-rwxr-xr-x | reaktor/commands/whatweb | 17 | ||||
-rwxr-xr-x | reaktor/commands/whois | 4 |
16 files changed, 244 insertions, 0 deletions
diff --git a/reaktor/commands/badcommand b/reaktor/commands/badcommand new file mode 100755 index 0000000..c59b4d1 --- /dev/null +++ b/reaktor/commands/badcommand @@ -0,0 +1 @@ +#? //retard diff --git a/reaktor/commands/caps b/reaktor/commands/caps new file mode 100755 index 0000000..ac8cc66 --- /dev/null +++ b/reaktor/commands/caps @@ -0,0 +1,13 @@ +#! /usr/bin/env python3 +import imp +import os + +def load_config(filename): + dirname = os.path.dirname(filename) + modname, ext = os.path.splitext(os.path.basename(filename)) + file, pathname, description = imp.find_module(modname, [ dirname ]) + return imp.load_module(modname, file, pathname, description) + +config = load_config(os.environ['config_filename']) +print('Private: '+' '.join(filter(None,[ x.get('capname',None) for x in config.commands]))) +print('Public: '+' '.join(filter(None,[ x.get('capname',None) for x in config.public_commands]))) diff --git a/reaktor/commands/hello b/reaktor/commands/hello new file mode 100755 index 0000000..05ed79b --- /dev/null +++ b/reaktor/commands/hello @@ -0,0 +1,2 @@ +#! /bin/sh +echo "Hello${*+, $*}!" diff --git a/reaktor/commands/identify b/reaktor/commands/identify new file mode 100755 index 0000000..c2fb2c5 --- /dev/null +++ b/reaktor/commands/identify @@ -0,0 +1,22 @@ +#!/usr/bin/env python +import imp +import os,sys + +def load_config(filename): + dirname = os.path.dirname(filename) + modname, ext = os.path.splitext(os.path.basename(filename)) + file, pathname, description = imp.find_module(modname, [ dirname ]) + return imp.load_module(modname, file, pathname, description) + +config = load_config(os.environ['config_filename']) + +with open(config.admin_file) as f: + for line in f: + nick,secret = line.split() + if sys.argv[1] == secret: + print("identified you as %s!"%nick) + with open(config.auth_file,'a+') as g: + g.write(os.environ['_prefix'] +"\n") + sys.exit(0) + +print("unable to identify you, sorry") diff --git a/reaktor/commands/licht_resolver b/reaktor/commands/licht_resolver new file mode 100755 index 0000000..5bdb651 --- /dev/null +++ b/reaktor/commands/licht_resolver @@ -0,0 +1,37 @@ +#! /usr/bin/python +# -*- coding: utf-8 -*- + +map = { + 'shackspace': { + 'device': { + 0: 'Licht0, Zickenzone; Fenster', + 1: 'Licht1, Sofaecke; Fenster', + 2: 'Licht2, Zickenzone; Ghetto', + 3: 'Licht3, Sofaecke; Ghetto', + 4: 'Licht4, Richtung Getränkelager', + 5: 'Licht5, Porschekonsole', + 6: 'Licht6, Tomatenecke', + 7: 'Licht7, Ghetto', + 10: 'Hauptschalter' + }, + 'state': { + 0: 'aus', + 1: 'an', + 2: 'aus in T-10s' + }, + '->': 'ist' + } +} + +from struct import unpack +import json +from os import environ as env + +location = "shackspace" + +map = map[location] +print (env["payload"]+"") +did, sid= unpack('BB', json.loads(env['payload'])) +device,state = map['device'][did], map['state'][sid] +arrow = map['->'] +print ' '.join([device, arrow, state]) diff --git a/reaktor/commands/nag b/reaktor/commands/nag new file mode 100755 index 0000000..f214139 --- /dev/null +++ b/reaktor/commands/nag @@ -0,0 +1,68 @@ +#! /bin/sh +set -euf +if test -e nag.hosts.ls; then + echo "nag seems to run already... if not, then delete $workdir/nag.*, please" + exit 23 +fi + +trap 'rm -f nag.hosts.ls nag.services.ls nag.patch' EXIT INT QUIT + + +# usage: git_pull_output_filter REPO_NAME +git_pull_output_filter() { + sed -n 's/^ [0-9]\+ file change/'"$1"': &/p' +} + + +if ! test -d nag.hosts; then + git clone "$hosts_repo" nag.hosts +else + (cd nag.hosts && git pull) | git_pull_output_filter hosts +fi + +if ! test -d nag.services; then + git clone "$services_repo" nag.services +else + (cd nag.services && git pull) | git_pull_output_filter services +fi + + +(cd nag.hosts && ls | sort) > nag.hosts.ls +(cd nag.services && ls | sort) > nag.services.ls + +diff -u nag.hosts.ls nag.services.ls > nag.patch || : + +missing_services=$(sed -n '1d;2d;s/^-\(.*\)/\1/p' nag.patch | tr '\n' ' ') +obsolete_services=$(sed -n '1d;2d;s/^+\(.*\)/\1/p' nag.patch | tr '\n' ' ') + +if test "${inspect_services-false}" = true; then + missing_owners=$(set +f; cd nag.services && grep '^owner:$' * | cut -d: -f1) + missing_mailtos=$(set +f; cd nag.services && grep '^mailto:$' * | cut -d: -f1) +fi + +nag_missing_services='missing services' +nag_obsolete_services='obsolete services' +nag_missing_owners='services with missing owner entry' +nag_missing_mailtos='services with missing mailto entry' + +# +# output +# +did_nag=false +for i in \ + missing_services \ + obsolete_services \ + missing_owners \ + missing_mailtos +do + eval "offenders=\${$i-}; nag_msg=\$nag_$i" + if test -n "$offenders"; then + echo $nag_msg: $offenders + did_nag=true + fi +done + +# if asked directly, answer if there is nothing to nag about +if test $did_nag = false -a -n "${_from:-}";then + echo "nothing to nag about" +fi diff --git a/reaktor/commands/reload b/reaktor/commands/reload new file mode 100755 index 0000000..bfa1f04 --- /dev/null +++ b/reaktor/commands/reload @@ -0,0 +1,2 @@ +#! /bin/sh +exec pkill -U reaktor diff --git a/reaktor/commands/respond b/reaktor/commands/respond new file mode 100755 index 0000000..e23dc3e --- /dev/null +++ b/reaktor/commands/respond @@ -0,0 +1,2 @@ +#!/bin/sh +printf '%s\n' "${_from}: $*" diff --git a/reaktor/commands/rev b/reaktor/commands/rev new file mode 100755 index 0000000..a8681ab --- /dev/null +++ b/reaktor/commands/rev @@ -0,0 +1,2 @@ +#! /bin/sh +git log -1 --format="%h by %an, %ar" diff --git a/reaktor/commands/say b/reaktor/commands/say new file mode 100755 index 0000000..8b83c05 --- /dev/null +++ b/reaktor/commands/say @@ -0,0 +1,2 @@ +#!/bin/sh +printf '%s\n' "$*" diff --git a/reaktor/commands/taken b/reaktor/commands/taken new file mode 100755 index 0000000..b8beba6 --- /dev/null +++ b/reaktor/commands/taken @@ -0,0 +1,28 @@ +#!/bin/sh +#!/bin/bash + +# domainavailable +# Fast, domain name checker to use from the shell +# Use globs for real fun: +# domainavailable blah{1..3}.{com,net,org,co.uk} +# Inspired by foca / giles: +# http://gilesbowkett.blogspot.com/2009/02/simple-bash-domain-availability.html + +for d in $@; +do +if host "$d" | grep "NXDOMAIN" >&/dev/null; then + w=$(whois "$d") + if ! test "$?" -eq 0 ;then + echo "$d - whois not available" + elif echo "$w" | grep -Ei "(No match|NOT FOUND|Status: free)" >&/dev/null; then + echo "$d available"; + elif echo "$w"| grep -Ei "(Status: invalid)" >&/dev/null ;then + echo "$d invalid" + else + echo "$d taken"; + fi +else + echo "$d taken"; +fi +done +exit 0 diff --git a/reaktor/commands/tell-on_join b/reaktor/commands/tell-on_join new file mode 100755 index 0000000..2dbff41 --- /dev/null +++ b/reaktor/commands/tell-on_join @@ -0,0 +1,19 @@ +#! /bin/sh +set -euf + +# require flock from util-linux +if test "${FLOCK-}" != "$state_file"; then + exec env FLOCK="$state_file" flock "$state_file" "$0" "$@" +fi + +to="$_from" + +# print messages +sed -n '/^'"$to"' /{ + s/^\([^ ]\+\) \([^ ]\+\) <\([^>]\+\)> \(.*\)/\1: \4 2-- \2, \3/p +}' "$state_file" + +# delete messages +sed -i '/^'"$to"' /{ + d +}' "$state_file" diff --git a/reaktor/commands/tell-on_privmsg b/reaktor/commands/tell-on_privmsg new file mode 100755 index 0000000..5d0aff4 --- /dev/null +++ b/reaktor/commands/tell-on_privmsg @@ -0,0 +1,17 @@ +#! /bin/sh +set -euf + +# require flock from util-linux +if test "${FLOCK-}" != "$state_file"; then + exec env FLOCK="$state_file" flock "$state_file" "$0" "$@" +fi + +from="$_prefix" +to="$1"; shift +msg="$*" +date=$(date) + +# TODO tell now, if already joined +printf '%s %s <%s> %s\n' "$to" "$from" "$date" "$msg" >> "$state_file" + +echo 'Consider it noted.' # that's what lambdabot says... diff --git a/reaktor/commands/uptime b/reaktor/commands/uptime new file mode 100755 index 0000000..7ff6416 --- /dev/null +++ b/reaktor/commands/uptime @@ -0,0 +1,8 @@ +#! /bin/sh +# +# //Reactor/commands/uptime - IRC-optimized uptime output +# +uptime | sed ' + s/^\(.*\) up \(.*\) days\?, *\(.*\), *\(.*\) users\?, *load average: \(.*\)$/\1; \2d \3; \4u; \5/;t + s/^\(.*\) up *\(.*\), *\(.*\) users\?, *load average: \(.*\)$/\1; 0d \2; \3u; \4/;t +' diff --git a/reaktor/commands/whatweb b/reaktor/commands/whatweb new file mode 100755 index 0000000..36711ef --- /dev/null +++ b/reaktor/commands/whatweb @@ -0,0 +1,17 @@ +#!/bin/sh +#wrapper for WhatWeb +set -eu + +# whatweb is in path? +whatweb=whatweb +if ! type -p whatweb >/dev/null 2>&1 ;then + here=$(dirname `readlink -f $0`) + whatweb="$here/../repos/whatweb/whatweb" + if ! test -e "$whatweb" then + echo "!! cannot find usable whatweb installation in path or basedir ($whatweb)" + exit 1 + fi +fi + +[ -z "${1:-}" ] && echo "!! no host given" && exit 1 +exec $whatweb_bin --user-agent="Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:25.0) Gecko/20100101 Firefox/25.0" -a 3 "$1" 2>&1 diff --git a/reaktor/commands/whois b/reaktor/commands/whois new file mode 100755 index 0000000..b073389 --- /dev/null +++ b/reaktor/commands/whois @@ -0,0 +1,4 @@ +#!/bin/sh +(! type whois >/dev/null 2>/dev/null) && echo "whois does not exist" && exit 0 + +whois "${1?usage: $0 domain}" | sed -e '/^$/d' -e '/^%/d' -e '/^Nserver/d' -e 's/^\[.*/---/' -e '/^Changed/d' -e '/^Status/d' -e '/^Type/d' -e '/^PostalCode/d' -e '/^Phone/d' -e '/^Fax/d' -e '/Last update of WHOIS database/Q' -e '/ID:/d' |