diff options
author | makefu <github@syntax-fehler.de> | 2014-02-20 18:50:20 +0100 |
---|---|---|
committer | makefu <github@syntax-fehler.de> | 2014-02-20 18:50:20 +0100 |
commit | f46851de1af7c044471523c40e0fe88579b8a997 (patch) | |
tree | f5d2e1424ef4cae39881bae5f4966976c482e12c | |
parent | 3d8232b6effc27bea833f0f99ab80f7c740d5433 (diff) |
add proposal for find-supers
this script may be used when bootstrapping new retiolum nodes
-rw-r--r-- | ship/lib/retiolum | 76 | ||||
-rw-r--r-- | ship/src/find-supers-tinc | 6 |
2 files changed, 82 insertions, 0 deletions
diff --git a/ship/lib/retiolum b/ship/lib/retiolum new file mode 100644 index 00000000..015537bd --- /dev/null +++ b/ship/lib/retiolum @@ -0,0 +1,76 @@ +#!/bin/sh +# retiolum host functions +#@include core +netname=${netname:-retiolum} + + +check_free_v4(){ + myipv4=${1-10.243.0.-1} + v4num=${myipv4##*.} + printf "Retard check: " + if [ "$v4num" -gt 0 -a "$v4num" -lt "256" ]; + then + info "No retard detected\n" + cd /etc/tinc/$netname/hosts + info "Check if ip is still free: " + for i in `ls -1`; do + if grep -q -e $myipv4\$ $i ;then + warn "Host IP already taken by $i! " + return 1 + fi + done + info "Passed\n" + return 0 + else + error "you are made of stupid. bailing out\n" + return 1 + fi + cd - >/dev/null +} + +find_active_nodes(){ + # TODO this function currently only supports a single address for a host + cd /etc/tinc/retiolum/hosts + # posix grep does not support [[:space:]] + for name in ` + grep '^[ ]*Address[ ]*=' * | + cut -d: -f1 | sort | uniq + `; do + if eval "`sed -n ' + s/[ ]\+//g + s/^\(Address\|Port\)=\(.*\)/\1="\${\1+\$\1\n}\2"/p + ' $name`"; then + port=${Port-655} + for host in $Address; do + if nc -zw 2 $host $port 2>/dev/null; then + echo "$name [('$host', $port)]" + fi & + done + wait + fi & + done + wait + cd - >/dev/null +} +find_supernodes(){ + cd /etc/tinc/retiolum/hosts + for name in ` + grep '^[ ]*Address[ ]*=' * | + cut -d: -f1 | sort | uniq + `; do + if eval "`sed -n ' + s/[ ]\+//g + s/^\(Address\|Port\)=\(.*\)/\1="\${\1+\$\1\n}\2"/p + ' $name`"; then + port=${Port-655} + for host in $Address; do + if nc -zw 2 $host $port 2>/dev/null; then + echo "$name [('$host', $port)]" + fi & + done + wait + fi & + done + wait + cd - >/dev/null +} diff --git a/ship/src/find-supers-tinc b/ship/src/find-supers-tinc new file mode 100644 index 00000000..edbb5a7b --- /dev/null +++ b/ship/src/find-supers-tinc @@ -0,0 +1,6 @@ +#!/bin/sh +#@include core +#@include retiolum + +find_supernodes | cut -d\ -f 1 | shuf | head -n 5 \ + | xargs -n1 printf "ConnectTo=%s\n" |