summaryrefslogtreecommitdiffstats
path: root/retiolum/scripts/tinc_setup/propagate-config
diff options
context:
space:
mode:
authortv <tv@shackspace.de>2015-05-20 16:49:23 +0200
committertv <tv@shackspace.de>2015-05-20 16:49:23 +0200
commit3cd71ef8189dc9226dfa01a91617d81ad4d429d6 (patch)
treeb4bda0b3b7a09daca5f16f52c1148c1dacce4b86 /retiolum/scripts/tinc_setup/propagate-config
parenta628b68dab6408ede1f695e9aa55c5df7b110e3b (diff)
parentc5a4be51df09659d9bbf7da573b4568ce56b7514 (diff)
Merge branch 'master' of https://github.com/krebscode/painload
Diffstat (limited to 'retiolum/scripts/tinc_setup/propagate-config')
-rwxr-xr-xretiolum/scripts/tinc_setup/propagate-config61
1 files changed, 61 insertions, 0 deletions
diff --git a/retiolum/scripts/tinc_setup/propagate-config b/retiolum/scripts/tinc_setup/propagate-config
new file mode 100755
index 00000000..27a9880a
--- /dev/null
+++ b/retiolum/scripts/tinc_setup/propagate-config
@@ -0,0 +1,61 @@
+#!/bin/sh -x
+set -euf
+
+main() {
+
+ if [ $# -ne 1 ]; then
+ usage
+ exit 1
+ fi
+
+ TINCDIR=$1
+
+ HOSTN=$(cat $TINCDIR/tinc.conf | awk '/Name ?=/ {gsub(/Name ?= ?/, ""); print}')
+ NICK="${HOSTN}_$(head /dev/urandom | tr -dc "0123456789" | head -c3)"
+
+ IRCCHANNEL=${IRCCHANNEL:-"#krebs_incoming"}
+ IRCSERVER=${IRCSERVER:-"irc.freenode.net"}
+ IRCPORT=${IRCPORT:-6667}
+
+ test -z ${HOSTSDIR+x} && find_hostdir
+
+ test -z ${TELNET+x} && find_telnet
+
+ ( echo "NICK $NICK";
+ echo "USER $NICK $IRCSERVER bla : $NICK";
+ echo "JOIN $IRCCHANNEL";
+ sleep 23;
+ echo "PRIVMSG $IRCCHANNEL : This is $HOSTN";
+ sed "s/^\(.*\)/PRIVMSG $IRCCHANNEL : \1/" $HOSTSDIR/$HOSTN;
+ sleep 5; ) | $TELNET $IRCSERVER $IRCPORT
+}
+
+exists() {
+ type "$1" >/dev/null 2>/dev/null;
+}
+
+find_hostdir() {
+ if [ -e "$TINCDIR/hosts" ]; then
+ HOSTSDIR="$TINCDIR/hosts"
+ else
+ echo 'cannot find hostsdir of tinc, please specify with HOSTSDIR=...'
+ exit 1
+ fi
+}
+
+find_telnet() {
+ if exists telnet >/dev/null; then
+ TELNET=$(command -v telnet)
+ else
+ echo "cannot find telnet binary, please install telnet-client"
+ echo "bailing out!"
+ exit 1
+ fi
+}
+
+usage() {
+ echo './propagate-config $TINCDIR'
+ echo 'If the hosts dir is not in $TINC_DIR you have to specify it using HOSTSDIR=$path_to_hostsdir ./propagate $TINCDIR.'
+}
+
+main "$@"