Skip to content

Commit 220bb36

Browse files
authored
Updates
1 parent 9191f4e commit 220bb36

39 files changed

Lines changed: 217 additions & 157 deletions

CHANGELOG.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,20 @@ Changes are organized by date, with the most recent changes listed first.
77
## 2025-07-01
88

99
### 🔧 CODE QUALITY
10+
- **Shared Functions Library Integration**: Expanded usage of `scripts/functions/shared/enginescript-common.sh` across the entire codebase
11+
- Added shared library sourcing to all vhost scripts (`vhost-install.sh`, `vhost-import.sh`, `vhost-remove.sh`)
12+
- Added shared library sourcing to installation scripts (`php-install.sh`, `redis-install.sh`, `nginx-cloudflare-ip-updater.sh`)
13+
- Added shared library sourcing to update scripts (`nginx-update.sh`, `mariadb-update.sh`)
14+
- Replaced direct `service restart` commands with `restart_service()` function calls for consistency
15+
- Enhanced `nginx-update.sh` with comprehensive error logging and debug pauses using shared functions
16+
- Fixed remaining conditional expressions (`[ ]``[[ ]]`) in `vhost-import.sh` for consistency
17+
- All scripts now use consistent error handling, service management, and debugging patterns
18+
- **Conditional Expression Standardization**: Replaced all `[ ]` (test) conditional expressions with `[[ ]]` (keyword) throughout the entire codebase
19+
- Updated all installation scripts (enginescript-install.sh, nginx-install.sh, php-install.sh, mariadb-install.sh, redis-install.sh, gcc-install.sh, etc.)
20+
- Updated all function scripts (backup scripts, cron scripts, vhost scripts, security scripts, alias scripts, etc.)
21+
- Updated all utility and tool installation scripts (ufw-cloudflare.sh, zlib-install.sh, tools-install.sh, etc.)
22+
- Modernizes shell scripting practices and improves readability and maintainability
23+
- `[[ ]]` provides better string handling, pattern matching, and is less error-prone than `[ ]`
1024
- **Shell Scripts**: Standardized shebang line in `scripts/functions/alias/alias-debug.sh` to use `#!/usr/bin/env bash` for consistency across all shell scripts
1125
- **Function Deduplication**: Created shared functions library at `scripts/functions/shared/enginescript-common.sh` to consolidate duplicated functions
1226
- Consolidated `debug_pause()` and `print_last_errors()` functions from `scripts/install/enginescript-install.sh` and `scripts/install/nginx/nginx-install.sh`

scripts/functions/alias/alias-debug.sh

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -299,7 +299,7 @@ debug_print "|---------|---------|" "|---------|---------|"
299299
services=("nginx" "php8.3-fpm" "mariadb" "redis-server")
300300
for service in "${services[@]}"; do
301301
status=$(systemctl is-active "$service")
302-
if [ "$status" = "active" ]; then
302+
if [[ "$status" == "active" ]]; then
303303
debug_print "${service} | ${GREEN}${status}${NORMAL}" "| ${service} | 🟢 \`${status}\` |"
304304
else
305305
debug_print "${service} | ${YELLOW}${status}${NORMAL}" "| ${service} | 🟡 \`${status}\` |"
@@ -348,7 +348,7 @@ done < <(find /var/www/sites/*/html -maxdepth 0 -type d 2>/dev/null)
348348
debug_print "\n\n"
349349

350350
# Show sample headers from first domain
351-
if [ -n "$first_domain" ]; then
351+
if [[ -n "$first_domain" ]]; then
352352
debug_print "\n### Sample HTTP Headers\n" "\n### Sample HTTP Headers\n"
353353
debug_print "Below is a sample of HTTP headers from \`$first_domain\`. Other domains may have different configurations.\n" "Below is a sample of HTTP headers from \`$first_domain\`. Other domains may have different configurations.\n"
354354
debug_print "To check headers for other domains, use: \`curl -I https://domain.com\`\n" "To check headers for other domains, use: \`curl -I https://domain.com\`\n"
@@ -383,7 +383,7 @@ cat << 'EOF' >> "$DEBUG_FILE"
383383
EOF
384384

385385
# Append install error log if it exists
386-
if [ -f /var/log/EngineScript/install-error-log.txt ]; then
386+
if [[ -f /var/log/EngineScript/install-error-log.txt ]]; then
387387
echo -e "\n## EngineScript Install Error Log (Full Contents)\n" >> "$DEBUG_FILE"
388388
cat /var/log/EngineScript/install-error-log.txt >> "$DEBUG_FILE"
389389
fi

scripts/functions/backup/daily-database-backup.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ do
5151
gzip -cf "/var/www/sites/$i/html/wp-config.php" > "/home/EngineScript/site-backups/$i/wp-config/daily/${NOW}/${WPCONFIG_FILE}"
5252

5353
# Amazon S3 Database Backup
54-
if [ "$INSTALL_S3_BACKUP" = 1 ] && [ "$S3_BUCKET_NAME" != PLACEHOLDER ] && [ "$DAILY_S3_DATABASE_BACKUP" = 1 ];
54+
if [[ "$INSTALL_S3_BACKUP" == "1" ]] && [[ "$S3_BUCKET_NAME" != "PLACEHOLDER" ]] && [[ "$DAILY_S3_DATABASE_BACKUP" == "1" ]];
5555
then
5656
echo "Uploading Database Backup for ${i} to Amazon S3 Bucket"
5757
/usr/local/bin/aws s3 cp "/home/EngineScript/site-backups/$i/database/daily/${NOW}/${DATABASE_FILE}.gz" "s3://${S3_BUCKET_NAME}/$i/backups/database/daily/${NOW}/${DATABASE_FILE}.gz" --storage-class STANDARD

scripts/functions/backup/hourly-database-backup.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ do
4646
gzip -f "/home/EngineScript/site-backups/$i/database/hourly/${NOW}/${DATABASE_FILE}"
4747

4848
# Amazon S3 Database Backup
49-
if [ "$INSTALL_S3_BACKUP" = 1 ] && [ "$S3_BUCKET_NAME" != PLACEHOLDER ] && [ "$HOURLY_S3_DATABASE_BACKUP" = 1 ];
49+
if [[ "$INSTALL_S3_BACKUP" == "1" ]] && [[ "$S3_BUCKET_NAME" != "PLACEHOLDER" ]] && [[ "$HOURLY_S3_DATABASE_BACKUP" == "1" ]];
5050
then
5151
/usr/local/bin/aws s3 cp "/home/EngineScript/site-backups/$i/database/hourly/${NOW}/${DATABASE_FILE}.gz" "s3://${S3_BUCKET_NAME}/$i/backups/database/hourly/${NOW}/${DATABASE_FILE}.gz" --storage-class STANDARD
5252
fi

scripts/functions/backup/weekly-wp-content-backup.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ do
4444
tar -zcf "/home/EngineScript/site-backups/$i/wp-content/weekly/${WPCONTENT_FILE}" wp-content
4545

4646
# Amazon S3 WP-Content Backup
47-
if [ "$INSTALL_S3_BACKUP" = 1 ] && [ "$S3_BUCKET_NAME" != PLACEHOLDER ] && [ "$WEEKLY_S3_WPCONTENT_BACKUP" = 1 ];
47+
if [[ "$INSTALL_S3_BACKUP" == "1" ]] && [[ "$S3_BUCKET_NAME" != "PLACEHOLDER" ]] && [[ "$WEEKLY_S3_WPCONTENT_BACKUP" == "1" ]];
4848
then
4949
echo "Uploading WP-Content Backup for ${i} to Amazon S3 Bucket"
5050
/usr/local/bin/aws s3 cp "/home/EngineScript/site-backups/$i/wp-content/weekly/${WPCONTENT_FILE}" "s3://${S3_BUCKET_NAME}/$i/backups/wp-content/weekly/${WPCONTENT_FILE}" --storage-class STANDARD

scripts/functions/cron/checksums.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ done
3939
# Trim leading space if ERRORS is not empty
4040
ERRORS="${ERRORS##*( )}"
4141

42-
if [ -n "$ERRORS" ]; then
42+
if [[ -n "$ERRORS" ]]; then
4343
# Use multiple -d options for clarity and proper quoting
4444
curl -u "$PUSHBULLET_TOKEN": https://api.pushbullet.com/v2/pushes \
4545
-d type=note \

scripts/functions/cron/uploads-php-scan.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ do
3636
! -path './wp-migrate-db/*' \
3737
| wc -l)
3838

39-
if [ "$numFiles" -gt 0 ]; then
39+
if [[ "$numFiles" -gt 0 ]]; then
4040
ERRORS="$ERRORS $i"
4141
fi
4242

@@ -46,7 +46,7 @@ done
4646
# Trim leading space if ERRORS is not empty
4747
ERRORS="${ERRORS##*( )}"
4848

49-
if [ -n "$ERRORS" ]; then
49+
if [[ -n "$ERRORS" ]]; then
5050
# Use multiple -d options for clarity and proper quoting
5151
curl -u "$PUSHBULLET_TOKEN": https://api.pushbullet.com/v2/pushes \
5252
-d type=note \

scripts/functions/security/wpscan.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ select d in *; do test -n "$d" && break; echo ">>> Invalid Selection"; done
2222
echo "WPScan"
2323

2424
# Run WPScan
25-
if [ "${WPSCANAPI}" = PLACEHOLDER ]
25+
if [[ "${WPSCANAPI}" == "PLACEHOLDER" ]]
2626
then
2727
wpscan --url "$d"
2828
else

scripts/functions/vhost/vhost-export.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ else
3232
fi
3333

3434
# Check if SITES array is empty or unset
35-
if [ ${#SITES[@]} -eq 0 ]; then
35+
if [[ ${#SITES[@]} -eq 0 ]]; then
3636
echo "No sites found in ${SITES_LIST_FILE}. Cannot export."
3737
exit 1
3838
fi
@@ -73,7 +73,7 @@ FILES_EXPORT_PATH="${SITE_EXPORT_DIR}/${FILES_EXPORT_FILENAME}"
7373
# --- Create Export Directory ---
7474
echo "Creating export directory: ${SITE_EXPORT_DIR}"
7575
mkdir -p "${SITE_EXPORT_DIR}"
76-
if [ $? -ne 0 ]; then
76+
if [[ $? -ne 0 ]]; then
7777
echo "ERROR: Failed to create export directory ${SITE_EXPORT_DIR}"
7878
exit 1
7979
fi

scripts/functions/vhost/vhost-import.sh

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,14 @@
1111
source /usr/local/bin/enginescript/enginescript-variables.txt
1212
source /home/EngineScript/enginescript-install-options.txt
1313

14+
# Source shared functions library
15+
source /usr/local/bin/enginescript/scripts/functions/shared/enginescript-common.sh
1416

1517

18+
19+
#----------------------------------------------------------------------------------
20+
# Start Main Script
21+
1622
# --- Define Fixed Import Paths (Needed for instructions) ---
1723
IMPORT_BASE_DIR="/home/EngineScript/temp/site-import"
1824
# Directories for the original two-file method (keep variable names consistent)
@@ -55,16 +61,12 @@ echo "---------------------------------------------------------------------"
5561
read -p "Press [Enter] to continue once the file(s) are prepared..."
5662
# --- End Instructions ---
5763

58-
59-
#----------------------------------------------------------------------------------
60-
# Start Main Script
61-
6264
# Check if services are running
6365
echo -e "\n\n${BOLD}Running Services Check:${NORMAL}\n"
6466

6567
# MariaDB Service Check
6668
STATUS="$(systemctl is-active mariadb)"
67-
if [ "${STATUS}" = "active" ]; then
69+
if [[ "${STATUS}" == "active" ]]; then
6870
echo "PASSED: MariaDB is running."
6971
else
7072
echo "FAILED: MariaDB not running. Please diagnose this issue before proceeding."
@@ -73,7 +75,7 @@ fi
7375

7476
# Nginx Service Check
7577
STATUS="$(systemctl is-active nginx)"
76-
if [ "${STATUS}" = "active" ]; then
78+
if [[ "${STATUS}" == "active" ]]; then
7779
echo "PASSED: Nginx is running."
7880
else
7981
echo "FAILED: Nginx not running. Please diagnose this issue before proceeding."
@@ -82,7 +84,7 @@ fi
8284

8385
# PHP Service Check
8486
STATUS="$(systemctl is-active "php${PHP_VER}-fpm")"
85-
if [ "${STATUS}" = "active" ]; then
87+
if [[ "${STATUS}" == "active" ]]; then
8688
echo "PASSED: PHP ${PHP_VER} is running."
8789
else
8890
echo "FAILED: PHP ${PHP_VER} not running. Please diagnose this issue before proceeding."
@@ -91,7 +93,7 @@ fi
9193

9294
# Redis Service Check
9395
STATUS="$(systemctl is-active redis)"
94-
if [ "${STATUS}" = "active" ]; then
96+
if [[ "${STATUS}" == "active" ]]; then
9597
echo "PASSED: Redis is running."
9698
else
9799
echo "FAILED: Redis not running. Please diagnose this issue before proceeding."
@@ -958,7 +960,7 @@ if [ "${#SITES[@]}" = 1 ];
958960
# Check if redis.conf needs update (avoid duplicate changes)
959961
if ! grep -q "databases ${#SITES[@]}" /etc/redis/redis.conf; then
960962
sed -i "s|databases ${OLDREDISDB}|databases ${#SITES[@]}|g" /etc/redis/redis.conf
961-
service redis-server restart
963+
restart_service "redis-server"
962964
fi
963965
# Set WordPress to use the latest Redis database number.
964966
sed -i "s|WP_REDIS_DATABASE', 0|WP_REDIS_DATABASE', ${OLDREDISDB}|g" "${TARGET_WP_PATH}/wp-config.php"

0 commit comments

Comments
 (0)