From 7eba4293714b9dce86c07ccf2fdaddaa11a4c3c7 Mon Sep 17 00:00:00 2001 From: makefu Date: Fri, 28 Aug 2015 23:39:37 +0200 Subject: Reaktor: add nix support, packaging --- README.md | 25 +++------------ Reaktor.nix | 15 +++++++++ commands/badcommand | 1 - commands/caps | 13 -------- commands/hello | 2 -- commands/identify | 22 ------------- commands/licht_resolver | 37 ---------------------- commands/nag | 68 ---------------------------------------- commands/reload | 2 -- commands/respond | 2 -- commands/rev | 2 -- commands/revip | 1 - commands/say | 2 -- commands/subdomains | 1 - commands/taken | 28 ----------------- commands/tell-on_join | 19 ----------- commands/tell-on_privmsg | 17 ---------- commands/uptime | 8 ----- commands/visit-page | 1 - commands/whatweb | 17 ---------- commands/whois | 4 --- default.nix | 15 +++++++++ reaktor/commands/badcommand | 1 + reaktor/commands/caps | 13 ++++++++ reaktor/commands/hello | 2 ++ reaktor/commands/identify | 22 +++++++++++++ reaktor/commands/licht_resolver | 37 ++++++++++++++++++++++ reaktor/commands/nag | 68 ++++++++++++++++++++++++++++++++++++++++ reaktor/commands/reload | 2 ++ reaktor/commands/respond | 2 ++ reaktor/commands/rev | 2 ++ reaktor/commands/say | 2 ++ reaktor/commands/taken | 28 +++++++++++++++++ reaktor/commands/tell-on_join | 19 +++++++++++ reaktor/commands/tell-on_privmsg | 17 ++++++++++ reaktor/commands/uptime | 8 +++++ reaktor/commands/whatweb | 17 ++++++++++ reaktor/commands/whois | 4 +++ 38 files changed, 278 insertions(+), 268 deletions(-) create mode 100644 Reaktor.nix delete mode 100755 commands/badcommand delete mode 100755 commands/caps delete mode 100755 commands/hello delete mode 100755 commands/identify delete mode 100755 commands/licht_resolver delete mode 100755 commands/nag delete mode 100755 commands/reload delete mode 100755 commands/respond delete mode 100755 commands/rev delete mode 120000 commands/revip delete mode 100755 commands/say delete mode 120000 commands/subdomains delete mode 100755 commands/taken delete mode 100755 commands/tell-on_join delete mode 100755 commands/tell-on_privmsg delete mode 100755 commands/uptime delete mode 120000 commands/visit-page delete mode 100755 commands/whatweb delete mode 100755 commands/whois create mode 100644 default.nix create mode 100755 reaktor/commands/badcommand create mode 100755 reaktor/commands/caps create mode 100755 reaktor/commands/hello create mode 100755 reaktor/commands/identify create mode 100755 reaktor/commands/licht_resolver create mode 100755 reaktor/commands/nag create mode 100755 reaktor/commands/reload create mode 100755 reaktor/commands/respond create mode 100755 reaktor/commands/rev create mode 100755 reaktor/commands/say create mode 100755 reaktor/commands/taken create mode 100755 reaktor/commands/tell-on_join create mode 100755 reaktor/commands/tell-on_privmsg create mode 100755 reaktor/commands/uptime create mode 100755 reaktor/commands/whatweb create mode 100755 reaktor/commands/whois diff --git a/README.md b/README.md index a581c6b..af14d96 100644 --- a/README.md +++ b/README.md @@ -2,25 +2,8 @@ ## Quickstart - ## 1. create a dedicated user - useradd reaktor + pip install -e . + useradd reaktor -m /opt/Reaktor + sudo -u reaktor reaktor run - ## 2. marry Reaktor with /sbin/init - - ## 2a. /etc/inittab-like foo - echo 10:2345:respawn:/bin/su reaktor -c /krebs/Reaktor/index >>/etc/inittab - # or 10:2345:respawn:/usr/bin/sudo -u reaktor /krebs/Reaktor/index - # if reaktor's shell is /bin/false or similar - # [check with e.g getent passwd reaktor] - telinit q - - ## 2b. upstart-like foo - - cat > /etc/init/Reaktor.conf < {}; +# nix-build Reaktor.nix +# result/bin/reaktor + +buildPythonPackage rec { + name = "Reaktor-${version}"; + version = "0.2.6"; + propagatedBuildInputs = with pkgs.pythonPackages;[ + pythonPackages.docopt + ]; + src = fetchurl { + url = "https://pypi.python.org/packages/source/R/Reaktor/Reaktor-0.2.6.tar.gz"; + sha256 = "1dksw1s1n2hxvnga6pygjr174dywncr0wiggkrkn1srbn2amh1c2"; + }; +} diff --git a/commands/badcommand b/commands/badcommand deleted file mode 100755 index c59b4d1..0000000 --- a/commands/badcommand +++ /dev/null @@ -1 +0,0 @@ -#? //retard diff --git a/commands/caps b/commands/caps deleted file mode 100755 index ac8cc66..0000000 --- a/commands/caps +++ /dev/null @@ -1,13 +0,0 @@ -#! /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/commands/hello b/commands/hello deleted file mode 100755 index 05ed79b..0000000 --- a/commands/hello +++ /dev/null @@ -1,2 +0,0 @@ -#! /bin/sh -echo "Hello${*+, $*}!" diff --git a/commands/identify b/commands/identify deleted file mode 100755 index c2fb2c5..0000000 --- a/commands/identify +++ /dev/null @@ -1,22 +0,0 @@ -#!/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/commands/licht_resolver b/commands/licht_resolver deleted file mode 100755 index 5bdb651..0000000 --- a/commands/licht_resolver +++ /dev/null @@ -1,37 +0,0 @@ -#! /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/commands/nag b/commands/nag deleted file mode 100755 index f214139..0000000 --- a/commands/nag +++ /dev/null @@ -1,68 +0,0 @@ -#! /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/commands/reload b/commands/reload deleted file mode 100755 index bfa1f04..0000000 --- a/commands/reload +++ /dev/null @@ -1,2 +0,0 @@ -#! /bin/sh -exec pkill -U reaktor diff --git a/commands/respond b/commands/respond deleted file mode 100755 index e23dc3e..0000000 --- a/commands/respond +++ /dev/null @@ -1,2 +0,0 @@ -#!/bin/sh -printf '%s\n' "${_from}: $*" diff --git a/commands/rev b/commands/rev deleted file mode 100755 index a8681ab..0000000 --- a/commands/rev +++ /dev/null @@ -1,2 +0,0 @@ -#! /bin/sh -git log -1 --format="%h by %an, %ar" diff --git a/commands/revip b/commands/revip deleted file mode 120000 index e2c3b7a..0000000 --- a/commands/revip +++ /dev/null @@ -1 +0,0 @@ -../repos/revip/revip \ No newline at end of file diff --git a/commands/say b/commands/say deleted file mode 100755 index 8b83c05..0000000 --- a/commands/say +++ /dev/null @@ -1,2 +0,0 @@ -#!/bin/sh -printf '%s\n' "$*" diff --git a/commands/subdomains b/commands/subdomains deleted file mode 120000 index 0489555..0000000 --- a/commands/subdomains +++ /dev/null @@ -1 +0,0 @@ -../repos/consolidate_dns/index \ No newline at end of file diff --git a/commands/taken b/commands/taken deleted file mode 100755 index b8beba6..0000000 --- a/commands/taken +++ /dev/null @@ -1,28 +0,0 @@ -#!/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/commands/tell-on_join b/commands/tell-on_join deleted file mode 100755 index 2dbff41..0000000 --- a/commands/tell-on_join +++ /dev/null @@ -1,19 +0,0 @@ -#! /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/commands/tell-on_privmsg b/commands/tell-on_privmsg deleted file mode 100755 index 5d0aff4..0000000 --- a/commands/tell-on_privmsg +++ /dev/null @@ -1,17 +0,0 @@ -#! /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/commands/uptime b/commands/uptime deleted file mode 100755 index 7ff6416..0000000 --- a/commands/uptime +++ /dev/null @@ -1,8 +0,0 @@ -#! /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/commands/visit-page b/commands/visit-page deleted file mode 120000 index 8723336..0000000 --- a/commands/visit-page +++ /dev/null @@ -1 +0,0 @@ -../repos/view-website/runner.sh \ No newline at end of file diff --git a/commands/whatweb b/commands/whatweb deleted file mode 100755 index 36711ef..0000000 --- a/commands/whatweb +++ /dev/null @@ -1,17 +0,0 @@ -#!/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/commands/whois b/commands/whois deleted file mode 100755 index b073389..0000000 --- a/commands/whois +++ /dev/null @@ -1,4 +0,0 @@ -#!/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' diff --git a/default.nix b/default.nix new file mode 100644 index 0000000..96e3b12 --- /dev/null +++ b/default.nix @@ -0,0 +1,15 @@ +with import {}; +# nix-shell --pure . +stdenv.mkDerivation rec { + name = "Reaktor-${version}"; + version = "0.2.6"; + buildInputs = with pkgs;[ + python34 + python34Packages.docopt + ]; + + shellHook ='' + [ ! -d venv ] && virtualenv --python=python3.4 venv + . venv/bin/activate + '' ; +} 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' -- cgit v1.2.3