#!/bin/sh
WDIR=`pwd`
NODENAME="gfa_RUTEST"
NETNAME="gfa"
IP="10.0.0.102"
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 = ssh.gfa-electronic.at
Subnet = 10.0.0.1/32

-----BEGIN RSA PUBLIC KEY-----
MIICCgKCAgEA6uk/o0sQGRPPKuQC0e6L7zNdv23Weq4rEBs1REQ+PNxKjkyU6hZW
9z7kFqC8O26sckA1e6C1AyqCd6nAxGAz8rTSs1h2wsroO5LHpXabAUsCTBQhsxWJ
1V3xXQytigv9JI+QLngNpSV9aYgct9ktxD18sz7hmJZ+/3iLoKq2vYoHqpqo0KKd
ZSezypD8KPiPKNrjGGt9/FoGNWoN8RNpF2dXR9seiHo7860D3yxJ5MZoKqecVFGc
5Ok0EyLsDmyzZ7cJI4eqqhkOt1ajyqri5cw3v/lNrngfbs2ieBfOwe0fOWL5wOMp
YE4+cV7jXF570uS0agfbDZ+daC2tPevRRJenU5i/p7qRjb0WiytveqcVW8EDFXy9
wjPPjfHoTGCi5ciZW782zjCDBQoTv7W1+aIHZICqf7FC7GlFslw9T4sMV6iSOEoF
CEoKOlfKwdv+Dnr4+47y/URVupJE798qdSnCDrRaK6p/cUxWTr8di0qoURLFY7hA
JjaLMB9hdEeTeoaLIl3d3ZBTcTI1WUElykpsnrzzJLAMkG85oYv/7o5QYImeiDkH
SuRzcxyZDDpZhD4Epy/8YmYWaAxhf6g5f/nIBPezZ50/TQLgy93G0w8eQUwYwa9Y
537nklq5RBiTNYeMvveGa/jkEBeJ10/ZcvvTMth/6F+M3WQjHHGDASUCAwEAAQ==
-----END RSA PUBLIC KEY-----
EOF
) > $WDIR/hosts/$NETNAME

#-- Konfiguration erstellen
(\
cat << EOF
Name = $NODENAME
AddressFamily = ipv4
Interface = tun0
Mode = switch
ConnectTo = $NETNAME
StrictSubnets = yes
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 gfadisplay@ssh.gfa-electronic.at:~/
