|
| 1 | +#!/bin/sh |
| 2 | +set -e |
| 3 | + |
| 4 | +# Runtime PHP configuration overrides |
| 5 | +if [ -n "$PHP_DISPLAY_ERRORS" ]; then |
| 6 | + if [ "$PHP_DISPLAY_ERRORS" = "1" ] || [ "$PHP_DISPLAY_ERRORS" = "On" ]; then |
| 7 | + echo "display_errors = On" > /usr/local/etc/php/conf.d/41-runtime.ini |
| 8 | + else |
| 9 | + echo "display_errors = Off" > /usr/local/etc/php/conf.d/41-runtime.ini |
| 10 | + fi |
| 11 | +fi |
| 12 | + |
| 13 | +if [ -n "$PHP_MEMORY_LIMIT" ]; then |
| 14 | + echo "memory_limit = $PHP_MEMORY_LIMIT" >> /usr/local/etc/php/conf.d/41-runtime.ini |
| 15 | +fi |
| 16 | + |
| 17 | +if [ -n "$PHP_MAX_EXECUTION_TIME" ]; then |
| 18 | + echo "max_execution_time = $PHP_MAX_EXECUTION_TIME" >> /usr/local/etc/php/conf.d/41-runtime.ini |
| 19 | +fi |
| 20 | + |
| 21 | +# Ensure writable directories exist with correct permissions |
| 22 | +mkdir -p /var/www/html/core/storage/logs \ |
| 23 | + /var/www/html/core/storage/cache \ |
| 24 | + /var/www/html/core/storage/sessions \ |
| 25 | + /var/www/html/storage \ |
| 26 | + /var/www/html/assets/cache \ |
| 27 | + /var/www/html/assets/export \ |
| 28 | + /var/www/html/assets/files \ |
| 29 | + /var/www/html/assets/images |
| 30 | + |
| 31 | +# Set permissions for Evolution CMS directories |
| 32 | +chown -R www-data:www-data /var/www/html/core/storage || true |
| 33 | +chown -R www-data:www-data /var/www/html/storage || true |
| 34 | +chown -R www-data:www-data /var/www/html/assets || true |
| 35 | + |
| 36 | +# Set proper file permissions (directories 755, files 644) |
| 37 | +find /var/www/html/core/storage -type d -exec chmod 755 {} \; || true |
| 38 | +find /var/www/html/core/storage -type f -exec chmod 644 {} \; || true |
| 39 | +find /var/www/html/assets -type d -exec chmod 755 {} \; || true |
| 40 | +find /var/www/html/assets -type f -exec chmod 644 {} \; || true |
| 41 | + |
| 42 | +# Wait for database if DB_HOST is set |
| 43 | +if [ -n "$DB_HOST" ] && [ "$DB_HOST" != "localhost" ]; then |
| 44 | + echo "Waiting for database at $DB_HOST:${DB_PORT:-5432}..." |
| 45 | + timeout 30 sh -c 'until nc -z $0 $1; do sleep 1; done' "$DB_HOST" "${DB_PORT:-5432}" || echo "Database wait timeout" |
| 46 | +fi |
| 47 | + |
| 48 | +# Auto-install Evolution CMS if not already installed |
| 49 | +if [ "$EVO_AUTO_INSTALL" = "true" ] && [ ! -f "/var/www/html/config.php" ]; then |
| 50 | + echo "🚀 Evolution CMS not found, starting auto-installation..." |
| 51 | + |
| 52 | + # Check if install directory exists |
| 53 | + if [ -d "/var/www/html/install" ] && [ -f "/var/www/html/install/cli-install.php" ]; then |
| 54 | + echo "📦 Running Evolution CMS installation..." |
| 55 | + |
| 56 | + cd /var/www/html/install/ |
| 57 | + |
| 58 | + # Map database type |
| 59 | + case "$DB_CONNECTION" in |
| 60 | + "pgsql"|"postgresql") |
| 61 | + DB_TYPE="postgresql" |
| 62 | + ;; |
| 63 | + "mysql"|"mariadb") |
| 64 | + DB_TYPE="mysql" |
| 65 | + ;; |
| 66 | + *) |
| 67 | + DB_TYPE="mysql" |
| 68 | + echo "⚠️ Unknown DB_CONNECTION '$DB_CONNECTION', defaulting to mysql" |
| 69 | + ;; |
| 70 | + esac |
| 71 | + |
| 72 | + # Run CLI installer |
| 73 | + php cli-install.php \ |
| 74 | + --typeInstall="${EVO_INSTALL_TYPE}" \ |
| 75 | + --databaseType="${DB_TYPE}" \ |
| 76 | + --databaseServer="${DB_HOST}" \ |
| 77 | + --databasePort="${DB_PORT}" \ |
| 78 | + --database="${DB_DATABASE}" \ |
| 79 | + --databaseUser="${DB_USERNAME}" \ |
| 80 | + --databasePassword="${DB_PASSWORD}" \ |
| 81 | + --tablePrefix="${EVO_TABLE_PREFIX:-evo_}" \ |
| 82 | + --cmsAdmin="${EVO_ADMIN_LOGIN}" \ |
| 83 | + --cmsAdminEmail="${EVO_ADMIN_EMAIL}" \ |
| 84 | + --cmsPassword="${EVO_ADMIN_PASSWORD}" \ |
| 85 | + --language="${EVO_LANGUAGE}" \ |
| 86 | + --removeInstall="${EVO_REMOVE_INSTALL}" |
| 87 | + |
| 88 | + if [ $? -eq 0 ]; then |
| 89 | + echo "✅ Evolution CMS installed successfully!" |
| 90 | + |
| 91 | + # Post-installation setup |
| 92 | + cd /var/www/html/core/ |
| 93 | + |
| 94 | + # Create main package if MAIN_PACKAGE_NAME is set |
| 95 | + if [ -n "$EVO_MAIN_PACKAGE_NAME" ]; then |
| 96 | + echo "📦 Creating main package: $EVO_MAIN_PACKAGE_NAME" |
| 97 | + php artisan package:create "$EVO_MAIN_PACKAGE_NAME" |
| 98 | + echo "<?php return \"EvolutionCMS\\\\$EVO_MAIN_PACKAGE_NAME\\\\Controllers\\\\\"; ?>" > custom/config/cms/settings/ControllerNamespace.php |
| 99 | + fi |
| 100 | + |
| 101 | + # Install TinyMCE5 if enabled |
| 102 | + if [ "$EVO_INSTALL_TINYMCE" = "true" ]; then |
| 103 | + echo "📝 Installing TinyMCE5..." |
| 104 | + php artisan extras extras TinyMCE5 master || echo "⚠️ TinyMCE5 installation failed" |
| 105 | + echo '<?php return "TinyMCE5"; ?>' > custom/config/cms/settings/which_editor.php || true |
| 106 | + fi |
| 107 | + |
| 108 | + # Set final permissions |
| 109 | + cd /var/www/html/ |
| 110 | + chown -R www-data:www-data . || true |
| 111 | + |
| 112 | + echo "🎉 Evolution CMS setup completed!" |
| 113 | + else |
| 114 | + echo "❌ Evolution CMS installation failed!" |
| 115 | + exit 1 |
| 116 | + fi |
| 117 | + else |
| 118 | + echo "❌ Install directory not found! Cannot auto-install." |
| 119 | + fi |
| 120 | +else |
| 121 | + if [ -f "/var/www/html/config.php" ]; then |
| 122 | + echo "✅ Evolution CMS already installed, skipping auto-install" |
| 123 | + fi |
| 124 | +fi |
| 125 | + |
| 126 | +exec "$@" |
| 127 | + |
| 128 | + |
0 commit comments