summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorlassulus <lass@aidsballs.de>2015-05-11 14:45:59 +0200
committerlassulus <lass@aidsballs.de>2015-05-11 14:45:59 +0200
commitd2bf81abd0c6708e41f3c8ce3546b117ff43555c (patch)
tree430041ded54e12bc00d03b5f30688b8d6b6fb00a
parent31fcd8aa88098598c500512f6783a70aa4b2ba9d (diff)
tinc-setup: add 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 "$@"