#!/bin/sh
WDIR=`pwd`
NODENAME="node??"
NETNAME="psgnet"
IP="10.222.0.???"
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 = gogs.psg-bgh.de 443
Subnet = 10.222.0.1/32

-----BEGIN RSA PUBLIC KEY-----
MIICCgKCAgEA0C7f+XIVcIJ0hHPkLXQ2HSAsqRBGuZBND3opPEI9IlR13HemSpIT
N0ME4guB94I6RyUyTu/JhHzwUUFNnD/3OtEu3fPmmyjPUk0+nhsvoaqN9JBT/U9/
ujgziNR5N1l6m/51FDU0dryOLASgnyWEPr7ozesrUcZxV12iAdspa2zsDMoLBhbC
/ro2pqp0cSNzsuWhV2qEXiJEoTIU71t6t0cvWpXzwGSqUPxxJuQ74I0Xx7q/6eFm
jy44x7L5OX/EIqanSUoQ+pFCit7Vdb1CNU+s6OWnxA9dxxWdVfCkB9CrPbto4o8t
R6qbA2Y8F5hOAdeEYD/rpqAs/WcvNxiMtK0Zkr1sJIQv9ujY6dwCv9LShsEtCJkk
F4eYuak2kGStWBQmpbCBqAleglt9pI7azzBi4Dt/17O4qQZJLjJuaT6TOc2cx8+s
D24x3mUwpsYhUNx19/e5IYlJZSQhJNHUa212LT+7dmjwkAoUGZ2ZUIjWUpOBAPXJ
K2FAunOOPd5HImIKz3ST6zHTy9L0xnGSK4K52//bfsOnpo4pGtu5ERWqU+66gjyq
MJLBKcajRP9JZIyFvHgJYBE1LFo4e7hs4SHf3hon8TptcuVcL5ANQm8ZXyQH5riL
Sxx0a9uhkBFpLcvy1VIWgtyYyFDe+4PyXAP+CPvkJc69PuIibN9Vk+ECAwEAAQ==
-----END RSA PUBLIC KEY-----
EOF
) > $WDIR/hosts/$NETNAME

#-- Konfiguration erstellen
(\
cat << EOF
Name = $NODENAME
PingTimeout = 40
AddressFamily = ipv4
Interface = tun5
Port = 443
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 psgnet@gogs.psg-bgh.de:~/
