-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathinstall.sh
executable file
·334 lines (302 loc) · 10.9 KB
/
install.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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
#!/bin/sh -i
set -e
# Install node and npm via nvm - https://github.com/nvm-sh/nvm
# Run this script like - bash script-name.sh
# Tested on Ubuntu, MacOS
# @playground
if [[ $OSTYPE == 'darwin'* ]]
then
echo 'MacOS'
which -s brew
if [[ $? != 0 ]]
then
# Install Homebrew
ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
fi
brew install socat jq
else
echo "Update and install jq"
sudo apt-get update && sudo apt-get upgrade -y && sudo apt-get install jq
fi
ensure_dialog_installed() {
if ! command -v dialog &> /dev/null; then
echo "dialog could not be found, attempting to install..."
# Detect the package manager and install dialog
if [[ "$OSTYPE" == "linux-gnu"* ]]; then
if command -v apt-get &> /dev/null; then
sudo apt-get update && sudo apt-get install -y dialog
elif command -v yum &> /dev/null; then
sudo yum install -y dialog
else
echo "No compatible package manager found. Please install dialog manually."
exit 1
fi
elif [[ "$OSTYPE" == "darwin"* ]]; then
# Assume Homebrew is installed on macOS
if command -v brew &> /dev/null; then
brew install dialog
else
echo "Homebrew is not installed. Please install Homebrew and dialog manually."
exit 1
fi
else
echo "Unsupported OS. Please install dialog manually."
exit 1
fi
else
echo "dialog is already installed."
fi
}
ensure_dialog_installed
ENV_SETUP=""
CONFIG_FILE=""
K8S_SETUP=""
PS3='Choose your environment setup: '
ENV_SETUP_OPTIONS=("Run-In-Containers" "All-In-One" "OH-Mesh" "Quit")
# Create a dialog box
CHOICE=$(dialog --colors --clear --no-shadow \
--backtitle "Setup Configuration" \
--title "\Zb\Z1Choose Your Environment Setup" \
--menu "\n\Zb\Z3Select an option:" 15 60 5 \
"1" "Run-In-Containers" \
"2" "All-In-One" \
"3" "OH-Mesh" \
"4" "Quit" \
3>&1 1>&2 2>&3)
case $CHOICE in
1)
ENV_SETUP="Run-In-Containers"
#echo "$ENV_SETUP, Runs both CLI and Agent in its own container, choose <Confirm> to continue setup."
;;
2)
ENV_SETUP="All-In-One"
#echo "$ENV_SETUP, Runs CLI, Agent & Management Hub on the same machine, choose <Confirm> to continue setup."
;;
3)
ENV_SETUP="OH-Mesh"
# echo "$ENV_SETUP, Set up OH Agent with Mesh, choose <Confirm> to continue setup."
;;
4)
# echo "User requested exit"
exit
;;
*)
# echo "Invalid option, exiting."
exit 1
;;
esac
if [ "${ENV_SETUP}" = "OH-Mesh" ]
then
# Use dialog to create a menu for Kubernetes setup
K8S_SETUP=$(dialog --colors --clear --no-shadow \
--backtitle "Kubernetes Setup" \
--title "\Zb\Z1Choose Kubernetes Setup for OH Agent with Mesh" \
--menu "\n\Zb\Z3Select Kubernetes setup:" 15 60 4 \
"None" "Kube is already setup" \
"K3S" "Setup K3S for OH Agent with Mesh" \
"K8S" "Setup K8S for OH Agent with Mesh" \
"Confirm" "Confirm your selection" \
"Quit" "Exit setup" \
3>&1 1>&2 2>&3)
case $K8S_SETUP in
"None")
echo "Kube is already setup."
K8S_SETUP="None"
;;
"K3S")
echo "Setup K3S for OH Agent with Mesh, choose <Confirm> to continue setup."
K8S_SETUP="K3S"
;;
"K8S")
echo "Setup K8S for OH Agent with Mesh, choose <Confirm> to continue setup."
K8S_SETUP="K8S"
;;
"Confirm")
echo "You have chosen $K8S_SETUP for your setup."
;;
"Quit")
echo "User requested exit"
exit
;;
*)
echo "Invalid option, exiting."
exit 1
;;
esac
fi
PS3='Continue with setup: '
configfile=("Config-File" "Confirm" "Help" "Quit")
while true; do
CHOICE=$(dialog --colors --clear --no-shadow \
--backtitle "Configuration File Setup" \
--title "\Zb\Z1Configuration Options" \
--menu "\n\Zb\Z3Select an option:" 15 60 4 \
"Config-File" "Provide configuration file path" \
"Confirm" "Confirm the provided configuration file" \
"Help" "Get help on what needs to be in the configuration file" \
"Quit" "Exit setup" \
3>&1 1>&2 2>&3)
case $CHOICE in
"Config-File")
CONFIG_FILE=$(dialog --title "Configuration File" --inputbox "Enter the absolute path to your configuration file:" 8 60 3>&1 1>&2 2>&3)
if [ "$?" -eq 1 ]; then
echo "User cancelled the input."
elif [ -z "$CONFIG_FILE" ]; then
dialog --title "Error" --msgbox "No path provided. Please provide a valid path." 5 50
else
dialog --title "File Provided" --msgbox "You have provided $CONFIG_FILE" 5 50
fi
;;
"Confirm")
if [ -z "${CONFIG_FILE}" ]; then
dialog --title "Error" --msgbox "You have not provided your configuration file." 5 50
else
dialog --title "File Provided" --msgbox "You have provided $CONFIG_FILE for this setup" 5 50
break
fi
;;
"Help")
dialog --title "Configuration Help" --msgbox "You would need to provide your configuration json file with the following info:\n\n{
\"org\": {\n
\"HZN_ORG_ID\": \"examples\",\n
\"HZN_DEVICE_TOKEN\": \"\",\n
\"HZN_DEVICE_ID\": \"device-name\",\n
\"HZN_EXCHANGE_USER_AUTH\": \"************\",\n
\"HZN_EXCHANGE_URL\": \"http://xxx.xxx.xxx.xxx:3090/v1\",\n
\"HZN_FSS_CSSURL\": \"http://xxx.xxx.xxx.xxx:9443/\",\n
\"HZN_AGBOT_URL\": \"http://xxx.xxx.xxx.xxx:3111\",\n
\"HZN_SDO_SVC_URL\": \"http://xxx.xxx.xxx.xxx:9008/api\",\n
\"HZN_AGENT_PORT\": \"8510\",\n
\"HZN_CSS\": false,\n
\"ANAX\": \"https://github.com/open-horizon/anax/releases/latest/download/agent-install.sh\"\n
},\n
\"service\": {\n
\"SERVICE_NAME\": \"chunk-saved-model-service\",\n
\"SERVICE_CONTAINER_NAME\": \"chunk-saved-model-service\",\n
\"SERVICE_VERSION\": \"1.0.0\",\n
\"SERVICE_VERSION_RANGE_UPPER\": \"1.0.0\",\n
\"SERVICE_VERSION_RANGE_LOWER\": \"1.0.0\",\n
\"SERVICE_CONTAINER_CREDS\": \"\",\n
\"VOLUME_MOUNT\": \"/mms-shared\",\n
\"MMS_SHARED_VOLUME\": \"mms_shared_volume\",\n
\"MMS_OBJECT_TYPE\": \"chunk_object_detection\",\n
\"MMS_OBJECT_ID\": \"chunk_config.json\",\n
\"MMS_OBJECT_FILE\": \"config/config.json\",\n
\"MMS_CONTAINER_CREDS\": \"\",\n
\"MMS_CONTAINER_NAME\": \"chunk-mms-service\",\n
\"MMS_SERVICE_NAME\": \"chunk-mms-service\",
\"MMS_SERVICE_VERSION\": \"1.0.1\",
\"MMS_SERVICE_FALLBACK_VERSION\": \"1.0.0\",\n
\"UPDATE_FILE_NAME\": \"model.zip\"\n
},\n
\"folders\": [\n
\"/var/tmp/horizon/horizon1/fss-domain-socket\",\n
\"/var/tmp/horizon/horizon1/ess-auth\",\n
\"/var/tmp/horizon/horizon1/secrets\",\n
\"/var/tmp/horizon/horizon1/nmp\"\n
],\n
\"local\": {\n
\"YOUR_DOCKERHUB_ID\": \"dockerid\",\n
\"DOCKER_REGISTRY\": \"hub.docker.com\",\n
\"DOCKER_TOKEN\": \"dckr_pat_w......\"\n
},\n
\"anaxInContainer\": \"docker run -d -t --restart always --name horizon1 --privileged -p 127.0.0.1:8081:8510 -e DOCKER_NAME=horizon1 -e HZN_VAR_RUN_BASE=/var/tmp/horizon/horizon1 -v /var/run/docker.sock:/var/run/docker.sock -v /var/horizon:/etc/default/horizon:ro -v /var/agent-install.crt:/var/agent-install.crt -v horizon1_var:/var/horizon/ -v horizon1_etc:/etc/horizon/ -v /var/tmp/horizon/horizon1:/var/tmp/horizon/horizon1 openhorizon/amd64_anax:2.30.0-952\",\n
\"cliInContainer\": \"docker run -d -it --restart always --name hzn-cli --privileged --network=\\\"host\\\" -v /var/run/docker.sock:/var/run/docker.sock -v /var/agent-install.crt:/var/agent-install.crt -e HORIZON_URL=http://localhost:8081 -e HZN_ORG_ID=${HZN_ORG_ID} -e HZN_EXCHANGE_USER_AUTH=${HZN_EXCHANGE_USER_AUTH} -e HZN_FSS_CSSURL=${HZN_FSS_CSSURL} -e HZN_EXCHANGE_URL=${HZN_EXCHANGE_URL} -e version=v2.30.0-952 playbox21/hzn-cli_amd64\"\n
}" 22 70
;;
"Quit")
echo "User requested exit"
exit
;;
*) dialog --title "Invalid Option" --msgbox "Invalid option, exiting." 5 50
exit 1
;;
esac
done
if [[ -f "${HOME}/.nvm/nvm.sh" ]]; then
export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" # This loads nvm
[ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion" # This loads nvm bash_completion
else echo "nvm not installed"
# Define versions
INSTALL_NODE_VER=20
INSTALL_NVM_VER=0.39.5
# You can pass argument to this script --version 8
if [ "$1" = '--version' ]; then
echo "==> Using specified node version - $2"
INSTALL_NODE_VER=$2
fi
echo "==> Ensuring .bashrc exists and is writable"
touch ~/.bashrc
echo "==> Installing node version manager (NVM). Version $INSTALL_NVM_VER"
# Removed if already installed
rm -rf ~/.nvm
# Unset exported variable
export NVM_DIR=
# Install nvm
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v$INSTALL_NVM_VER/install.sh | bash
# Make nvm command available to terminal
source ~/.nvm/nvm.sh
echo "==> Installing node js version $INSTALL_NODE_VER"
nvm install $INSTALL_NODE_VER
echo "==> Make this version system default"
nvm alias default $INSTALL_NODE_VER
nvm use default
echo "==> Checking for versions"
nvm --version
echo "==> List installed node versions"
nvm ls
nvm cache clear
echo "==> Now you're all setup and ready for development. If changes are yet to take effect in the current shell, try source ~/.bashrc or open a new shell"
fi
echo "==> Print binary paths"
which npm
which node
echo "==> Checking for versions"
node --version
npm --version
echo -e "==> Update npm to latest version, if this stuck then terminate (CTRL+C) the execution"
npm install -g npm
if [ "$1" = "--skip-hzn-cli" ]
then
echo "==> Skipping oh cli installation"
else
echo "==> Installing oh cli"
npm i -g hzn-cli
fi
echo "==> Checking oh version"
oh --version
echo "==> Setting up hzn environment..."
sudo touch /etc/default/horizon
if [ "${ENV_SETUP}" = "Cli-And-Anax" ]
then
echo "$ENV_SETUP, here we go."
oh deploy autoSetup --config_file ${CONFIG_FILE}
elif [ "${ENV_SETUP}" = "CLI-Only" ]
then
echo "$ENV_SETUP, here we go."
oh deploy autoSetupCliOnly --config_file ${CONFIG_FILE}
elif [ "${ENV_SETUP}" = "CLI-In-Container" ]
then
echo "$ENV_SETUP, here we go."
oh deploy autoSetupCliInContainer --config_file ${CONFIG_FILE}
elif [ "${ENV_SETUP}" = "Anax-In-Container" ]
then
echo "$ENV_SETUP, here we go."
oh deploy autoSetupAnaxInContainer --config_file ${CONFIG_FILE}
elif [ "${ENV_SETUP}" = "Run-In-Containers" ]
then
echo "$ENV_SETUP, here we go."
oh deploy autoSetupContainer --config_file ${CONFIG_FILE}
elif [ "${ENV_SETUP}" = "All-In-One" ]
then
echo "$ENV_SETUP, here we go."
oh deploy autoSetupAllInOne --config_file ${CONFIG_FILE}
elif [ "${ENV_SETUP}" = "OH-Mesh" ]
then
echo "$ENV_SETUP, here we go."
oh deploy autoSetupOpenHorizonMesh --config_file ${CONFIG_FILE} --k8s ${K8S_SETUP}
else
echo "Something went wrong...$ENV_SETUP"
break
fi