-
-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathenginescript-update.sh
More file actions
216 lines (183 loc) · 9.54 KB
/
Copy pathenginescript-update.sh
File metadata and controls
216 lines (183 loc) · 9.54 KB
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
#!/usr/bin/env bash
#----------------------------------------------------------------------------------
# EngineScript - A High-Performance WordPress Server Built on Ubuntu and Cloudflare
#----------------------------------------------------------------------------------
# Website: https://EngineScript.com
# GitHub: https://github.com/Enginescript/EngineScript
# License: GPL v3.0
#----------------------------------------------------------------------------------
# EngineScript Variables
source /usr/local/bin/enginescript/enginescript-variables.txt || { echo "Error: Failed to source /usr/local/bin/enginescript/enginescript-variables.txt" >&2; exit 1; }
source /home/EngineScript/enginescript-install-options.txt || { echo "Error: Failed to source /home/EngineScript/enginescript-install-options.txt" >&2; exit 1; }
# Source shared functions library
source /usr/local/bin/enginescript/scripts/functions/shared/enginescript-common.sh || { echo "Error: Failed to source /usr/local/bin/enginescript/scripts/functions/shared/enginescript-common.sh" >&2; exit 1; }
#----------------------------------------------------------------------------------
# Start Main Script
# Return to /usr/src
return_to_src
# --------------------------------------------------------
# Update EngineScript
# Determine which branch to use based on TEST_MODE setting
if [[ "${TEST_MODE}" == "1" ]]; then
ENGINESCRIPT_BRANCH="update-software-versions"
echo "TEST_MODE enabled: Updating from development branch (update-software-versions)"
else
ENGINESCRIPT_BRANCH="master"
echo "Updating from production branch (master)"
fi
# Copy EngineScript
cd /usr/local/bin/enginescript
echo "Fetching ${ENGINESCRIPT_BRANCH} branch..."
git fetch origin "${ENGINESCRIPT_BRANCH}" 2>> /tmp/enginescript_install_errors.log
git checkout -f "${ENGINESCRIPT_BRANCH}" 2>> /tmp/enginescript_install_errors.log
git reset --hard FETCH_HEAD 2>> /tmp/enginescript_install_errors.log
print_last_errors
debug_pause "EngineScript Git Pull"
# Convert line endings
dos2unix /usr/local/bin/enginescript/*
# Set directory and file permissions to 755
find /usr/local/bin/enginescript \( -type d -o -type f \) -exec chmod 755 {} \;
# Set ownership
chown -R root:root /usr/local/bin/enginescript
# Make shell scripts executable
find /usr/local/bin/enginescript -type f -iname "*.sh" -exec chmod +x {} \;
echo ""
echo ""
echo "============================================================="
echo ""
echo "${BOLD}EngineScript has been updated${NORMAL}"
echo ""
echo "============================================================="
echo ""
echo ""
# --------------------------------------------------------
# Check Installation Completion Status
verify_installation_completion "EngineScript Update"
echo "============================================================="
echo "Installation Verification Complete - Proceeding with Updates"
echo "============================================================="
echo ""
# --------------------------------------------------------
# Updating files from previous versions
/usr/local/bin/enginescript/scripts/functions/auto-upgrade/normal-auto-upgrade.sh 2>> /tmp/enginescript_install_errors.log
/usr/local/bin/enginescript/scripts/functions/auto-upgrade/emergency-auto-upgrade.sh 2>> /tmp/enginescript_install_errors.log
print_last_errors
debug_pause "Auto-Upgrades"
# --------------------------------------------------------
# Update EngineScript Frontend
# Safety Check: Verify we're only wiping the control-panel directory
# This prevents accidental deletion of admin tools (phpMyAdmin, etc.)
CONTROL_PANEL_DIR="/var/www/admin/control-panel"
TOOLS_DIR="/var/www/admin/tools"
# Verify tools directory exists and is not empty (contains user configurations)
if [[ -d "$TOOLS_DIR" ]]; then
TOOLS_COUNT=$(find "$TOOLS_DIR" -mindepth 1 -maxdepth 1 -type d 2>/dev/null | wc -l)
if [[ "$TOOLS_COUNT" -gt 0 ]]; then
echo "✓ Admin tools directory verified: $TOOLS_COUNT tool(s) found in $TOOLS_DIR"
echo " Tools will NOT be affected by this update."
fi
else
echo "ℹ Admin tools directory not found. Creating..."
mkdir -p "$TOOLS_DIR"
fi
# Admin Control Panel - Remove old files and replace with new version
# NOTE: Only the control-panel directory is wiped on updates.
# Admin tools (phpMyAdmin, TinyFileManager, phpSysInfo, Adminer, phpinfo)
# are stored in /var/www/admin/tools/ and are NOT affected by updates.
echo "Cleaning up old Admin Control Panel files..."
# Safety: Double-check we're targeting the correct directory
if [[ "$CONTROL_PANEL_DIR" == "/var/www/admin/control-panel" ]]; then
rm -rf "${CONTROL_PANEL_DIR:?}"/*
else
echo "ERROR: Control panel directory path mismatch. Aborting for safety."
exit 1
fi
/usr/local/bin/enginescript/scripts/install/tools/frontend/admin-control-panel-install.sh 2>> /tmp/enginescript_install_errors.log
print_last_errors
debug_pause "Admin Control Panel Update"
# Update configuration files from main credentials file
echo "Updating configuration files with user credentials..."
/usr/local/bin/enginescript/scripts/functions/shared/update-config-files.sh 2>> /tmp/enginescript_install_errors.log
print_last_errors
debug_pause "Config Files Update"
# Set permissions for EngineScript frontend directories
set_enginescript_frontend_permissions
# ---------------------------------------------------------
# Update EngineScript plugins
# Update both EngineScript plugins for each site in sites.sh
SITES_FILE="/home/EngineScript/sites-list/sites.sh"
if [[ -f "$SITES_FILE" ]]; then
# shellcheck source=/home/EngineScript/sites-list/sites.sh
source "$SITES_FILE"
for SITE in "${SITES[@]}"; do
# Remove quotes from domain name if present
DOMAIN=$(echo "$SITE" | tr -d '"')
WP_PLUGIN_DIR="/var/www/sites/${DOMAIN}/html/wp-content/plugins"
if [[ -d "$WP_PLUGIN_DIR" ]]; then
# Only update EngineScript custom plugins if the option is enabled
if [[ "${INSTALL_ENGINESCRIPT_PLUGINS}" == "1" ]]; then
# Update the two custom EngineScript plugins:
# 1. EngineScript Site Exporter plugin
echo "Updating EngineScript Site Exporter plugin for $DOMAIN..."
mkdir -p "/tmp/es-se-plugin-update"
if wget -q "https://github.com/EngineScript/enginescript-site-exporter/releases/download/v${ES_SE_PLUGIN_VER}/enginescript-site-exporter-${ES_SE_PLUGIN_VER}.zip" -O "/tmp/es-se-plugin-update/enginescript-site-exporter-${ES_SE_PLUGIN_VER}.zip" 2>/dev/null; then
# Verify the downloaded file is a valid zip
if unzip -t "/tmp/es-se-plugin-update/enginescript-site-exporter-${ES_SE_PLUGIN_VER}.zip" >/dev/null 2>&1; then
unzip -q -o "/tmp/es-se-plugin-update/enginescript-site-exporter-${ES_SE_PLUGIN_VER}.zip" -d "$WP_PLUGIN_DIR/"
echo "EngineScript Site Exporter plugin updated successfully for $DOMAIN"
else
echo "Warning: Downloaded EngineScript Site Exporter plugin file is corrupted for $DOMAIN"
fi
else
echo "Warning: Failed to download EngineScript Site Exporter plugin for $DOMAIN"
fi
rm -rf "/tmp/es-se-plugin-update"
# 2. EngineScript Site Optimizer plugin
echo "Updating EngineScript Site Optimizer plugin for $DOMAIN..."
mkdir -p "/tmp/es-so-plugin-update"
if wget -q "https://github.com/EngineScript/enginescript-site-optimizer/releases/download/v${ES_SO_PLUGIN_VER}/enginescript-site-optimizer-${ES_SO_PLUGIN_VER}.zip" -O "/tmp/es-so-plugin-update/enginescript-site-optimizer-${ES_SO_PLUGIN_VER}.zip" 2>/dev/null; then
# Verify the downloaded file is a valid zip
if unzip -t "/tmp/es-so-plugin-update/enginescript-site-optimizer-${ES_SO_PLUGIN_VER}.zip" >/dev/null 2>&1; then
unzip -q -o "/tmp/es-so-plugin-update/enginescript-site-optimizer-${ES_SO_PLUGIN_VER}.zip" -d "$WP_PLUGIN_DIR/"
echo "EngineScript Site Optimizer plugin updated successfully for $DOMAIN"
else
echo "Warning: Downloaded EngineScript Site Optimizer plugin file is corrupted for $DOMAIN"
fi
else
echo "Warning: Failed to download EngineScript Site Optimizer plugin for $DOMAIN"
fi
rm -rf "/tmp/es-so-plugin-update"
# Set permissions for both plugins (only if they exist)
if [[ -d "$WP_PLUGIN_DIR/enginescript-site-exporter" ]]; then
chown -R www-data:www-data "$WP_PLUGIN_DIR/enginescript-site-exporter"
find "$WP_PLUGIN_DIR/enginescript-site-exporter" -type d -exec chmod 755 {} \;
find "$WP_PLUGIN_DIR/enginescript-site-exporter" -type f -exec chmod 644 {} \;
fi
if [[ -d "$WP_PLUGIN_DIR/enginescript-site-optimizer" ]]; then
chown -R www-data:www-data "$WP_PLUGIN_DIR/enginescript-site-optimizer"
find "$WP_PLUGIN_DIR/enginescript-site-optimizer" -type d -exec chmod 755 {} \;
find "$WP_PLUGIN_DIR/enginescript-site-optimizer" -type f -exec chmod 644 {} \;
fi
else
echo "Skipping EngineScript custom plugins update for $DOMAIN (disabled in config)..."
fi
else
echo "Warning: Plugin directory $WP_PLUGIN_DIR does not exist for site $DOMAIN"
fi
done
else
echo "Warning: SITES file $SITES_FILE not found. Skipping plugin updates for sites."
fi
print_last_errors
debug_pause "EngineScript Plugins Update"
echo ""
echo ""
echo "============================================================="
echo ""
echo "${BOLD}EngineScript has been updated${NORMAL}"
echo ""
echo "Branch: ${ENGINESCRIPT_BRANCH}"
echo ""
echo "============================================================="
echo ""
echo ""