#!/bin/sh
WDIR=`pwd`
NODENAME="rru_disprru"
NETNAME="runet"
IP="10.234.0.126"
NETMASK="255.255.255.0"
NETWORK="$IP/32"

rm -rf $NETNAME
mkdir -p $NETNAME/hosts
WDIR=$WDIR/$NETNAME

#--- interface erstellen
echo ">>"$WDIR"<<"
(\
cat << EOF
#--- automatisch erstellt
Subnet = $NETWORK
EOF
) > $WDIR/hosts/$NODENAME

#--- zieldaten
echo ">>"$WDIR"<<"
(\
cat << EOF
Address = spider.ruhome.de 755
Subnet = 10.234.0.1/24

-----BEGIN RSA PUBLIC KEY-----
MIICCgKCAgEArTGjeAuZ6/qLMEUtLlWWfp0HRxx7ivMAICcxLZbvpNLNZ6r1Z2Yr
/pk9378vqIviNzxHw6Gktuat69rebTJifzhMnZjxm9J9PFBsKxFtn95sGs0glj2Q
pImbKucrFjgUd/FWw/rp1MwqHIlh/pVfJ7tncsQfroD1KY7/52NHNOl9yk6UW6xT
0lsdFFXUOU8l+JFt+uYgIa/ZWf0hNsB30TTU1TeIY/AMjwxoGG8ax6OZNR5Dowfg
HwsVkxBaHq1kyJG06YUZvxuZ/ONw7cpGgLqK4uBtTRWgYx3C19SrQMsWNBGIIYXd
oM08k9u1kcYRgH5tbxEV5RpNACXgfdT3BAdbXoAhjQE69xTbthIRHeu0PIRO6F//
ujA2pWmpumpEY8pJHnydUwINI687Ev428GQFWfXW9xGZ3C5Xg3huU2vhA5yVc0vM
cxM8aBBpYrqjd0HUlowqwA7Carmvy+rdz3ih2UmD6xvhUA8UGLSGyJr/7648GiqU
uoTcUL4mZJzfvaP6k5A7/ivHbOhIljHDGryZPu72hks48sqk+HR9FH9lTNZEiE/L
EC1ieCQl++V5PpeopPcD+BJaONtKfF1b6ePV/nwIMdtcR0ZF4qCSu/eZQ4DcWLa+
Ztfc3C/SvupUNJG/9vjmtIDjw2Fo062FIzvfMibjXCb96Upnj9ai8zECAwEAAQ==
-----END RSA PUBLIC KEY-----

EOF
) > $WDIR/hosts/$NETNAME

#-- Konfiguration erstellen
(\
cat << EOF
Name = $NODENAME
AddressFamily = ipv4
Interface = tun2
Port = 755
Mode = router
ConnectTo = $NETNAME
EOF
) > $WDIR/tinc.conf

#-- up script erstellen
(\
cat << EOF
#!/bin/sh
ifconfig \$INTERFACE $IP netmask $NETMASK
EOF
) > $WDIR/tinc-up
chmod u+x $WDIR/tinc-up

#-- down script erstellen
(\
cat << EOF
#!/bin/sh
ifconfig \$INTERFACE down
EOF
) > $WDIR/tinc-down
chmod u+x $WDIR/tinc-down

tincd  -c $WDIR -K4096 <<EOF


EOF

scp $WDIR/hosts/$NODENAME runet@spider.ruhome.de:~/
