Path Fix and Folder Name fix of OPCUA
[eliot.git] / blueprints / iotgateway / scripts / setup.sh
1 #!/bin/bash -ex
2 ##############################################################################
3 # Copyright (c) 2019 Huawei Tech and others.
4 #
5 # All rights reserved. This program and the accompanying materials
6 # are made available under the terms of the Apache License, Version 2.0
7 # which accompanies this distribution, and is available at
8 # http://www.apache.org/licenses/LICENSE-2.0
9 ##############################################################################
10
11 ########################################################################################
12 #                                                                                      #
13 # The script is to setup the ELIOT Manager and ELIOT nodes.                            #
14 # It installs Docker in both ELIOT Manager and ELIOT node.                             #
15 # It installs Kubernetes. In the ELIOT Manager kubeadm, kubelet, kubectl is installed. #
16 # In ELIOT Edge Node it will install kubeadn, kubelet.                                 #
17 # Script is tested in Ubuntu 16.04 version.                                            #
18 # sshpass needs to be installed before executing this script.                          #
19 ########################################################################################
20
21 echo "**********************************************************************"
22 echo "ELIOT IOT-Gateway Platform Deployment--------------------------STARTED"
23
24 # constants
25
26 OSPLATFORM=$(awk -F= '/^NAME/{print $2}' /etc/os-release)
27 ELIOT_REPO="https://gerrit.akraino.org/r/eliot"
28
29 show_help()
30 {
31   echo "The script helps in setting up the ELIOT Toplogy Infrastrucutre"
32   echo "The setup installs Docker, K8S Master and K8S worker nodes in  "
33   echo "ELIOT Manager and ELIOT Workder Nodes respectively "
34   echo "After completion of script execution execute command: "
35   echo "kubectl get nodes to check whether the connection between "
36   echo "ELIOT Manager and ELIOT Nodes are established"
37   echo ""
38   echo "Nodelist file should have the details of Worker Nodes in the format of:"
39   echo "EliotNodeUserName|EliotNodeIP|EliotNodePasswor"
40   echo "Each line should have detail of one ELIOT Node only"
41 }
42
43 # Setting up ELIOT Manager Node.
44 # Installing Docker, K8S and Initializing K8S Master
45 setup_k8smaster()
46 {
47   #set -o xtrace
48   sudo rm -rf ~/.kube
49   source common.sh | tee eliotcommon.log
50   source k8smaster.sh | tee kubeadm.log
51   # Setup ELIOT Node
52   setup_k8sworkers
53 }
54
55 setup_k8sworkers()
56 {
57   set -o xtrace
58
59   # Install Docker on ELIOT Node
60   SETUP_WORKER_COMMON="sudo rm -rf ~/eliot &&\
61                        git clone ${ELIOT_REPO} &&\
62                        cd eliot/blueprints/iotgateway/scripts/ && source common.sh"
63   #SETUP_WORKER_COMMON="cd eliot/scripts/ && source common.sh"
64   SETUP_WORKER="cd eliot/blueprints/iotgateway/scripts/ && source k8sworker.sh"
65
66   KUBEADM_TOKEN=$(kubeadm token create --print-join-command)
67   KUBEADM_JOIN="sudo ${KUBEADM_TOKEN}"
68
69  # Read all the Worker Node details from nodelist file.
70  while read line
71  do
72      nodeinfo="${line}"
73      nodeusr=$(echo ${nodeinfo} | cut -d"|" -f1)
74      nodeip=$(echo ${nodeinfo} | cut -d"|" -f2)
75      nodepaswd=$(echo ${nodeinfo} | cut -d"|" -f3)
76      sshpass -p ${nodepaswd} ssh ${nodeusr}@${nodeip} ${SETUP_WORKER_COMMON} < /dev/null
77      sshpass -p ${nodepaswd} ssh ${nodeusr}@${nodeip} ${SETUP_WORKER} < /dev/null
78      sshpass -p ${nodepaswd} ssh ${nodeusr}@${nodeip} ${KUBEADM_JOIN} < /dev/null
79  done < nodelist > /dev/null 2>&1
80
81 }
82
83 setup_k8smaster_centos()
84 {
85   set -o xtrace
86   sudo rm -rf ~/.kube
87   source common_centos.sh | tee eliotcommon_centos.log
88   source k8smaster_centos.sh | tee kubeadm_centos.log
89
90   # Setup ELIOT Node
91   setup_k8sworkers_centos
92
93   kubectl apply -f cni/calico/v38/calico.yaml
94
95 }
96
97
98 setup_k8sworkers_centos()
99 {
100   set -o xtrace
101   # Install Docker on ELIOT Node
102
103   SETUP_WORKER_COMMON_CENTOS="sudo rm -rf ~/eliot &&\
104                               git clone ${ELIOT_REPO} &&\
105                               cd eliot/blueprints/iotgateway/scripts/ && source common_centos.sh"
106
107   # SETUP_WORKER_COMMON_CENTOS="cd /root/eliot/scripts/ && source common_centos.sh"
108
109   KUBEADM_TOKEN=$(sudo kubeadm token create --print-join-command)
110   KUBEADM_JOIN_CENTOS="sudo ${KUBEADM_TOKEN}"
111   # Read all the Worker Node details from nodelist file.
112   while read line
113   do
114       nodeinfo="${line}" < /dev/null 2>&1
115       nodeusr=$(echo ${nodeinfo} | cut -d"|" -f1) < /dev/null
116       nodeip=$(echo ${nodeinfo} | cut -d"|" -f2)  < /dev/null
117       nodepaswd=$(echo ${nodeinfo} | cut -d"|" -f3) < /dev/null
118       sudo sshpass -p ${nodepaswd} ssh ${nodeusr}@${nodeip} ${SETUP_WORKER_COMMON_CENTOS} < /dev/null
119       sudo sshpass -p ${nodepaswd} ssh ${nodeusr}@${nodeip} ${KUBEADM_JOIN_CENTOS} < /dev/null
120   done < nodelist > /dev/null 2>&1
121
122 }
123
124 # verify kubernetes setup by deploying nginx server.
125
126 verify_k8s_status(){
127   set -o xtrace
128   source verifyk8s.sh | tee verifyk8s.log
129 }
130
131
132 install_edgex(){
133  set -o xtrace
134  cd edgex && source edgexonk8s.sh
135 }
136
137 # verify installation of edgex platform 
138 verify_edgex()
139 {
140  set -o xtrace
141  source verifyedgex.sh | tee verifyedgex.log
142
143 }
144
145
146 install_cadvisor_edge(){
147  set -o xtrace
148  SETUP_CADVISOR_ATEDGE="cd eliot/blueprints/iotgateway/scripts/ && source cadvisorsetup.sh"
149  while read line
150  do
151      nodeinfo="${line}"
152      nodeusr=$(echo ${nodeinfo} | cut -d"|" -f1)
153      nodeip=$(echo ${nodeinfo} | cut -d"|" -f2)
154      nodepaswd=$(echo ${nodeinfo} | cut -d"|" -f3)
155      sshpass -p ${nodepaswd} ssh ${nodeusr}@${nodeip} ${SETUP_CADVISOR_ATEDGE} < /dev/null
156  done < nodelist > /dev/null 2>&1
157  echo "CADVISOR Installed in all the ELIOT IOT-GATEWAY Nodes"
158 }
159
160 install_prometheus(){
161  set -o xtrace
162  source prometheus.sh | tee install_prometheus.log
163  echo "Prometheus deployed successfully on ELIOT Manager Node  and integrated with CAdvisor running on IOT-Gateway Nodes "
164 }
165
166 install_opcua_centos(){
167  set -o xtrace
168  INSTALL_OPCUA_ATEDGE="cd eliot/blueprints/iotgateway/scripts/opc-ua/ && source install.sh"
169  while read line
170  do
171      nodeinfo="${line}"
172      nodeusr=$(echo ${nodeinfo} | cut -d"|" -f1)
173      nodeip=$(echo ${nodeinfo} | cut -d"|" -f2)
174      nodepaswd=$(echo ${nodeinfo} | cut -d"|" -f3)
175      sshpass -p ${nodepaswd} ssh ${nodeusr}@${nodeip} ${INSTALL_OPCUA_ATEDGE} < /dev/null
176  done < nodelist > /dev/null 2>&1
177  echo " OPC-UA Server and Client are successfully Deployed on all IOT-Gateway Nodes"
178 }
179
180 # Start
181 #
182
183 if [ $1 == "--help" ] || [ $1 == "-h" ];
184 then
185   show_help
186   exit 0
187 fi
188
189 setupPath=`pwd`
190
191 if [[ $OSPLATFORM = *CentOS* ]]; then
192    setup_k8smaster_centos
193 else
194    setup_k8smaster
195 fi
196
197 sleep 20
198 verify_k8s_status
199 install_cadvisor_edge
200 sleep 10
201 install_prometheus
202 sleep 5
203 sudo docker ps | grep prometheus
204
205 install_edgex
206 sleep 20
207 verify_edgex
208
209 # Installing OPC-UA on IOT Gateway Node
210
211 cd ${setupPath}
212 if [[ $OSPLATFORM = *CentOS* ]]; then
213    install_opcua_centos
214 fi
215
216 # Removing the taint from master node
217 kubectl taint nodes --all node-role.kubernetes.io/master- || true
218
219 echo "**********************************************************************"
220 echo "ELIOT IOT-Gateway Platform Deployment--------------------------SUCCESS"
221