-
-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathsetup.sh
More file actions
243 lines (197 loc) · 8.11 KB
/
setup.sh
File metadata and controls
243 lines (197 loc) · 8.11 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
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
#!/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
# Company: VisiStruct / EngineScript
# License: GPL v3.0
#----------------------------------------------------------------------------
# Check current user's ID. If user is not 0 (root), exit.
if [[ "${EUID}" != 0 ]];
then
echo "ALERT:"
echo "EngineScript should be executed as the root user."
exit 1
fi
# Check if the server is running on a 64-bit environment. If not, exit.
BIT_TYPE=$(uname -m)
if [[ "${BIT_TYPE}" != 'x86_64' ]];
then
echo "EngineScript requires a 64-bit environment to run optimally."
exit 1
fi
# Check if the server is running Ubuntu
LINUX_TYPE=$(lsb_release -i | cut -d':' -f 2 | tr -d '[:space:]')
if [[ "$LINUX_TYPE" != "Ubuntu" ]]; then
echo "EngineScript does not support $LINUX_TYPE. Please use Ubuntu 24.04"
exit 1
else
echo "Detected Linux Type: $LINUX_TYPE"
fi
# Check if Ubuntu is 24.04 LTS Release. If not, exit.
UBUNTU_VERSION="$(lsb_release -sr)"
Noble=24.04
if (( $(bc <<<"$UBUNTU_VERSION != $Noble") )); then
echo "ALERT:"
echo "EngineScript does not support Ubuntu $UBUNTU_VERSION. We recommend using Ubuntu 24.04 LTS"
exit 1
else
echo "Current Ubuntu Version: $UBUNTU_VERSION"
fi
#----------------------------------------------------------------------------
# Start Main Script
# Install Required Packages for Script
apt update --allow-releaseinfo-change -y
core_packages="apt bash boxes cron coreutils curl dos2unix git gzip nano needrestart openssl pwgen sed software-properties-common tar tzdata unattended-upgrades unzip zip"
apt install -qy $core_packages || {
echo "Error: Unable to install one or more packages. Exiting..."
exit 1
}
# Check for required commands
required_commands=("apt" "boxes" "dos2unix" "git" "nano" "wget")
for cmd in "${required_commands[@]}"; do
if ! command -v $cmd &> /dev/null; then
echo "Error: $cmd is not installed. Please install it and try again."
exit 1
fi
done
# Configure needrestart if available
if [[ -f "/etc/needrestart/needrestart.conf" ]]; then
sed -i "s/#\$nrconf{restart} = 'i';/\$nrconf{restart} = 'a';/" /etc/needrestart/needrestart.conf
fi
# Upgrade Software
apt upgrade -y
# Return to /usr/src
cd /usr/src
# Remove existing EngineScript directory if it exists
if [[ -d "/usr/local/bin/enginescript" ]]; then
rm -rf /usr/local/bin/enginescript
fi
# EngineScript Git Clone (full clone to allow branch switching)
git clone https://github.com/EngineScript/EngineScript.git -b master /usr/local/bin/enginescript
# Convert line endings
dos2unix /usr/local/bin/enginescript/*
# Set directory and file permissions to 755
find /usr/local/bin/enginescript -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 {} \;
# Source shared functions now that EngineScript is cloned and ready.
source /usr/local/bin/enginescript/scripts/functions/shared/enginescript-common.sh || {
echo "Error: Failed to source shared functions from /usr/local/bin/enginescript/scripts/functions/shared/enginescript-common.sh"
exit 1
}
# Pre-install resource checks so setup fails early on unsupported/misreported systems.
require_basic_system_resources "MEMORY_TOTAL_MB" "CPU_COUNT"
echo "Detected total memory: ${MEMORY_TOTAL_MB} MB"
echo "Detected CPU count: ${CPU_COUNT}"
# Create EngineScript Home Directory
mkdir -p "/home/EngineScript/config-backups/nginx"
mkdir -p "/home/EngineScript/config-backups/php"
mkdir -p "/home/EngineScript/mysql-credentials"
mkdir -p "/home/EngineScript/site-backups"
mkdir -p "/home/EngineScript/sites-list"
mkdir -p "/home/EngineScript/temp/site-export"
mkdir -p "/home/EngineScript/temp/site-import-completed-backups"
mkdir -p "/home/EngineScript/temp/site-import/database-file"
mkdir -p "/home/EngineScript/temp/site-import/root-directory"
# Create /etc/enginescript directory if it doesn't exist
if [[ ! -d "/etc/enginescript" ]]; then
echo "Creating EngineScript configuration directory..."
mkdir -p "/etc/enginescript"
echo "✓ EngineScript configuration directory created"
fi
# Create /var/www/admin/control-panel/ if it doesn't exist
if [[ ! -d "/var/www/admin/control-panel/" ]]; then
echo "Creating EngineScript admin control panel directory..."
mkdir -p "/var/www/admin/control-panel"
echo "✓ EngineScript admin control panel directory created"
fi
# Create /var/www/admin/tools/ if it doesn't exist
if [[ ! -d "/var/www/admin/tools/" ]]; then
echo "Creating EngineScript admin tools directory..."
mkdir -p "/var/www/admin/tools"
echo "✓ EngineScript admin tools directory created"
fi
# Create /var/cache/enginescript/api if it doesn't exist
if [[ ! -d "/var/cache/enginescript/api" ]]; then
echo "Creating EngineScript dashboard API cache directory..."
mkdir -p "/var/cache/enginescript/api"
echo "✓ EngineScript dashboard API cache directory created"
fi
# Ensure correct ownership and permissions for the API cache directory
if [[ -d "/var/cache/enginescript/api" ]]; then
chown -R www-data:www-data /var/cache/enginescript/api
chmod -R 775 /var/cache/enginescript/api
fi
# EngineScript Logs
# Create EngineScript logs
mkdir -p "/var/log/EngineScript"
touch "/var/log/EngineScript/install-error-log.log"
touch "/var/log/EngineScript/install-log.log"
touch "/var/log/EngineScript/vhost-export.log"
touch "/var/log/EngineScript/vhost-import.log"
touch "/var/log/EngineScript/vhost-install.log"
touch "/var/log/EngineScript/vhost-remove.log"
touch "/var/log/EngineScript/enginescript-api.log"
touch "/var/log/EngineScript/enginescript-api-security.log"
# Set proper permissions for EngineScript logs
chown -R www-data:www-data "/var/log/EngineScript"
chmod -R 644 "/var/log/EngineScript"/*.log
# Logrotate - EngineScript Logs (DISABLED - preserves install logs)
# cp -rf "/usr/local/bin/enginescript/config/etc/logrotate.d/enginescript" "/etc/logrotate.d/enginescript"
# find /etc/logrotate.d -type f -print0 | sudo xargs -0 chmod 0644
# Return to /usr/src
cd "/usr/src"
# Create EngineScript Aliases
source "/var/log/EngineScript/install-log.log"
if [[ "${ALIAS}" = 1 ]];
then
echo "ALIAS script has already run"
else
/usr/local/bin/enginescript/scripts/install/alias/enginescript-alias-install.sh
echo "ALIAS=1" >> /var/log/EngineScript/install-log.log
fi
# Cleanup
apt-get remove apache2* php7* php8* -y
# Update & Upgrade
apt update --allow-releaseinfo-change -y
apt upgrade -y
# Set Time Zone
dpkg-reconfigure tzdata
# Set Unattended Upgrades
dpkg-reconfigure unattended-upgrades
# Set MOTD
cp -rf /usr/local/bin/enginescript/config/etc/update-motd.d/99-enginescript /etc/update-motd.d/99-enginescript
chmod +x /etc/update-motd.d/99-enginescript
chown root:root /etc/update-motd.d/99-enginescript
dos2unix /etc/update-motd.d/99-enginescript
# Test MOTD
run-parts --test /etc/update-motd.d/
run-parts /etc/update-motd.d/
# HWE
apt install --install-recommends linux-generic-hwe-${UBUNTU_VERSION} -y
# Update & Upgrade
apt update --allow-releaseinfo-change -y
apt upgrade -y
# Remove old downloads
rm -rf /usr/src/*.tar.gz*
# Remove old packages
apt clean -y
apt autoremove --purge -y
apt autoclean -y
if [[ -f "/home/EngineScript/enginescript-install-options.txt" ]]; then
clear
echo -e "\n\nInitial setup is complete.\n\nProceed to: Step 2 - Edit Options File\n\nhttps://github.com/EngineScript/EngineScript#step-2---edit-options-file\n\n"
else
cp -rf /usr/local/bin/enginescript/config/home/enginescript-install-options.txt /home/EngineScript/enginescript-install-options.txt
clear
echo -e "\n\nInitial setup is complete.\n\nProceed to: Step 2 - Edit Options File\n\nhttps://github.com/EngineScript/EngineScript#step-2---edit-options-file\n\n"
fi
echo -e "Server needs to restart" | boxes -a c -d shell -p a1l2
echo "Server will restart in 10 seconds"
sleep 10
echo "Restarting..."
shutdown -r now