summaryrefslogtreecommitdiffstats
path: root/modules/retiolum/scripts/tinc_setup/install.sh
blob: 8834aafc25884f578fa52d724b5f4dd82acbc13c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
#! /bin/sh
# USE WITH GREAT CAUTION

make -C ../../ update
set -e

CURR=`pwd`
MYBIN=../../bin
netname=retiolum
# create configuration directory for $netname
mkdir -p /etc/tinc/$netname/hosts
cd /etc/tinc/$netname

echo "added known hosts:"
ls -1 hosts | LC_ALL=C sort
echo "delete the nodes you do not trust!"

myname="${1:-}"
if [ ! "$myname" ] 
then
  echo "select username: "
  read myname
fi
if [ ! -e "hosts/$myname" ]
then
  myipv4="${2:-}"
  mynet4=10.7.7.0
  
  if [ ! "$myipv4" ] 
  then
    echo "select v4 subnet ip (1-255) :"
    read v4num
    if [  "$v4num" -gt 0 -a "$v4num" -lt "256" ];
    then 
      echo "check"
    else
      echo "you are made of stupid. bailing out" 
      exit 1
    fi
    myipv4=10.7.7.$v4num
  fi
  echo "Subnet = $myipv4" > hosts/$myname

  myipv6=`${CURR}/../../bin/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


myipv6=${myipv6-`sed -rn 's|^Subnet *= *(42:[0-9A-Fa-f:]*/128)|\1|p' /etc/tinc/$netname/hosts/$myname`}

cat>tinc-up<<EOF
#! /bin/sh
ifconfig \$INTERFACE up $myipv4/24
route add -net $mynet4/24 dev \$INTERFACE
ip -6 addr add ${myipv6} dev \$INTERFACE
ip -6 route add 42::/16 dev \$INTERFACE
EOF

chmod +x tinc-up

cat>tinc.conf<<EOF
Name = $myname
ConnectTo = supernode
ConnectTo = kaah
ConnectTo = pa_sharepoint
Device = /dev/net/tun
EOF

if [ ! -e rsa_key.priv ] 
then
  echo "creating new keys"
  tincd -n $netname -K 
  python ${CURR}/write_channel.py || \
  echo "cannot write public key to IRC, you are on your own. Good Luck"
else
  echo "key files already exist, skipping"
  echo "if you know what you are doing, remove rsa_key.priv"
fi
# add user tincd
# this is what the setup scripts for the distribution has to do
#useradd tincd