fix the enrollement-carryover balance
This commit is contained in:
@@ -0,0 +1,207 @@
|
||||
#!/usr/bin/env python3
|
||||
|
||||
import re
|
||||
import sys
|
||||
from collections import defaultdict
|
||||
from pathlib import Path
|
||||
|
||||
|
||||
# Matches common SQL statements containing a table name.
|
||||
TABLE_PATTERNS = [
|
||||
re.compile(
|
||||
r'^\s*CREATE\s+TABLE\s+(?:IF\s+NOT\s+EXISTS\s+)?[`"\[]?([^`"\]\s(.]+)',
|
||||
re.IGNORECASE,
|
||||
),
|
||||
re.compile(
|
||||
r'^\s*INSERT\s+INTO\s+[`"\[]?([^`"\]\s(.]+)',
|
||||
re.IGNORECASE,
|
||||
),
|
||||
re.compile(
|
||||
r'^\s*UPDATE\s+[`"\[]?([^`"\]\s(.]+)',
|
||||
re.IGNORECASE,
|
||||
),
|
||||
re.compile(
|
||||
r'^\s*ALTER\s+TABLE\s+[`"\[]?([^`"\]\s(.]+)',
|
||||
re.IGNORECASE,
|
||||
),
|
||||
re.compile(
|
||||
r'^\s*DELETE\s+FROM\s+[`"\[]?([^`"\]\s(.]+)',
|
||||
re.IGNORECASE,
|
||||
),
|
||||
]
|
||||
|
||||
|
||||
def extract_table_name(line):
|
||||
"""Return table name if the line starts a recognizable table statement."""
|
||||
for pattern in TABLE_PATTERNS:
|
||||
match = pattern.search(line)
|
||||
if match:
|
||||
return match.group(1)
|
||||
return None
|
||||
|
||||
|
||||
def normalize_line(line):
|
||||
"""
|
||||
Normalize a line for comparison.
|
||||
|
||||
Removes leading/trailing whitespace but otherwise leaves SQL intact.
|
||||
"""
|
||||
return line.strip()
|
||||
|
||||
|
||||
def parse_sql_file(filename):
|
||||
"""
|
||||
Parse SQL into table -> list of (line_number, original_line).
|
||||
|
||||
Once a table-related statement is detected, following lines are associated
|
||||
with that table until another table statement begins.
|
||||
"""
|
||||
tables = defaultdict(list)
|
||||
|
||||
current_table = None
|
||||
|
||||
with open(filename, "r", encoding="utf-8", errors="replace") as f:
|
||||
for line_number, line in enumerate(f, start=1):
|
||||
table = extract_table_name(line)
|
||||
|
||||
if table:
|
||||
current_table = table
|
||||
|
||||
if current_table:
|
||||
cleaned = normalize_line(line)
|
||||
|
||||
# Ignore completely blank lines.
|
||||
if cleaned:
|
||||
tables[current_table].append(
|
||||
(line_number, line.rstrip("\n"))
|
||||
)
|
||||
|
||||
return tables
|
||||
|
||||
|
||||
def line_multiset(lines):
|
||||
"""
|
||||
Convert lines into:
|
||||
normalized_line -> list of occurrences
|
||||
|
||||
Keeping occurrences means duplicate INSERT rows are handled correctly.
|
||||
"""
|
||||
result = defaultdict(list)
|
||||
|
||||
for line_number, text in lines:
|
||||
result[normalize_line(text)].append((line_number, text))
|
||||
|
||||
return result
|
||||
|
||||
|
||||
def compare_table(table, lines1, lines2, file1, file2):
|
||||
data1 = line_multiset(lines1)
|
||||
data2 = line_multiset(lines2)
|
||||
|
||||
all_lines = sorted(set(data1) | set(data2))
|
||||
|
||||
only_file1 = []
|
||||
only_file2 = []
|
||||
|
||||
for normalized in all_lines:
|
||||
occurrences1 = data1.get(normalized, [])
|
||||
occurrences2 = data2.get(normalized, [])
|
||||
|
||||
common_count = min(len(occurrences1), len(occurrences2))
|
||||
|
||||
only_file1.extend(occurrences1[common_count:])
|
||||
only_file2.extend(occurrences2[common_count:])
|
||||
|
||||
if not only_file1 and not only_file2:
|
||||
return False
|
||||
|
||||
print()
|
||||
print("=" * 100)
|
||||
print(f"TABLE: {table}")
|
||||
print("=" * 100)
|
||||
|
||||
if only_file1:
|
||||
print(f"\nOnly in {file1}:")
|
||||
for line_number, text in only_file1:
|
||||
print(f" Line {line_number}: {text}")
|
||||
|
||||
if only_file2:
|
||||
print(f"\nOnly in {file2}:")
|
||||
for line_number, text in only_file2:
|
||||
print(f" Line {line_number}: {text}")
|
||||
|
||||
return True
|
||||
|
||||
|
||||
def compare_sql_files(file1, file2):
|
||||
tables1 = parse_sql_file(file1)
|
||||
tables2 = parse_sql_file(file2)
|
||||
|
||||
all_tables = sorted(set(tables1) | set(tables2))
|
||||
|
||||
print(f"Comparing:")
|
||||
print(f" File 1: {file1}")
|
||||
print(f" File 2: {file2}")
|
||||
print()
|
||||
|
||||
differences = 0
|
||||
|
||||
for table in all_tables:
|
||||
if table not in tables1:
|
||||
print()
|
||||
print("=" * 100)
|
||||
print(f"TABLE: {table}")
|
||||
print("=" * 100)
|
||||
print(f"Table exists only in {file2}")
|
||||
differences += 1
|
||||
continue
|
||||
|
||||
if table not in tables2:
|
||||
print()
|
||||
print("=" * 100)
|
||||
print(f"TABLE: {table}")
|
||||
print("=" * 100)
|
||||
print(f"Table exists only in {file1}")
|
||||
differences += 1
|
||||
continue
|
||||
|
||||
if compare_table(
|
||||
table,
|
||||
tables1[table],
|
||||
tables2[table],
|
||||
file1,
|
||||
file2,
|
||||
):
|
||||
differences += 1
|
||||
|
||||
print()
|
||||
print("=" * 100)
|
||||
|
||||
if differences == 0:
|
||||
print("No table differences found.")
|
||||
else:
|
||||
print(f"{differences} table(s) contain differences.")
|
||||
|
||||
|
||||
def main():
|
||||
if len(sys.argv) != 3:
|
||||
script = Path(sys.argv[0]).name
|
||||
print(f"Usage: python {script} file1.sql file2.sql")
|
||||
sys.exit(1)
|
||||
|
||||
file1 = sys.argv[1]
|
||||
file2 = sys.argv[2]
|
||||
|
||||
if not Path(file1).is_file():
|
||||
print(f"File not found: {file1}")
|
||||
sys.exit(1)
|
||||
|
||||
if not Path(file2).is_file():
|
||||
print(f"File not found: {file2}")
|
||||
sys.exit(1)
|
||||
|
||||
compare_sql_files(file1, file2)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
@@ -0,0 +1,247 @@
|
||||
#!/bin/bash
|
||||
|
||||
# ===============================
|
||||
# Al Rahma Sunday School Deployment Script
|
||||
# ===============================
|
||||
|
||||
# ----- Domain and App Info -----
|
||||
DM_NAME="home.alrahmaisgl.org"
|
||||
domain_app="alrahma"
|
||||
|
||||
# ----- Database credentials -----
|
||||
DB_HOST="localhost"
|
||||
DB_NAME="u280815660_school"
|
||||
DB_USER="u280815660_melabidi"
|
||||
DB_PASS=">tNxlRzP/W8"
|
||||
|
||||
# ----- Directories -----
|
||||
ZIP_FILE="$1"
|
||||
BASE_DIR="/home/u280815660/domains"
|
||||
DEPLOY_DIR="$BASE_DIR/$domain_app"
|
||||
APP_DIR="$BASE_DIR/$DM_NAME/$domain_app"
|
||||
PUBLIC_DIR="$BASE_DIR/$DM_NAME/public_html"
|
||||
BACKUP_DIR="$BASE_DIR/archive"
|
||||
SECRETS_DIR="$BASE_DIR/deploy_secrets"
|
||||
TIMESTAMP=$(date +"%Y%m%d_%H%M%S")
|
||||
|
||||
# ----- Runtime binaries -----
|
||||
# Hostinger/CloudLinux exposes PHP 8.5 here. The default CLI `php` may still be
|
||||
# PHP 8.2, which cannot install this project's PHP 8.5 lock file.
|
||||
PHP_BIN="${PHP_BIN:-/opt/alt/php85/usr/bin/php}"
|
||||
COMPOSER_BIN="${COMPOSER_BIN:-$(command -v composer2 || command -v composer || true)}"
|
||||
|
||||
|
||||
# ===============================
|
||||
# 1. VALIDATE INPUT
|
||||
# ===============================
|
||||
if [ -z "$ZIP_FILE" ] || [ ! -f "$ZIP_FILE" ]; then
|
||||
echo "? Please provide the ZIP file: ./deploy_home.sh alrahma_deploy.zip"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
echo "?? Starting deployment of $ZIP_FILE..."
|
||||
|
||||
if [ ! -x "$PHP_BIN" ]; then
|
||||
echo "? PHP 8.5 binary was not found or is not executable: $PHP_BIN"
|
||||
echo " Set PHP_BIN=/path/to/php85 and rerun the deployment."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if [ -z "$COMPOSER_BIN" ] || [ ! -e "$COMPOSER_BIN" ]; then
|
||||
echo "? composer2/composer was not found in PATH."
|
||||
echo " Set COMPOSER_BIN=/path/to/composer2 and rerun the deployment."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
echo "?? Using PHP: $("$PHP_BIN" -v | head -n 1)"
|
||||
echo "?? Using Composer: $COMPOSER_BIN"
|
||||
|
||||
# ===============================
|
||||
# 2. BACKUP EXISTING SITE
|
||||
# ===============================
|
||||
echo "??? Backing up current site..."
|
||||
mkdir -p "$BACKUP_DIR"
|
||||
cp -r "$PUBLIC_DIR" "$BACKUP_DIR/public_html_$TIMESTAMP"
|
||||
cp -r "$APP_DIR" "$BACKUP_DIR/$domain_app_$TIMESTAMP"
|
||||
|
||||
# ===============================
|
||||
# 3. BACKUP PERSISTENT FILES
|
||||
# ===============================
|
||||
echo "?? Backing up persistent files..."
|
||||
mkdir -p "$SECRETS_DIR"
|
||||
PERSIST_BACKUP="$BASE_DIR/persist_backup_$TIMESTAMP"
|
||||
mkdir -p "$PERSIST_BACKUP"
|
||||
|
||||
# writable/
|
||||
if [ -d "$APP_DIR/writable" ]; then
|
||||
echo " ? Backing up writable/"
|
||||
cp -r "$APP_DIR/writable" "$PERSIST_BACKUP/writable"
|
||||
fi
|
||||
|
||||
# .env
|
||||
if [ -f "$APP_DIR/.env" ]; then
|
||||
echo " ? Backing up .env"
|
||||
cp "$APP_DIR/.env" "$PERSIST_BACKUP/.env"
|
||||
fi
|
||||
|
||||
# .htaccess
|
||||
if [ -f "$PUBLIC_DIR/.htaccess" ]; then
|
||||
echo " ? Backing up .htaccess"
|
||||
cp "$PUBLIC_DIR/.htaccess" "$PERSIST_BACKUP/.htaccess"
|
||||
fi
|
||||
|
||||
# index.php
|
||||
if [ -f "$PUBLIC_DIR/index.php" ]; then
|
||||
echo " ? Backing up index.php"
|
||||
cp "$PUBLIC_DIR/index.php" "$PERSIST_BACKUP/index.php"
|
||||
fi
|
||||
|
||||
# ===============================
|
||||
# 4. CLEAN & EXTRACT NEW DEPLOY
|
||||
# ===============================
|
||||
echo "?? Cleaning old deployment..."
|
||||
rm -rf "$DEPLOY_DIR"
|
||||
unzip "$ZIP_FILE" -d "$BASE_DIR"
|
||||
|
||||
# ===============================
|
||||
# 5. DEPLOY APP FILES
|
||||
# ===============================
|
||||
echo "?? Deploying new app files..."
|
||||
rm -rf "$APP_DIR"
|
||||
mkdir -p "$APP_DIR"
|
||||
cp -r "$DEPLOY_DIR"/. "$APP_DIR"
|
||||
|
||||
# ===============================
|
||||
# 6. RESTORE PERSISTENT FILES
|
||||
# ===============================
|
||||
echo "?? Restoring persistent files..."
|
||||
|
||||
# writable/
|
||||
if [ -d "$PERSIST_BACKUP/writable" ]; then
|
||||
echo " ? Restoring writable/"
|
||||
rm -rf "$APP_DIR/writable"
|
||||
cp -r "$PERSIST_BACKUP/writable" "$APP_DIR/writable"
|
||||
fi
|
||||
|
||||
# .env
|
||||
if [ -f "$PERSIST_BACKUP/.env" ]; then
|
||||
echo " ? Restoring .env"
|
||||
cp "$PERSIST_BACKUP/.env" "$APP_DIR/.env"
|
||||
fi
|
||||
|
||||
# .htaccess
|
||||
if [ -f "$PERSIST_BACKUP/.htaccess" ]; then
|
||||
echo " ? Restoring .htaccess"
|
||||
cp "$PERSIST_BACKUP/.htaccess" "$PUBLIC_DIR/.htaccess"
|
||||
fi
|
||||
|
||||
# index.php
|
||||
if [ -f "$PERSIST_BACKUP/index.php" ]; then
|
||||
echo " ? Restoring index.php"
|
||||
cp "$PERSIST_BACKUP/index.php" "$PUBLIC_DIR/index.php"
|
||||
fi
|
||||
|
||||
# ===============================
|
||||
# 7. DEPLOY PUBLIC FILES
|
||||
# ===============================
|
||||
echo "?? Deploying public files..."
|
||||
rm -rf "$PUBLIC_DIR"/*
|
||||
cp -r "$APP_DIR/public/"* "$PUBLIC_DIR"
|
||||
|
||||
# Re-apply .htaccess and index.php again (to ensure overwrite protection)
|
||||
if [ -f "$PERSIST_BACKUP/.htaccess" ]; then
|
||||
cp "$PERSIST_BACKUP/.htaccess" "$PUBLIC_DIR/.htaccess"
|
||||
fi
|
||||
if [ -f "$PERSIST_BACKUP/index.php" ]; then
|
||||
cp "$PERSIST_BACKUP/index.php" "$PUBLIC_DIR/index.php"
|
||||
fi
|
||||
|
||||
# ===============================
|
||||
# 8. FIX index.php PATH
|
||||
# ===============================
|
||||
echo "?? Fixing index.php path..."
|
||||
sed -i "s|require FCPATH . '../app/Config/Paths.php';|require FCPATH . '../alrahma/app/Config/Paths.php';|" "$PUBLIC_DIR/index.php"
|
||||
|
||||
# ===============================
|
||||
# 9. UPDATE BASE URL & DB CONFIG
|
||||
# ===============================
|
||||
APP_CONFIG="$APP_DIR/app/Config/App.php"
|
||||
DB_CONFIG="$APP_DIR/app/Config/Database.php"
|
||||
echo "?? Updating configuration files..."
|
||||
|
||||
# Base URL
|
||||
sed -i "s|public string \$baseURL = .*|public string \$baseURL = 'https://$DM_NAME/';|" "$APP_CONFIG"
|
||||
|
||||
# Database.php
|
||||
sed -i "s|'hostname' => .*|'hostname' => '$DB_HOST',|" "$DB_CONFIG"
|
||||
sed -i "s|'username' => .*|'username' => '$DB_USER',|" "$DB_CONFIG"
|
||||
sed -i "s|'password' => .*|'password' => '$DB_PASS',|" "$DB_CONFIG"
|
||||
sed -i "s|'database' => .*|'database' => '$DB_NAME',|" "$DB_CONFIG"
|
||||
|
||||
# ===============================
|
||||
# 10. UPDATE db_connection.php
|
||||
# ===============================
|
||||
DB_CONN_FILE="$APP_DIR/app/db_connection.php"
|
||||
if [ -f "$DB_CONN_FILE" ]; then
|
||||
echo "??? Updating db_connection.php..."
|
||||
sed -i "s|\$host = '.*';|\$host = '$DB_HOST';|" "$DB_CONN_FILE"
|
||||
sed -i "s|\$dbname = '.*';|\$dbname = '$DB_NAME';|" "$DB_CONN_FILE"
|
||||
sed -i "s|\$username = '.*';|\$username = '$DB_USER';|" "$DB_CONN_FILE"
|
||||
sed -i "s|\$password = '.*';|\$password = '$DB_PASS';|" "$DB_CONN_FILE"
|
||||
fi
|
||||
|
||||
# ===============================
|
||||
# 11. FIX FPDF PATHS
|
||||
# ===============================
|
||||
echo "?? Fixing FPDF paths..."
|
||||
grep -rl "ThirdParty\\\\fpdf\\\\fpdf.php" "$APP_DIR/app" | while read -r file; do
|
||||
sed -i "s|ThirdParty\\\\fpdf\\\\fpdf.php|ThirdParty/fpdf/fpdf.php|g" "$file"
|
||||
echo "? Fixed path in: $file"
|
||||
done
|
||||
|
||||
# ===============================
|
||||
# 12. COMPOSER INSTALL
|
||||
# ===============================
|
||||
echo "?? Installing production Composer dependencies with PHP 8.5..."
|
||||
cd "$APP_DIR" || exit
|
||||
|
||||
export PATH="$(dirname "$PHP_BIN"):$PATH"
|
||||
export COMPOSER_ALLOW_SUPERUSER=1
|
||||
|
||||
if "$PHP_BIN" "$COMPOSER_BIN" --version >/dev/null 2>&1; then
|
||||
"$PHP_BIN" "$COMPOSER_BIN" install \
|
||||
--no-dev \
|
||||
--prefer-dist \
|
||||
--optimize-autoloader \
|
||||
--classmap-authoritative \
|
||||
--no-interaction \
|
||||
--no-progress
|
||||
else
|
||||
"$COMPOSER_BIN" install \
|
||||
--no-dev \
|
||||
--prefer-dist \
|
||||
--optimize-autoloader \
|
||||
--classmap-authoritative \
|
||||
--no-interaction \
|
||||
--no-progress
|
||||
fi
|
||||
|
||||
"$PHP_BIN" spark --version
|
||||
|
||||
# ===============================
|
||||
# 13. RESTORE PERMISSIONS
|
||||
# ===============================
|
||||
echo "?? Setting permissions..."
|
||||
chmod 644 "$PUBLIC_DIR/.htaccess"
|
||||
chmod 644 "$PUBLIC_DIR/index.php"
|
||||
chmod -R 755 "$APP_DIR"
|
||||
chmod 644 "$APP_DIR/app/db_connection.php"
|
||||
chmod -R 777 "$APP_DIR/writable"
|
||||
|
||||
# ===============================
|
||||
# ? DONE
|
||||
# ===============================
|
||||
echo "? Deployment completed successfully at $TIMESTAMP"
|
||||
echo "?? Backup stored in: $BACKUP_DIR"
|
||||
echo "?? Persistent files restored from: $PERSIST_BACKUP"
|
||||
echo "?? Writable, .env, .htaccess, and index.php preserved successfully!"
|
||||
@@ -0,0 +1,248 @@
|
||||
#!/bin/bash
|
||||
|
||||
# ===============================
|
||||
# Al Rahma Sunday School Deployment Script
|
||||
# ===============================
|
||||
|
||||
# ----- Domain and App Info -----
|
||||
DM_NAME="test.alrahmaisgl.org"
|
||||
domain_app="alrahma"
|
||||
|
||||
# ----- Database credentials -----
|
||||
DB_HOST="localhost"
|
||||
DB_NAME="u280815660_adjust_balance"
|
||||
DB_USER="u280815660_fixbalance"
|
||||
DB_PASS="|bP9TF79+7"
|
||||
|
||||
|
||||
# ----- Directories -----
|
||||
ZIP_FILE="$1"
|
||||
BASE_DIR="/home/u280815660/domains"
|
||||
DEPLOY_DIR="$BASE_DIR/$domain_app"
|
||||
APP_DIR="$BASE_DIR/$DM_NAME/$domain_app"
|
||||
PUBLIC_DIR="$BASE_DIR/$DM_NAME/public_html"
|
||||
BACKUP_DIR="$BASE_DIR/archive"
|
||||
SECRETS_DIR="$BASE_DIR/deploy_secrets"
|
||||
TIMESTAMP=$(date +"%Y%m%d_%H%M%S")
|
||||
|
||||
# ----- Runtime binaries -----
|
||||
# Hostinger/CloudLinux exposes PHP 8.5 here. The default CLI `php` may still be
|
||||
# PHP 8.2, which cannot install this project's PHP 8.5 lock file.
|
||||
PHP_BIN="${PHP_BIN:-/opt/alt/php85/usr/bin/php}"
|
||||
COMPOSER_BIN="${COMPOSER_BIN:-$(command -v composer2 || command -v composer || true)}"
|
||||
|
||||
|
||||
# ===============================
|
||||
# 1. VALIDATE INPUT
|
||||
# ===============================
|
||||
if [ -z "$ZIP_FILE" ] || [ ! -f "$ZIP_FILE" ]; then
|
||||
echo "? Please provide the ZIP file: ./deploy_home.sh alrahma_deploy.zip"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
echo "?? Starting deployment of $ZIP_FILE..."
|
||||
|
||||
if [ ! -x "$PHP_BIN" ]; then
|
||||
echo "? PHP 8.5 binary was not found or is not executable: $PHP_BIN"
|
||||
echo " Set PHP_BIN=/path/to/php85 and rerun the deployment."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if [ -z "$COMPOSER_BIN" ] || [ ! -e "$COMPOSER_BIN" ]; then
|
||||
echo "? composer2/composer was not found in PATH."
|
||||
echo " Set COMPOSER_BIN=/path/to/composer2 and rerun the deployment."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
echo "?? Using PHP: $("$PHP_BIN" -v | head -n 1)"
|
||||
echo "?? Using Composer: $COMPOSER_BIN"
|
||||
|
||||
# ===============================
|
||||
# 2. BACKUP EXISTING SITE
|
||||
# ===============================
|
||||
echo "??? Backing up current site..."
|
||||
mkdir -p "$BACKUP_DIR"
|
||||
cp -r "$PUBLIC_DIR" "$BACKUP_DIR/public_html_$TIMESTAMP"
|
||||
cp -r "$APP_DIR" "$BACKUP_DIR/$domain_app_$TIMESTAMP"
|
||||
|
||||
# ===============================
|
||||
# 3. BACKUP PERSISTENT FILES
|
||||
# ===============================
|
||||
echo "?? Backing up persistent files..."
|
||||
mkdir -p "$SECRETS_DIR"
|
||||
PERSIST_BACKUP="$BASE_DIR/persist_backup_$TIMESTAMP"
|
||||
mkdir -p "$PERSIST_BACKUP"
|
||||
|
||||
# writable/
|
||||
if [ -d "$APP_DIR/writable" ]; then
|
||||
echo " ? Backing up writable/"
|
||||
cp -r "$APP_DIR/writable" "$PERSIST_BACKUP/writable"
|
||||
fi
|
||||
|
||||
# .env
|
||||
if [ -f "$APP_DIR/.env" ]; then
|
||||
echo " ? Backing up .env"
|
||||
cp "$APP_DIR/.env" "$PERSIST_BACKUP/.env"
|
||||
fi
|
||||
|
||||
# .htaccess
|
||||
if [ -f "$PUBLIC_DIR/.htaccess" ]; then
|
||||
echo " ? Backing up .htaccess"
|
||||
cp "$PUBLIC_DIR/.htaccess" "$PERSIST_BACKUP/.htaccess"
|
||||
fi
|
||||
|
||||
# index.php
|
||||
if [ -f "$PUBLIC_DIR/index.php" ]; then
|
||||
echo " ? Backing up index.php"
|
||||
cp "$PUBLIC_DIR/index.php" "$PERSIST_BACKUP/index.php"
|
||||
fi
|
||||
|
||||
# ===============================
|
||||
# 4. CLEAN & EXTRACT NEW DEPLOY
|
||||
# ===============================
|
||||
echo "?? Cleaning old deployment..."
|
||||
rm -rf "$DEPLOY_DIR"
|
||||
unzip "$ZIP_FILE" -d "$BASE_DIR"
|
||||
|
||||
# ===============================
|
||||
# 5. DEPLOY APP FILES
|
||||
# ===============================
|
||||
echo "?? Deploying new app files..."
|
||||
rm -rf "$APP_DIR"
|
||||
mkdir -p "$APP_DIR"
|
||||
cp -r "$DEPLOY_DIR"/. "$APP_DIR"
|
||||
|
||||
# ===============================
|
||||
# 6. RESTORE PERSISTENT FILES
|
||||
# ===============================
|
||||
echo "?? Restoring persistent files..."
|
||||
|
||||
# writable/
|
||||
if [ -d "$PERSIST_BACKUP/writable" ]; then
|
||||
echo " ? Restoring writable/"
|
||||
rm -rf "$APP_DIR/writable"
|
||||
cp -r "$PERSIST_BACKUP/writable" "$APP_DIR/writable"
|
||||
fi
|
||||
|
||||
# .env
|
||||
if [ -f "$PERSIST_BACKUP/.env" ]; then
|
||||
echo " ? Restoring .env"
|
||||
cp "$PERSIST_BACKUP/.env" "$APP_DIR/.env"
|
||||
fi
|
||||
|
||||
# .htaccess
|
||||
if [ -f "$PERSIST_BACKUP/.htaccess" ]; then
|
||||
echo " ? Restoring .htaccess"
|
||||
cp "$PERSIST_BACKUP/.htaccess" "$PUBLIC_DIR/.htaccess"
|
||||
fi
|
||||
|
||||
# index.php
|
||||
if [ -f "$PERSIST_BACKUP/index.php" ]; then
|
||||
echo " ? Restoring index.php"
|
||||
cp "$PERSIST_BACKUP/index.php" "$PUBLIC_DIR/index.php"
|
||||
fi
|
||||
|
||||
# ===============================
|
||||
# 7. DEPLOY PUBLIC FILES
|
||||
# ===============================
|
||||
echo "?? Deploying public files..."
|
||||
rm -rf "$PUBLIC_DIR"/*
|
||||
cp -r "$APP_DIR/public/"* "$PUBLIC_DIR"
|
||||
|
||||
# Re-apply .htaccess and index.php again (to ensure overwrite protection)
|
||||
if [ -f "$PERSIST_BACKUP/.htaccess" ]; then
|
||||
cp "$PERSIST_BACKUP/.htaccess" "$PUBLIC_DIR/.htaccess"
|
||||
fi
|
||||
if [ -f "$PERSIST_BACKUP/index.php" ]; then
|
||||
cp "$PERSIST_BACKUP/index.php" "$PUBLIC_DIR/index.php"
|
||||
fi
|
||||
|
||||
# ===============================
|
||||
# 8. FIX index.php PATH
|
||||
# ===============================
|
||||
echo "?? Fixing index.php path..."
|
||||
sed -i "s|require FCPATH . '../app/Config/Paths.php';|require FCPATH . '../alrahma/app/Config/Paths.php';|" "$PUBLIC_DIR/index.php"
|
||||
|
||||
# ===============================
|
||||
# 9. UPDATE BASE URL & DB CONFIG
|
||||
# ===============================
|
||||
APP_CONFIG="$APP_DIR/app/Config/App.php"
|
||||
DB_CONFIG="$APP_DIR/app/Config/Database.php"
|
||||
echo "?? Updating configuration files..."
|
||||
|
||||
# Base URL
|
||||
sed -i "s|public string \$baseURL = .*|public string \$baseURL = 'https://$DM_NAME/';|" "$APP_CONFIG"
|
||||
|
||||
# Database.php
|
||||
sed -i "s|'hostname' => .*|'hostname' => '$DB_HOST',|" "$DB_CONFIG"
|
||||
sed -i "s|'username' => .*|'username' => '$DB_USER',|" "$DB_CONFIG"
|
||||
sed -i "s|'password' => .*|'password' => '$DB_PASS',|" "$DB_CONFIG"
|
||||
sed -i "s|'database' => .*|'database' => '$DB_NAME',|" "$DB_CONFIG"
|
||||
|
||||
# ===============================
|
||||
# 10. UPDATE db_connection.php
|
||||
# ===============================
|
||||
DB_CONN_FILE="$APP_DIR/app/db_connection.php"
|
||||
if [ -f "$DB_CONN_FILE" ]; then
|
||||
echo "??? Updating db_connection.php..."
|
||||
sed -i "s|\$host = '.*';|\$host = '$DB_HOST';|" "$DB_CONN_FILE"
|
||||
sed -i "s|\$dbname = '.*';|\$dbname = '$DB_NAME';|" "$DB_CONN_FILE"
|
||||
sed -i "s|\$username = '.*';|\$username = '$DB_USER';|" "$DB_CONN_FILE"
|
||||
sed -i "s|\$password = '.*';|\$password = '$DB_PASS';|" "$DB_CONN_FILE"
|
||||
fi
|
||||
|
||||
# ===============================
|
||||
# 11. FIX FPDF PATHS
|
||||
# ===============================
|
||||
echo "?? Fixing FPDF paths..."
|
||||
grep -rl "ThirdParty\\\\fpdf\\\\fpdf.php" "$APP_DIR/app" | while read -r file; do
|
||||
sed -i "s|ThirdParty\\\\fpdf\\\\fpdf.php|ThirdParty/fpdf/fpdf.php|g" "$file"
|
||||
echo "? Fixed path in: $file"
|
||||
done
|
||||
|
||||
# ===============================
|
||||
# 12. COMPOSER INSTALL
|
||||
# ===============================
|
||||
echo "?? Installing production Composer dependencies with PHP 8.5..."
|
||||
cd "$APP_DIR" || exit
|
||||
|
||||
export PATH="$(dirname "$PHP_BIN"):$PATH"
|
||||
export COMPOSER_ALLOW_SUPERUSER=1
|
||||
|
||||
if "$PHP_BIN" "$COMPOSER_BIN" --version >/dev/null 2>&1; then
|
||||
"$PHP_BIN" "$COMPOSER_BIN" install \
|
||||
--no-dev \
|
||||
--prefer-dist \
|
||||
--optimize-autoloader \
|
||||
--classmap-authoritative \
|
||||
--no-interaction \
|
||||
--no-progress
|
||||
else
|
||||
"$COMPOSER_BIN" install \
|
||||
--no-dev \
|
||||
--prefer-dist \
|
||||
--optimize-autoloader \
|
||||
--classmap-authoritative \
|
||||
--no-interaction \
|
||||
--no-progress
|
||||
fi
|
||||
|
||||
"$PHP_BIN" spark --version
|
||||
|
||||
# ===============================
|
||||
# 13. RESTORE PERMISSIONS
|
||||
# ===============================
|
||||
echo "?? Setting permissions..."
|
||||
chmod 644 "$PUBLIC_DIR/.htaccess"
|
||||
chmod 644 "$PUBLIC_DIR/index.php"
|
||||
chmod -R 755 "$APP_DIR"
|
||||
chmod 644 "$APP_DIR/app/db_connection.php"
|
||||
chmod -R 777 "$APP_DIR/writable"
|
||||
|
||||
# ===============================
|
||||
# ? DONE
|
||||
# ===============================
|
||||
echo "? Deployment completed successfully at $TIMESTAMP"
|
||||
echo "?? Backup stored in: $BACKUP_DIR"
|
||||
echo "?? Persistent files restored from: $PERSIST_BACKUP"
|
||||
echo "?? Writable, .env, .htaccess, and index.php preserved successfully!"
|
||||
Reference in New Issue
Block a user