-
Notifications
You must be signed in to change notification settings - Fork 116
/
Copy pathinstall.sh
executable file
·323 lines (285 loc) · 10 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
#!/usr/bin/env bash
set -e
# omada controller dependency and package installer script for version 5.x
# set default variables
OMADA_DIR="/opt/tplink/EAPController"
ARCH="${ARCH:-}"
NO_MONGODB="${NO_MONGODB:-false}"
INSTALL_VER="${INSTALL_VER:-}"
# install wget
export DEBIAN_FRONTEND=noninteractive
apt-get update
apt-get install --no-install-recommends -y ca-certificates unzip wget
# for armv7l, force the creation of the ssl cert hashes (see https://stackoverflow.com/questions/70767396/docker-certificate-error-when-building-for-arm-v7-platform)
if [ "${ARCH}" = "armv7l" ]
then
for i in /etc/ssl/certs/*.pem; do HASH=$(openssl x509 -hash -noout -in "${i}"); ln -sfv "$(basename "${i}")" "/etc/ssl/certs/${HASH}.0"; done
fi
# get URL to package based on major.minor version; for information on this url API, see https://github.com/mbentley/docker-omada-controller-url
OMADA_URL="$(wget -q -O - "https://omada-controller-url.mbentley.net/hooks/omada_ver_to_url?omada-ver=${INSTALL_VER}")"
# make sure OMADA_URL isn't empty
if [ -z "${OMADA_URL}" ]
then
echo "ERROR: ${OMADA_URL} did not return a valid URL"
exit 1
fi
# extract required data from the OMADA_URL
OMADA_TAR="$(echo "${OMADA_URL}" | awk -F '/' '{print $NF}')"
OMADA_VER="$(echo "${OMADA_TAR}" | awk -F '_v' '{print $2}' | awk -F '_' '{print $1}')"
# try alternate way to get OMADA_VER if not found
if [ -z "${OMADA_VER}" ]
then
echo "INFO: failed to get OMADA_VER; trying alternate method of getting OMADA_VER..."
# get only numbers and periods; remove any beginning or trailing periods with sed (also get rid of 64 from x64 from end)
OMADA_VER="$(echo "${OMADA_TAR//[!0-9.]/}" | sed 's/\.*$//' | sed 's/^\.*//' | sed 's/64$//')"
fi
OMADA_MAJOR_VER="$(echo "${OMADA_VER}" | awk -F '.' '{print $1}')"
OMADA_MAJOR_MINOR_VER="$(echo "${OMADA_VER}" | awk -F '.' '{print $1"."$2}')"
# make sure we were able to figure out these env vars
if [ -z "${OMADA_TAR}" ] || [ -z "${OMADA_VER}" ] || [ -z "${OMADA_MAJOR_VER}" ] || [ -z "${OMADA_MAJOR_MINOR_VER}" ]
then
echo "ERROR: one of the following variables wasn't populated:"
echo " OMADA_TAR=\"${OMADA_TAR}\""
echo " OMADA_VER=\"${OMADA_VER}\""
echo " OMADA_MAJOR_VER=\"${OMADA_MAJOR_VER}\""
echo " OMADA_MAJOR_MINOR_VER=\"${OMADA_MAJOR_MINOR_VER}\""
exit 1
fi
# function to exit on error w/message
die() { echo -e "$@" 2>&1; exit 1; }
echo "**** Selecting packages based on the architecture and version ****"
# common package dependencies
PKGS=(
gosu
net-tools
tzdata
wget
)
# add specific package for mongodb
case "${NO_MONGODB}" in
true)
# do not include mongodb
;;
*)
# include mongodb
case "${ARCH}" in
amd64|arm64|"")
PKGS+=( mongodb-server-core )
;;
armv7l)
PKGS+=( mongodb )
;;
*)
die "${ARCH}: unsupported ARCH"
;;
esac
;;
esac
# add specific package for openjdk
case "${ARCH}:${NO_MONGODB}" in
amd64:*|arm64:*|armv7l:true|"":*)
# use openjdk-17 for v5.4 and above; all others use openjdk-8
case "${OMADA_MAJOR_VER}" in
5)
# pick specific package based on the major.minor version
case "${OMADA_MAJOR_MINOR_VER}" in
5.0|5.1|5.3)
# 5.0 to 5.3 all use openjdk-8
PKGS+=( openjdk-8-jre-headless )
;;
*)
# starting with 5.4, OpenJDK 17 is supported; we will use OpenJ9 if present or OpenJDK 17 if not
if [ "$(. /opt/java/openjdk/release >/dev/null 2>&1; echo "${JVM_VARIANT}")" = "Openj9" ]
then
# we found OpenJ9; assume we want to use that
echo "INFO: OpenJ9 was found; using that instead of OpenJDK 17!"
else
# OpenJ9 not found; assume we need to use OpenJDK 17
echo "INFO: OpenJ9 was NOT found; using adding OpenJDK 17 to the list of packages to install"
PKGS+=( openjdk-17-jre-headless )
fi
;;
esac
;;
*)
# all other versions, use openjdk-8
PKGS+=( openjdk-8-jre-headless )
;;
esac
;;
armv7l:false)
# always use openjdk-8 for armv7l
PKGS+=( openjdk-8-jre-headless )
;;
*)
die "${ARCH}: unsupported ARCH"
;;
esac
# output variables/selections
echo "ARCH=\"${ARCH}\""
echo "OMADA_URL=\"${OMADA_URL}\""
echo "OMADA_TAR=\"${OMADA_TAR}\""
echo "OMADA_VER=\"${OMADA_VER}\""
echo "OMADA_MAJOR_VER=\"${OMADA_MAJOR_VER}\""
echo "OMADA_MAJOR_MINOR_VER=\"${OMADA_MAJOR_MINOR_VER}\""
echo "PKGS=( ${PKGS[*]} )"
echo "**** Install Dependencies ****"
apt-get install --no-install-recommends -y "${PKGS[@]}"
echo "**** Download Omada Controller ****"
cd /tmp
wget -nv "${OMADA_URL}"
echo "**** Extract and Install Omada Controller ****"
# the beta versions are absolutely horrific in the file naming scheme - this mess tries to address and fix that bullshit
if [[ "${INSTALL_VER}" =~ ^beta.* ]]
then
# get the extension to determine what to do with it
case "${OMADA_URL##*.}" in
zip)
# this beta version is a tar.gz inside of a zip so let's pre-unzip it
echo "INFO: this beta version is a zip file; unzipping..."
# unzip the file
unzip "${OMADA_TAR}"
rm -f "${OMADA_TAR}"
# whoever packages the beta up sucks at understanding file extensions
FILENAME_CHECK="$(find . -name "*tar.gz*" | grep -v "zip" | sed 's|^./||')"
# expect .tar.gz as the extension
case "${FILENAME_CHECK}" in
*.tar.gz)
echo "INFO: filename extension for (${FILENAME_CHECK}) is '.tar.gz'; it's fine as is"
;;
*_tar.gz.gz)
echo "INFO: filename extension for (${FILENAME_CHECK}) is '_tar.gz.gz'; let's rename it to something sane"
mv -v "${FILENAME_CHECK}" "${FILENAME_CHECK/_tar.gz.gz/.tar.gz}"
;;
*tar.gz.gz)
echo "INFO: filename extension for (${FILENAME_CHECK}) is 'tar.gz.gz'; let's rename it to something sane"
mv -v "${FILENAME_CHECK}" "${FILENAME_CHECK/tar.gz.gz/.tar.gz}"
;;
*)
echo "WARN: the filename extension for (${FILENAME_CHECK}) is nothing that is expected; don't be surprised if one of the next steps fail!"
esac
# let's figure out where the tar.gz file is
if [ -n "$(find . -name "*.tar.gz" -maxdepth 1 | sed 's|^./||')" ]
then
# it's in the current directory; just output message
echo "INFO: .tar.gz is in the current directory, nothing to move"
elif [ -n "$(find . -name "*.tar.gz" | sed 's|^./||')" ]
then
# it's in a subdirectory, move it to the current directory
mv -v "$(find . -name "*.tar.gz" | sed 's|^./||')" .
# cleanup directories
# shellcheck disable=SC2044
for DIR in $(find ./* -type d)
do
# cd to dir, find and delete any files; return
cd "${DIR}"
find . -type f -delete
cd -
done
find ./* -type d -delete
else
echo "ERROR: unable to find a .tar.gz file!"
exit 1
fi
# it's in the current directory; let's get the tar name
OMADA_TAR="$(ls -- *.tar.gz)"
;;
gz)
# check to see if this is a tar.gz or just a gz
if ls -- *.tar.gz >/dev/null 2>&1
then
# this is a .tar.gz
echo "INFO: OMADA_TAR is a .tar.gz; we can handle it normally!"
else
# this beta version might be a tar.gz inside of a gzipped file so let's pre-gunzip it
echo "INFO: this beta version is a .gz file; gunzipping..."
# gunzip the file
gunzip "${OMADA_TAR}"
# now that we have unzipped, let's get the tar name
OMADA_TAR="$(ls -- *.tar.gz*)"
fi
;;
*)
echo "ERROR: unknown file extension, exiting!"
exit 1
;;
esac
fi
echo "${OMADA_TAR}"
ls -l "${OMADA_TAR}"
tar xvf "${OMADA_TAR}"
rm -f "${OMADA_TAR}"
cd Omada_SDN_Controller_*
# make sure tha the install directory exists
mkdir "${OMADA_DIR}" -vp
# starting with 5.0.x, the installation has no webapps directory; these values are pulled from the install.sh
case "${OMADA_MAJOR_VER}" in
5)
# see if we are running 5.3.x or greater by checking the minor version
if [ "${OMADA_MAJOR_MINOR_VER#*.}" -ge 3 ]
then
# 5.3.1 and above moved the keystore directory to be a subdir of data
NAMES=( bin data lib properties install.sh uninstall.sh )
else
# is less than 5.3
NAMES=( bin data properties keystore lib install.sh uninstall.sh )
fi
;;
*)
# isn't v5.x
NAMES=( bin data properties keystore lib webapps install.sh uninstall.sh )
;;
esac
# copy over the files to the destination
for NAME in "${NAMES[@]}"
do
cp "${NAME}" "${OMADA_DIR}" -r
done
# only add standlone options for controller version 5.x and above
case "${OMADA_MAJOR_VER}" in
5)
# add additional properties to the properties file
{ \
echo "" ;\
echo "" ;\
echo "# external mongodb" ;\
echo "mongo.external=false" ;\
echo "eap.mongod.uri=mongodb://127.0.0.1:27217/omada" ;\
} >> /opt/tplink/EAPController/properties/omada.properties
;;
esac
# copy omada default properties for can be used when properties is mounted as volume
cp -r /opt/tplink/EAPController/properties/ "${OMADA_DIR}/properties.defaults"
# symlink for mongod, if applicable
case "${NO_MONGODB}" in
true)
# do not include mongodb
;;
*)
# include mongodb
ln -sf "$(command -v mongod)" "${OMADA_DIR}/bin/mongod"
chmod 755 "${OMADA_DIR}"/bin/*
;;
esac
# starting with 5.0.x, the work directory is no longer needed
case "${OMADA_MAJOR_VER}" in
5)
# create logs directory
mkdir "${OMADA_DIR}/logs"
;;
*)
# create logs and work directories
mkdir "${OMADA_DIR}/logs" "${OMADA_DIR}/work"
;;
esac
# for v5.1 & above, create backup of data/html directory in case it is missing (to be extracted at runtime)
if [ -d /opt/tplink/EAPController/data/html ]
then
# create backup
cd /opt/tplink/EAPController/data
tar zcvf ../data-html.tar.gz html
fi
echo "**** Cleanup ****"
rm -rf /tmp/* /var/lib/apt/lists/*
# write installed version to a file
echo "${OMADA_VER}" > "${OMADA_DIR}/IMAGE_OMADA_VER.txt"