From d2bf81abd0c6708e41f3c8ce3546b117ff43555c Mon Sep 17 00:00:00 2001 From: lassulus Date: Mon, 11 May 2015 14:45:59 +0200 Subject: tinc-setup: add propagate-config --- retiolum/scripts/tinc_setup/propagate-config | 61 ++++++++++++++++++++++++++++ 1 file changed, 61 insertions(+) create mode 100755 retiolum/scripts/tinc_setup/propagate-config (limited to 'retiolum/scripts/tinc_setup') 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 "$@" -- cgit v1.2.3