diff options
Diffstat (limited to 'retiolum/scripts/tinc_setup')
-rwxr-xr-x | retiolum/scripts/tinc_setup/install.sh | 46 | ||||
-rwxr-xr-x | retiolum/scripts/tinc_setup/tinc-up | 21 | ||||
-rw-r--r-- | retiolum/scripts/tinc_setup/write_channel.py | 9 |
3 files changed, 47 insertions, 29 deletions
diff --git a/retiolum/scripts/tinc_setup/install.sh b/retiolum/scripts/tinc_setup/install.sh index 9df38df7..a6b50b8a 100755 --- a/retiolum/scripts/tinc_setup/install.sh +++ b/retiolum/scripts/tinc_setup/install.sh @@ -1,11 +1,18 @@ #! /bin/sh # USE WITH GREAT CAUTION +set -eu + +if test "${nosudo-false}" != true -a `id -u` != 0; then + echo "we're going sudo..." >&2 + exec sudo "$0" "$@" + exit 23 # go to hell +fi #make -C ../../ update set -e DIRNAME=`dirname $0` CURR=`readlink -f ${DIRNAME}` -MYBIN=../../bin +MYBIN=${CURR}/../../bin netname=retiolum # create configuration directory for $netname mkdir -p /etc/tinc/$netname/hosts @@ -15,45 +22,50 @@ echo "added known hosts:" ls -1 hosts | LC_ALL=C sort echo "delete the nodes you do not trust!" +hostname="${HOSTNAME-`cat /etc/hostname`}" myname="${1:-}" if [ ! "$myname" ] then - echo "select username: " + printf "select node name [$hostname]: " read myname + if test -z "$myname"; then + myname="$hostname" + fi fi if [ ! -e "hosts/$myname" ] then + + # TODO eloop until we found a free IPv4 + # myipv4=$(echo 42.$(for i in `seq 1 3`; do echo "ibase=16;`bin/fillxx xx|tr [a-f] [A-F]`" | bc; done)|tr \ .)/32 + myipv4="${2:-}" - mynet4=10.7.7.0 + mynet4=10.243.0.0 if [ ! "$myipv4" ] then - echo "select v4 subnet ip (1-255) :" + printf 'select v4 subnet ip (1-255): ' read v4num - myipv4=10.7.7.$v4num - if [ "$v4num" -gt 0 -a "$v4num" -lt "256" ]; - then - echo "check" - else - echo "you are made of stupid. bailing out" - exit 1 - fi + until $MYBIN/check-free-retiolum-v4 $v4num; do + echo "your're an idiot!" + printf 'select unused v4 subnet ip (1-255): ' + read v4num + done + myipv4="10.243.0.$v4num" fi echo "Subnet = $myipv4" > hosts/$myname - myipv6=`${CURR}/../../bin/fillxx 42:xxxx:xxxx:xxxx:xxxx:xxxx:xxxx:xxxx`/128 + myipv6=`$MYBIN/fillxx 42:xxxx:xxxx:xxxx:xxxx:xxxx:xxxx:xxxx`/128 echo "Subnet = $myipv6" >> hosts/$myname else echo "own host file already exists! will not write again!" fi -cp $CURR/tinc-up /etc/tinc/$netname/ - cat>tinc.conf<<EOF Name = $myname -ConnectTo = supernode -ConnectTo = kaah +ConnectTo = euer +ConnectTo = oxberg ConnectTo = pa_sharepoint +ConnectTo = supernode Device = /dev/net/tun EOF diff --git a/retiolum/scripts/tinc_setup/tinc-up b/retiolum/scripts/tinc_setup/tinc-up index ae7c68e6..a829528d 100755 --- a/retiolum/scripts/tinc_setup/tinc-up +++ b/retiolum/scripts/tinc_setup/tinc-up @@ -4,17 +4,22 @@ dirname="`dirname "$0"`" conf=$dirname/tinc.conf -name=`sed -rn 's|^ *Name *= *([^ ]*) *$|\1|p' $conf` +name=`sed -n 's|^ *Name *= *\([^ ]*\) *$|\1|p' $conf` host=$dirname/hosts/$name -route4=10.7.7.0/24 -addr4=`sed -rn 's|^ *Subnet *= *(10\.[^ ]*) *$|\1|p' $host` +ip link set $INTERFACE up -route6=42::/16 -addr6=`sed -rn 's|^ *Subnet *= *(42:[^ ]*) *$|\1|p' $host` +addr4=`sed -n 's|^ *Subnet *= *\(10[.][^ ]*\) *$|\1|p' $host` +if [ "$addr4" != '' ];then + ip -4 addr add $addr4 dev $INTERFACE + ip -4 route add 10.243.0.0/16 dev $INTERFACE +else + addr4=`sed -n 's|^ *Subnet *= *\(42[.][^ ]*\) *$|\1|p' $host` + ip -4 addr add $addr4 dev $INTERFACE + ip -4 route add 42.0.0.0/16 dev $INTERFACE +fi -ifconfig $INTERFACE up $addr4 -route add -net $route4 dev $INTERFACE +addr6=`sed -n 's|^ *Subnet *= *\(42[:][^ ]*\) *$|\1|p' $host` ip -6 addr add $addr6 dev $INTERFACE -ip -6 route add $route6 dev $INTERFACE +ip -6 route add 42::/16 dev $INTERFACE diff --git a/retiolum/scripts/tinc_setup/write_channel.py b/retiolum/scripts/tinc_setup/write_channel.py index a11d4605..8299fa8d 100644 --- a/retiolum/scripts/tinc_setup/write_channel.py +++ b/retiolum/scripts/tinc_setup/write_channel.py @@ -3,18 +3,19 @@ import random, sys, time, socket try: myname=sys.argv[1] except: - print "you are made of stupid" + print("you are made of stupid") exit (23) -CHANNEL = '#tincspasm' +CHANNEL = '#krebsco' HOST='irc.freenode.net' FILE="/etc/tinc/retiolum/hosts/"+myname PORT=6667 NICK= myname+"_"+str(random.randint(23,666)) +print("Connecting...") sock = socket.socket(socket.AF_INET,socket.SOCK_STREAM) sock.connect((HOST,PORT)) -print NICK +print(NICK) sock.send("NICK %s\r\n" % NICK) sock.send("USER %s %s bla : %s\r\n" %(NICK,HOST,NICK)) sock.send("JOIN %s\r\n" % CHANNEL) @@ -22,5 +23,5 @@ time.sleep(23) f = open(FILE,'r') a = [ sock.send("PRIVMSG %s : %s" % ( CHANNEL,line)) for line in f] time.sleep(5) #because irc is so lazy -print "closing socket" +print("closing socket") sock.close() |