-
Notifications
You must be signed in to change notification settings - Fork 0
/
lsws_whm_plugin_install.sh
413 lines (319 loc) · 12.7 KB
/
lsws_whm_plugin_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
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
#!/bin/sh
# /********************************************
# LiteSpeed Web Server Plugin for WHM
#
# @author LiteSpeed Technologies, Inc. (https://www.litespeedtech.com)
# @copyright (c) 2008-2022
# *********************************************/
#
# If from lsws install, 3 params
# WHM_PLUGIN_SRCDIR=$1
# LSWS_HOME=$2
# CPANEL_PLUGIN_AUTOINSTALL=$3
#
WHM_PLUGIN_TEMPDIR="/usr/src/lsws_whm"
WHM_DOCROOT="/usr/local/cpanel/whostmgr/docroot"
WHM_PLUGIN_CGIDIR="${WHM_DOCROOT}/cgi"
WHM_PLUGIN_ICONDIR="${WHM_DOCROOT}/addon_plugins"
WHM_PLUGIN_INSDIR="${WHM_PLUGIN_CGIDIR}/lsws"
WHM_PLUGIN_TMPL_INSDIR="${WHM_DOCROOT}/templates/lsws"
WHM_PLUGIN_LSCWP_SRC_DIR="/usr/src/litespeed-wp-plugin"
WHM_PLUGIN_HTTPDIR="http://www.litespeedtech.com/packages/cpanel"
THEME_JUPITER_PLUGIN_DIR="/usr/local/cpanel/base/frontend/jupiter/ls_web_cache_manager"
THEME_PAPER_LANTERN_PLUGIN_DIR="/usr/local/cpanel/base/frontend/paper_lantern/ls_web_cache_manager"
CPANEL_PLUGIN_CAPABLE=0
if [ ! -d "${WHM_PLUGIN_CGIDIR}" ] ; then
exit
fi
WHM_PLUGIN_INST_USER=$(id)
WHM_PLUGIN_INST_USER=$(expr "${WHM_PLUGIN_INST_USER}" : 'uid=.*(\(.*\)) gid=.*')
if [ "${WHM_PLUGIN_INST_USER}" != "root" ] ; then
echo "Require root permission to install this plugin. Abort!"
exit
fi
if [ "x${2}" = "x" ] ; then
LSWS_HOME="/usr/local/lsws"
else
LSWS_HOME="${2}"
fi
WEBCACHE_MGR_DATA_DIR="${LSWS_HOME}/admin/lscdata"
CPANEL_PLUGIN_AUTOINSTALL_DISABLE_FLAG="${WHM_PLUGIN_INSDIR}/cpanel_autoinstall_off"
TMP_CPANEL_PLUGIN_AUTOINSTALL_DISABLE_FLAG="/tmp/cpanel_autoinstall_off"
WHM_PLUGIN_DATA_DIR="${WHM_PLUGIN_INSDIR}/data"
TMP_WHM_PLUGIN_DATA_DIR="/tmp/lsws_whm_plugin_data_tmp"
WHM_PLUGIN_LSWS_HOME_FILE="${WHM_PLUGIN_INSDIR}/LSWS_HOME.config"
TMP_WHM_PLUGIN_LSWS_HOME_FILE="/tmp/LSWS_HOME.config"
whmPluginNeedsUpdate()
{
CURR_WHM_VER="${1}"
if ! LATEST_WHM_VER=$(wget -qO- "${WHM_PLUGIN_HTTPDIR}/WHM_LATEST_VER"); then
echo "Failed to query latest WHM plugin version (wget failure). Abort!"
exit;
fi
FILTERED_LATEST_WHM_VER="$(echo "${LATEST_WHM_VER}" | \
sed -e 's/^[^[:digit:]]*\.//g' -e 's/\.\+$//g' -e 's/\.+$//g' -e 's/\.\.\+/\./g' -e 's/[^[:digit:]\.]//g')"
if [ "${LATEST_WHM_VER}" != "${FILTERED_LATEST_WHM_VER}" ] ; then
echo "Failed to query latest WHM plugin version (unexpected content). Abort!"
exit;
fi
CURR_MAJOR=$(echo "${CURR_WHM_VER}" | awk -F"." '{print $1}')
LATEST_MAJOR=$(echo "${LATEST_WHM_VER}" | awk -F"." '{print $1}')
if [ "${CURR_MAJOR}" -lt "${LATEST_MAJOR}" ] ; then
return 0
elif [ "${CURR_MAJOR}" -gt "${LATEST_MAJOR}" ] ; then
return 1
fi
CURR_MINOR=$(echo "${CURR_WHM_VER}" | awk -F"." '{print $2}')
LATEST_MINOR=$(echo "${LATEST_WHM_VER}" | awk -F"." '{print $2}')
if [ "${CURR_MINOR}" -lt "${LATEST_MINOR}" ] ; then
return 0
elif [ "${CURR_MINOR}" -gt "${LATEST_MINOR}" ] ; then
return 1
fi
CURR_IMPROVEMENT=$(echo "${CURR_WHM_VER}" | awk -F"." '{print match($3, /[^ ]/) ? $3 : 0}')
LATEST_IMPROVEMENT=$(echo "${LATEST_WHM_VER}" | awk -F"." '{print match($3, /[^ ]/) ? $3 : 0}')
if [ "${CURR_IMPROVEMENT}" -lt "${LATEST_IMPROVEMENT}" ] ; then
return 0
elif [ "${CURR_IMPROVEMENT}" -gt "${LATEST_IMPROVEMENT}" ] ; then
return 1
fi
CURR_PATCH=$(echo "${CURR_WHM_VER}" | awk -F"." '{print match($4, /[^ ]/) ? $4 : 0}')
LATEST_PATCH=$(echo "${LATEST_WHM_VER}" | awk -F"." '{print match($4, /[^ ]/) ? $4 : 0}')
if [ "${CURR_PATCH}" -lt "${LATEST_PATCH}" ] ; then
return 0
elif [ "${CURR_PATCH}" -gt "${LATEST_PATCH}" ] ; then
return 1
fi
return 1
}
echo ""
echo " Install LiteSpeed Web Server Plugin for WHM"
echo "=============================================="
echo ""
CURR_WHM_VER_FILE="${WHM_PLUGIN_INSDIR}/VERSION"
if [ -e "${CURR_WHM_VER_FILE}" ] ; then
CURR_WHM_VER=$(cat "${CURR_WHM_VER_FILE}")
if ! whmPluginNeedsUpdate "${CURR_WHM_VER}" ; then
echo "Installed WHM Plugin version already up-to-date. Abort!"
exit;
fi
fi
if [ "x${1}" = "x" ] ; then
echo "... creating directories ..."
# Create temp directory to install
if [ ! -e "${WHM_PLUGIN_TEMPDIR}" ] ; then
mkdir -v -p "${WHM_PLUGIN_TEMPDIR}"
echo " Temp directory created"
fi
cd "${WHM_PLUGIN_TEMPDIR}"
echo "... downloading latest version of the plugin ..."
if ! wget \
"--output-document=${WHM_PLUGIN_TEMPDIR}/lsws_whm_plugin.tar.gz" \
"${WHM_PLUGIN_HTTPDIR}/lsws_whm_plugin.tar.gz"
then
/bin/rm -rf "${WHM_PLUGIN_TEMPDIR}"
echo ""
echo "Failed to download lsws_whm_plugin.tar.gz. Abort!"
exit;
fi
echo "Done downloading."
echo ""
echo "... extracting ..."
if ! tar -zxf lsws_whm_plugin.tar.gz; then
/bin/rm -rf "${WHM_PLUGIN_TEMPDIR}"
echo ""
echo "Failed to to extract lsws_whm_plugin.tar.gz. Abort!"
exit;
fi
echo ""
fi
# Create working directories for WHM PHP files and backup any existing data
if [ -e "${WHM_PLUGIN_INSDIR}" ] ; then
if [ -e "${WHM_PLUGIN_CGIDIR}/addon_lsws.cgi" ] ; then
echo " Removing old entry script addon_lsws.cgi"
/bin/rm -f "${WHM_PLUGIN_CGIDIR}/addon_lsws.cgi"
fi
if [ ! -e "${WEBCACHE_MGR_DATA_DIR}" ] ; then
if [ -e "${LSWS_HOME}/admin" ] ; then
mkdir "${WEBCACHE_MGR_DATA_DIR}"
fi
fi
if [ -e "${CPANEL_PLUGIN_AUTOINSTALL_DISABLE_FLAG}" ] ; then
/bin/mv "${CPANEL_PLUGIN_AUTOINSTALL_DISABLE_FLAG}" "${TMP_CPANEL_PLUGIN_AUTOINSTALL_DISABLE_FLAG}"
fi
if [ -e "${WHM_PLUGIN_DATA_DIR}" ] ; then
/bin/mv "${WHM_PLUGIN_DATA_DIR}" "${TMP_WHM_PLUGIN_DATA_DIR}"
fi
if [ -e "${WHM_PLUGIN_LSWS_HOME_FILE}" ] ; then
/bin/mv "${WHM_PLUGIN_LSWS_HOME_FILE}" "${TMP_WHM_PLUGIN_LSWS_HOME_FILE}"
fi
echo " Removing old working directory ${WHM_PLUGIN_INSDIR}"
/bin/rm -rf "${WHM_PLUGIN_INSDIR}"
fi
if [ -e "${WHM_PLUGIN_TMPL_INSDIR}" ] ; then
echo " Removing old template directory ${WHM_PLUGIN_TMPL_INSDIR}"
/bin/rm -rf "${WHM_PLUGIN_TMPL_INSDIR}"
fi
#Cleanup old lsc data from installs < 2.1.12
if [ -e "${LSWS_HOME}/add-ons/webcachemgr/shared/lsc_versions_data" ] ; then
/bin/rm -f "${LSWS_HOME}/add-ons/webcachemgr/shared/lsc_versions_data"
fi
if [ -e "${LSWS_HOME}/add-ons/webcachemgr/shared/lsc_manager_data" ] ; then
/bin/rm -f "${LSWS_HOME}/add-ons/webcachemgr/shared/lsc_manager_data"
fi
#cleanup old lsc data/files from installs < 3.0.0
if [ -e "${WEBCACHE_MGR_DATA_DIR}/lsc_manager_data" ] ; then
/bin/rm -f "${WEBCACHE_MGR_DATA_DIR}/lsc_manager_data"
fi
if [ -e "${WEBCACHE_MGR_DATA_DIR}/lsc_versions_data" ] ; then
/bin/rm -f "${WEBCACHE_MGR_DATA_DIR}/lsc_versions_data"
fi
#force new data files permissions
if [ -e "${WEBCACHE_MGR_DATA_DIR}/lscm.data" ] ; then
chmod 600 "${WEBCACHE_MGR_DATA_DIR}/lscm.data"
fi
if [ -e "${WEBCACHE_MGR_DATA_DIR}/lscm.data.cust" ] ; then
chmod 600 "${WEBCACHE_MGR_DATA_DIR}/lscm.data.cust"
fi
mkdir -v "${WHM_PLUGIN_INSDIR}"
mkdir -v "${WHM_PLUGIN_TMPL_INSDIR}"
if [ -e "${TMP_CPANEL_PLUGIN_AUTOINSTALL_DISABLE_FLAG}" ] ; then
/bin/mv "${TMP_CPANEL_PLUGIN_AUTOINSTALL_DISABLE_FLAG}" "${CPANEL_PLUGIN_AUTOINSTALL_DISABLE_FLAG}"
echo " Retained disable cPanel plugin auto install flag file"
fi
if [ -e "${TMP_WHM_PLUGIN_DATA_DIR}" ] ; then
/bin/mv "${TMP_WHM_PLUGIN_DATA_DIR}" "${WHM_PLUGIN_DATA_DIR}"
echo " Retained WHM plugin data dir files"
fi
if [ -e "${TMP_WHM_PLUGIN_LSWS_HOME_FILE}" ] ; then
/bin/mv "${TMP_WHM_PLUGIN_LSWS_HOME_FILE}" "${WHM_PLUGIN_LSWS_HOME_FILE}"
echo " Retained LSWS_HOME.config file"
fi
echo ""
if [ "x${1}" = "x" ] ; then
WHM_PLUGIN_SRCDIR="${WHM_PLUGIN_TEMPDIR}/lsws_whm_plugin"
/bin/cp -r "${WHM_PLUGIN_SRCDIR}"/* "${WHM_PLUGIN_INSDIR}/"
cd "${WHM_PLUGIN_INSDIR}"
# # Removes install files
/bin/rm -rf "${WHM_PLUGIN_TEMPDIR}"
else
# install from lsws addon
WHM_PLUGIN_SRCDIR="${1}"
/bin/cp -r "${WHM_PLUGIN_SRCDIR}"/* "${WHM_PLUGIN_INSDIR}/"
echo "LSWS_HOME=${LSWS_HOME}" > "${WHM_PLUGIN_LSWS_HOME_FILE}"
fi
echo "... moving files ..."
if [ ! -e "${WHM_PLUGIN_ICONDIR}" ] ; then
mkdir -v "${WHM_PLUGIN_ICONDIR}"
fi
/bin/cp -f "${WHM_PLUGIN_INSDIR}/lsws_icon.png" "${WHM_PLUGIN_ICONDIR}/"
/bin/mv -f "${WHM_PLUGIN_INSDIR}/lsws.html.tt" "${WHM_PLUGIN_TMPL_INSDIR}/"
echo "... setting permission to files ..."
chmod -R 600 "${WHM_PLUGIN_INSDIR}"
chmod 700 "${WHM_PLUGIN_INSDIR}"/*.cgi
chmod 700 "${WHM_PLUGIN_INSDIR}"/*.sh
chmod 700 "${WHM_PLUGIN_INSDIR}/bin"
chmod 700 "${WHM_PLUGIN_INSDIR}"/bin/*.sh
if [ -e "${WHM_PLUGIN_INSDIR}/res/ls_web_cache_mgr" ] ; then
chmod 700 "${WHM_PLUGIN_INSDIR}"/res/ls_web_cache_mgr/*.sh
CPANEL_PLUGIN_CAPABLE=1;
fi
# update easyapache hooks
"${WHM_PLUGIN_INSDIR}/bin/whm_eahook.sh" REFRESH
sed -i 's/target=mainFrame/target=_self/' "${WHM_PLUGIN_INSDIR}/lsws.conf"
if [ -e "/usr/local/cpanel/bin/register_appconfig" ] ; then
REGISTERED=$(/usr/local/cpanel/bin/is_registered_with_appconfig whostmgr lsws)
if [ "x${REGISTERED}" != "x1" ] ; then
echo "Register LSWS Plugin ..."
if [ ! -e "/var/cpanel/apps" ] ; then
mkdir -v "/var/cpanel/apps"
echo " apps registration directory created"
fi
else
# check if config changed
CHANGED=$(diff /var/cpanel/apps/lsws.conf "${WHM_PLUGIN_INSDIR}/lsws.conf")
if [ "${CHANGED}" != "" ] ; then
REGISTERED=0
fi
fi
if [ "x${REGISTERED}" != "x1" ] ; then
/usr/local/cpanel/bin/register_appconfig "${WHM_PLUGIN_INSDIR}/lsws.conf"
fi
/bin/rm -f "${WHM_PLUGIN_INSDIR}/addon_lsws.cgi"
else
echo "old version no AppConfig, place entry at parent dir"
/bin/mv -f "${WHM_PLUGIN_INSDIR}/addon_lsws.cgi" "${WHM_PLUGIN_CGIDIR}/"
/bin/rm -f "${WHM_PLUGIN_INSDIR}/lsws.cgi"
fi
#Create and add needed LSCWP source directory
if [ ! -e "${WHM_PLUGIN_LSCWP_SRC_DIR}" ] ; then
mkdir -m 755 "${WHM_PLUGIN_LSCWP_SRC_DIR}"
fi
#CageFs remount for $WHM_PLUGIN_LSCWP_SRC_DIR handled in fix_cagefs.sh
if [ -f "/etc/cagefs/cagefs.mp" ] ; then
FORCE_REMOUNT=0
if ! grep -v 'deleted' /proc/mounts | grep -q 'litespeed-wp-plugin' ; then
FORCE_REMOUNT=1
if ! grep -Eq "^${WHM_PLUGIN_LSCWP_SRC_DIR}$" /etc/cagefs/cagefs.mp; then
# shellcheck disable=SC1003
sed -i -e '$a\' /etc/cagefs/cagefs.mp
echo "${WHM_PLUGIN_LSCWP_SRC_DIR}" >> /etc/cagefs/cagefs.mp
fi
fi
THIS_DIR=$( cd "$( dirname "${0}" )" && pwd )
if [ -f "${LSWS_HOME}/admin/misc/fix_cagefs.sh" ] ; then
#If CageFS, add LSWS to cage if missing.
"${LSWS_HOME}/admin/misc/fix_cagefs.sh" "${FORCE_REMOUNT}"
elif [ -f "${THIS_DIR}/../../../admin/misc/fix_cagefs.sh" ] ; then
#LSWS not installed yet, run package relative script.
"${THIS_DIR}/../../../admin/misc/fix_cagefs.sh" "${FORCE_REMOUNT}"
else
echo "Could not find fix_cagefs.sh! Script was not executed."
fi
fi
#Exclude LSCache files from backup
CP_BACKUP_EXCLUDE_MASTER=/usr/local/cpanel/etc/cpbackup-exclude.conf
CP_BACKUP_EXCLUDE_GLOBAL=/etc/cpbackup-exclude.conf
if [ ! -f "${CP_BACKUP_EXCLUDE_GLOBAL}" ] && [ -f "${CP_BACKUP_EXCLUDE_MASTER}" ] ; then
cp "${CP_BACKUP_EXCLUDE_MASTER}" "${CP_BACKUP_EXCLUDE_GLOBAL}"
fi
if [ -f "${CP_BACKUP_EXCLUDE_GLOBAL}" ] ; then
grep -Fxq "lscache/" "${CP_BACKUP_EXCLUDE_GLOBAL}"
FOUND="${?}"
fi
if [ ! -f "${CP_BACKUP_EXCLUDE_GLOBAL}" ] || [ "${FOUND}" -ne 0 ] ; then
echo "lscache/" >> "${CP_BACKUP_EXCLUDE_GLOBAL}"
fi
##
# Install/Update cPanel Plugin if found
##
if [ "${CPANEL_PLUGIN_CAPABLE}" -eq 1 ] ; then
CPANEL_PLUGIN_AUTOINSTALL=1
if [ "x${3}" = "x" ] ; then
if [ -e "${CPANEL_PLUGIN_AUTOINSTALL_DISABLE_FLAG}" ] ; then
CPANEL_PLUGIN_AUTOINSTALL=0
fi
else
CPANEL_PLUGIN_AUTOINSTALL="${3}"
if [ "${CPANEL_PLUGIN_AUTOINSTALL}" -eq 1 ] ; then
if [ -e "${CPANEL_PLUGIN_AUTOINSTALL_DISABLE_FLAG}" ] ; then
/bin/rm -f "${CPANEL_PLUGIN_AUTOINSTALL_DISABLE_FLAG}"
fi
else
touch "${CPANEL_PLUGIN_AUTOINSTALL_DISABLE_FLAG}"
fi
fi
LSCMCTL_SCRIPT="${LSWS_HOME}/admin/misc/lscmctl"
if [ -e "${LSCMCTL_SCRIPT}" ] ; then
if "${LSCMCTL_SCRIPT}" --help | grep -q 'cpanelplugin' \
&& [ "${CPANEL_PLUGIN_AUTOINSTALL}" -eq 1 ] \
|| [ -e "${THEME_JUPITER_PLUGIN_DIR}" ] \
|| [ -e "${THEME_PAPER_LANTERN_PLUGIN_DIR}" ]
then
"${LSCMCTL_SCRIPT}" cpanelplugin --install
fi
fi
fi
echo ""
echo " LiteSpeed WHM Plugin Installed Successfully."
echo "=============================================="