#!/bin/sh # SugarCRM 6.5 CE Docker Entrypoint # ================================== # Creates config.php directly (bypasses broken silent installer) # Resolve DB connection from env if [ -z "$DB_HOST_NAME" ]; then export DB_HOST_NAME=${DB_PORT_3306_TCP_ADDR:-db} fi if [ -z "$DB_TCP_PORT" ]; then export DB_TCP_PORT=${DB_PORT_3306_TCP_PORT:-3306} fi if [ -z "$DB_USER_NAME" ]; then export DB_USER_NAME=${DB_ENV_MYSQL_USER:-sugarcrm} fi if [ -z "$DB_PASSWORD" ]; then export DB_PASSWORD=${DB_ENV_MYSQL_PASSWORD:-sugarcrm_secret} fi if [ -z "$DATABASE_NAME" ]; then export DATABASE_NAME=${DB_ENV_MYSQL_DATABASE:-sugarcrm} fi # Generate config_override.php from template (ignore perm error) /usr/local/bin/envtemplate.py -i /usr/local/src/config_override.php.pyt -o /var/www/html/config_override.php 2>/dev/null || true # Start Apache echo "Starting Apache (background)..." apachectl -DFOREGROUND & APACHE_PID=$! # Wait for Apache echo "Waiting for Apache..." for i in $(seq 1 30); do if curl -s http://localhost/ >/dev/null 2>&1; then echo "Apache is ready" break fi sleep 1 done # Wait for MySQL echo "Waiting for MySQL..." for i in $(seq 1 30); do if php -r "\$c=@mysql_connect('$DB_HOST_NAME:$DB_TCP_PORT','$DB_USER_NAME','$DB_PASSWORD');if(\$c){mysql_close(\$c);exit(0);}exit(1);" 2>/dev/null; then echo "MySQL is ready" break fi sleep 2 done # Create config.php directly if not exists or empty CONFIG_PHP=/var/www/html/config.php if [ ! -s "$CONFIG_PHP" ]; then echo "Creating config.php directly..." cat > "$CONFIG_PHP" << CONFIGEOF array('completed' => true), 'dbconfig' => array( 'db_host_name' => '$DB_HOST_NAME', 'db_host_instance' => 'SQLEXPRESS', 'db_user_name' => '$DB_USER_NAME', 'db_password' => '$DB_PASSWORD', 'db_name' => '$DATABASE_NAME', 'db_type' => 'mysql', 'db_port' => '$DB_TCP_PORT', 'db_manager' => 'MysqlManager', ), 'dbconfigoption' => array( 'persistent' => true, 'autofree' => false, 'debug' => 0, 'ssl' => false, ), 'default_currency_iso4217' => 'EUR', 'default_currency_name' => 'Euro', 'default_currency_symbol' => '€', 'default_date_format' => 'd.m.Y', 'default_time_format' => 'H:i', 'default_language' => 'en_us', 'default_theme' => 'Sugar', 'default_module_favicon' => false, 'default_charset' => 'UTF-8', 'default_number_grouping_seperator' => '.', 'default_decimal_seperator' => ',', 'disable_export' => false, 'disable_vcr' => false, 'dump_slow_queries' => false, 'email_default_client' => 'sugar', 'email_default_editor' => 'plain', 'export_delimiter' => ',', 'history_max_viewed' => 50, 'installer_locked' => true, 'languages' => array('en_us' => 'English (US)'), 'list_max_entries_per_page' => 20, 'lock_default_user_name' => 'admin', 'lock_default_user_password' => 'admin123', 'passwordsetting' => array( 'minpwdlength' => '', 'oneupper' => '', 'onelower' => '', 'onenumber' => '', 'onespecial' => '', 'systemgenerated' => '0', 'forgotpasswordON' => '1', 'linkexpiration' => '1', 'linkexpirationtime' => '24', 'linkexpirationtype' => '1', 'userexpiration' => '0', 'userexpirationtime' => '', 'userexpirationtype' => '1', 'userexpirationlogin' => '', 'lockoutexpiration' => '0', 'lockoutexpirationtime' => '', 'lockoutexpirationtype' => '1', 'lockoutexpirationlogin' => '', ), 'resource_management' => array( 'special_query_limit' => 50000, 'special_query_modules' => array('Reports', 'Export', 'Import', 'Administration', 'Sync'), 'default_limit' => 1000, ), 'site_url' => 'http://localhost:2080', 'site_url_is_set' => true, 'sugar_version' => '6.5.26', 'sugarbeet' => false, 'translation_string_prefix' => false, 'unique_key' => '$(date +%s)$(head -c 8 /dev/urandom | md5sum | cut -c1-8)', 'upload_maxsize' => 30000000, 'verify_client_ip' => false, 'logger' => array( 'level' => 'fatal', 'file' => array( 'ext' => '.log', 'name' => 'sugarcrm', 'dateFormat' => '%c', 'maxSize' => '10MB', 'dirPerm' => 0770, 'filePerm' => 0660, ), ), 'cache_dir' => 'cache/', ); CONFIGEOF # Verify config.php has content if [ -s "$CONFIG_PHP" ]; then echo "config.php created successfully ($(wc -l < "$CONFIG_PHP") lines)" # Ensure installer_locked is true sed -i "s/'installer_locked' => *false/'installer_locked' => true/" "$CONFIG_PHP" 2>/dev/null || true if ! grep -q "installer_locked" "$CONFIG_PHP"; then echo " 'installer_locked' => true," >> "$CONFIG_PHP" fi # Insert adminwizard into DB for API access php -r " \$c = @mysql_connect('$DB_HOST_NAME:$DB_TCP_PORT', '$DB_USER_NAME', '$DB_PASSWORD'); if (\$c) { mysql_select_db('$DATABASE_NAME', \$c); mysql_query(\"INSERT IGNORE INTO config (category, name, value) VALUES ('system', 'adminwizard', '{\\\"completed\\\":true}')\", \$c); mysql_close(\$c); } " 2>/dev/null || true else echo "ERROR: config.php is empty!" fi else echo "SugarCRM already configured ($(wc -l < "$CONFIG_PHP") lines)" # Ensure installer_locked is true if grep -q "'installer_locked' => false" "$CONFIG_PHP" 2>/dev/null; then sed -i "s/'installer_locked' => false/'installer_locked' => true/" "$CONFIG_PHP" echo "Fixed installer_locked" fi # Ensure adminwizard is in config if ! grep -q adminwizard "$CONFIG_PHP" 2>/dev/null; then sed -i "/'site_url' =>/a\\ 'adminwizard' => array('completed' => true)," "$CONFIG_PHP" 2>/dev/null || true echo "Admin Wizard disabled" fi fi # Clean up rm -f /var/www/html/config_si.php # Start cron /usr/sbin/cron echo "Setup complete. SugarCRM 6.5.26 CE ready." # Bring Apache to foreground wait $APACHE_PID