-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathdeploynode.sh
executable file
·83 lines (60 loc) · 1.91 KB
/
deploynode.sh
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
#!/bin/bash
#Deploy the weave overlay onto the footlocker hosts
#Jim McBride jm@gonkulator.io 8/28/15
set -e
usage()
{
echo ""
echo "Usage: $0 user@host network/mask"
echo "e.g., $0 jm@server1.gonkulator.io 10.100.101.0/24"
echo ""
exit 1
}
#functions / defines
targets=($(cat targets))
export sshtarget=$1
export dsthostname=$(echo ${sshtarget} | awk -F\@ '{print $2}')
export dstusername=$(echo ${sshtarget} | awk -F\@ '{print $1}')
export clusternetwork=$2
export clusternetworknocidr=$(echo ${clusternetwork} | awk -F\/ '{print $1}')
export clusternetworkcidr=$(echo ${clusternetwork} | awk -F\/ '{print $2}')
export clusternetworknolastoctet=$(echo ${clusternetworknocidr} | awk -F. '{print $1"."$2"."$3"."}')
export PID=$$
status() {
echo "[o] $*"
}
error() {
echo "[!] ERROR: $*"
}
#main
if [ $# -lt 2 ] ; then
usage
exit 1
fi
if [ ${clusternetworkcidr} -ne 24 ] ; then
error Sorry - currently only support /24 networks
exit 1
fi
######
export OCTET=1
for i in ${targets[@]}; do
status Starting weave on $(echo $i | awk -F\@ '{print $2}')
#ssh ${i} "weave launch --ipalloc-range ${clusternetwork}"
ssh ${i} "weave launch"
status Connecting $(echo $i | awk -F\@ '{print $2}') to CLAN
ssh ${i} "weave expose ${clusternetworknolastoctet}${OCTET}/24"
status Copying teleport script to $(echo $i | awk -F\@ '{print $2}'):.
scp teleport.sh ${i}:.
((OCTET++))
done
status Interconnecting nodes...
for i in ${targets[@]}; do
if [ ${i} != "${targets[0]}" ] ; then
status Connecting $(echo ${targets[0]} | awk -F \@ '{print $2}') to $(echo $i | awk -F\@ '{print $2}')
#dont even ask - yes this is the most portable system resolver based fix i could come up with in 10 minutes
ssh ${targets[0]} weave connect $(ping -t1 -c1 $(echo $i | awk -F\@ '{print $2}') | grep PING | awk '{print $3}' | sed s/[\)\(\:]//g)
#ssh ${targets[0]} weave connect $(echo $i | awk -F\@ '{print $2}')
else
status "Skipping self..."
fi
done