fix: rewrite init.sh - create config.php directly, fix envtemplate perms
Some checks failed
Docker Build & Push SugarCRM 6.5 CE / build-and-push (push) Failing after 1m6s
Some checks failed
Docker Build & Push SugarCRM 6.5 CE / build-and-push (push) Failing after 1m6s
This commit is contained in:
@@ -42,7 +42,7 @@ RUN docker-php-ext-configure imap --with-kerberos --with-imap-ssl && \
|
|||||||
COPY config_override.php.pyt /usr/local/src/config_override.php.pyt
|
COPY config_override.php.pyt /usr/local/src/config_override.php.pyt
|
||||||
COPY envtemplate.py /usr/local/bin/envtemplate.py
|
COPY envtemplate.py /usr/local/bin/envtemplate.py
|
||||||
COPY init.sh /usr/local/bin/init.sh
|
COPY init.sh /usr/local/bin/init.sh
|
||||||
RUN chmod u+x /usr/local/bin/init.sh
|
RUN chmod +x /usr/local/bin/envtemplate.py /usr/local/bin/init.sh
|
||||||
|
|
||||||
# Cron
|
# Cron
|
||||||
COPY crons.conf /root/crons.conf
|
COPY crons.conf /root/crons.conf
|
||||||
|
|||||||
201
init.sh
201
init.sh
@@ -1,9 +1,9 @@
|
|||||||
#!/bin/sh
|
#!/bin/sh
|
||||||
# SugarCRM 6.5 CE Docker Entrypoint
|
# SugarCRM 6.5 CE Docker Entrypoint
|
||||||
# ==================================
|
# ==================================
|
||||||
# Pitfalls documented (see README.md Technical Notes)
|
# Creates config.php directly (bypasses broken silent installer)
|
||||||
|
|
||||||
# Resolve DB connection from env/linked container
|
# Resolve DB connection from env
|
||||||
if [ -z "$DB_HOST_NAME" ]; then
|
if [ -z "$DB_HOST_NAME" ]; then
|
||||||
export DB_HOST_NAME=${DB_PORT_3306_TCP_ADDR:-db}
|
export DB_HOST_NAME=${DB_PORT_3306_TCP_ADDR:-db}
|
||||||
fi
|
fi
|
||||||
@@ -20,14 +20,15 @@ if [ -z "$DATABASE_NAME" ]; then
|
|||||||
export DATABASE_NAME=${DB_ENV_MYSQL_DATABASE:-sugarcrm}
|
export DATABASE_NAME=${DB_ENV_MYSQL_DATABASE:-sugarcrm}
|
||||||
fi
|
fi
|
||||||
|
|
||||||
/usr/local/bin/envtemplate.py -i /usr/local/src/config_override.php.pyt -o /var/www/html/config_override.php
|
# 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 in background for silent install via HTTP
|
# Start Apache
|
||||||
echo "Starting Apache (background)..."
|
echo "Starting Apache (background)..."
|
||||||
apachectl -DFOREGROUND &
|
apachectl -DFOREGROUND &
|
||||||
APACHE_PID=$!
|
APACHE_PID=$!
|
||||||
|
|
||||||
# Wait for Apache to be ready
|
# Wait for Apache
|
||||||
echo "Waiting for Apache..."
|
echo "Waiting for Apache..."
|
||||||
for i in $(seq 1 30); do
|
for i in $(seq 1 30); do
|
||||||
if curl -s http://localhost/ >/dev/null 2>&1; then
|
if curl -s http://localhost/ >/dev/null 2>&1; then
|
||||||
@@ -37,91 +38,151 @@ for i in $(seq 1 30); do
|
|||||||
sleep 1
|
sleep 1
|
||||||
done
|
done
|
||||||
|
|
||||||
# Run silent install if not already installed
|
# Wait for MySQL
|
||||||
if [ ! -f /var/www/html/config.php ]; then
|
echo "Waiting for MySQL..."
|
||||||
echo "Running SugarCRM Silent Install..."
|
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
|
||||||
|
|
||||||
cat > /var/www/html/config_si.php << SIEOF
|
# 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
|
||||||
<?php
|
<?php
|
||||||
\$sugar_config_si = array(
|
// SugarCRM 6.5 CE Configuration
|
||||||
'setup_db_host_name' => 'DB_HOST',
|
// Auto-generated by Docker entrypoint
|
||||||
'setup_db_database_name' => 'DB_NAME',
|
\$sugar_config = array(
|
||||||
'setup_db_admin_user_name' => 'DB_USER',
|
'adminwizard' => array('completed' => true),
|
||||||
'setup_db_admin_password' => 'DB_PASS',
|
'dbconfig' => array(
|
||||||
'setup_db_type' => 'mysql',
|
'db_host_name' => '$DB_HOST_NAME',
|
||||||
'setup_db_port_num' => 'DB_PORT',
|
'db_host_instance' => 'SQLEXPRESS',
|
||||||
'setup_db_drop_tables' => false,
|
'db_user_name' => '$DB_USER_NAME',
|
||||||
'setup_db_create_database' => false,
|
'db_password' => '$DB_PASSWORD',
|
||||||
'setup_db_create_sugarsales_user' => false,
|
'db_name' => '$DATABASE_NAME',
|
||||||
'setup_license_key' => 'free',
|
'db_type' => 'mysql',
|
||||||
'setup_license_accept' => true,
|
'db_port' => '$DB_TCP_PORT',
|
||||||
'setup_site_url' => 'http://localhost:2080',
|
'db_manager' => 'MysqlManager',
|
||||||
'setup_system_name' => 'SugarCRM 6.5 CE',
|
),
|
||||||
'setup_site_admin_user_name' => 'admin',
|
'dbconfigoption' => array(
|
||||||
'setup_site_admin_password' => 'admin123',
|
'persistent' => true,
|
||||||
'setup_site_admin_password_retype' => 'admin123',
|
'autofree' => false,
|
||||||
'demoData' => 'no',
|
'debug' => 0,
|
||||||
'dbUSRData' => 'create',
|
'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/',
|
||||||
);
|
);
|
||||||
SIEOF
|
require_once('include/SugarObjects/VardefManager.php');
|
||||||
|
require_once('modules/Administration/Administration.php');
|
||||||
|
CONFIGEOF
|
||||||
|
|
||||||
sed -i "s/DB_HOST/$DB_HOST_NAME/g" /var/www/html/config_si.php
|
# Verify config.php has content
|
||||||
sed -i "s/DB_NAME/$DATABASE_NAME/g" /var/www/html/config_si.php
|
if [ -s "$CONFIG_PHP" ]; then
|
||||||
sed -i "s/DB_USER/$DB_USER_NAME/g" /var/www/html/config_si.php
|
echo "config.php created successfully ($(wc -l < "$CONFIG_PHP") lines)"
|
||||||
sed -i "s/DB_PASS/$DB_PASSWORD/g" /var/www/html/config_si.php
|
|
||||||
sed -i "s/DB_PORT/$DB_TCP_PORT/g" /var/www/html/config_si.php
|
|
||||||
|
|
||||||
# Wait for MySQL (using PHP socket check - no mysqladmin in container)
|
# Ensure installer_locked is true
|
||||||
echo "Waiting for MySQL..."
|
sed -i "s/'installer_locked' => *false/'installer_locked' => true/" "$CONFIG_PHP" 2>/dev/null || true
|
||||||
for i in $(seq 1 30); do
|
if ! grep -q "installer_locked" "$CONFIG_PHP"; then
|
||||||
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 " 'installer_locked' => true," >> "$CONFIG_PHP"
|
||||||
echo "MySQL is ready"
|
|
||||||
break
|
|
||||||
fi
|
fi
|
||||||
sleep 2
|
|
||||||
done
|
|
||||||
|
|
||||||
# Run silent install via HTTP
|
# Insert adminwizard into DB for API access
|
||||||
echo "Executing silent install..."
|
|
||||||
curl -s "http://localhost/install.php?goto=SilentInstall&cli=true" > /dev/null 2>&1
|
|
||||||
|
|
||||||
if [ -f /var/www/html/config.php ]; then
|
|
||||||
echo "Silent install complete"
|
|
||||||
|
|
||||||
# Fix: installer_locked=true to prevent AdminWizard blocking API
|
|
||||||
sed -i "s/'installer_locked' => false/'installer_locked' => true/" /var/www/html/config.php 2>/dev/null || true
|
|
||||||
|
|
||||||
# Skip Admin Wizard in config.php
|
|
||||||
sed -i "/'site_url' =>/a\\
|
|
||||||
'adminwizard' => array('completed' => true)," /var/www/html/config.php 2>/dev/null || true
|
|
||||||
|
|
||||||
# Skip Admin Wizard in database (pitfall: needed for API access after restart)
|
|
||||||
php -r "
|
php -r "
|
||||||
\$c = @mysql_connect('$DB_HOST_NAME:$DB_TCP_PORT', '$DB_USER_NAME', '$DB_PASSWORD');
|
\$c = @mysql_connect('$DB_HOST_NAME:$DB_TCP_PORT', '$DB_USER_NAME', '$DB_PASSWORD');
|
||||||
if (\$c) {
|
if (\$c) {
|
||||||
mysql_select_db('$DATABASE_NAME', \$c);
|
mysql_select_db('$DATABASE_NAME', \$c);
|
||||||
mysql_query(\"INSERT INTO config (category, name, value) VALUES ('system', 'adminwizard', '{\\\"completed\\\":true}')\", \$c);
|
mysql_query(\"INSERT IGNORE INTO config (category, name, value) VALUES ('system', 'adminwizard', '{\\\"completed\\\":true}')\", \$c);
|
||||||
mysql_close(\$c);
|
mysql_close(\$c);
|
||||||
}
|
}
|
||||||
" 2>/dev/null || true
|
" 2>/dev/null || true
|
||||||
|
|
||||||
echo "Admin Wizard disabled"
|
|
||||||
else
|
else
|
||||||
echo "WARNING: config.php was not created! Check install."
|
echo "ERROR: config.php is empty!"
|
||||||
fi
|
fi
|
||||||
else
|
else
|
||||||
echo "SugarCRM already installed"
|
echo "SugarCRM already configured ($(wc -l < "$CONFIG_PHP") lines)"
|
||||||
|
|
||||||
# Ensure installer_locked is true (idempotent restart fix)
|
# Ensure installer_locked is true
|
||||||
if grep -q "'installer_locked' => false" /var/www/html/config.php 2>/dev/null; then
|
if grep -q "'installer_locked' => false" "$CONFIG_PHP" 2>/dev/null; then
|
||||||
sed -i "s/'installer_locked' => false/'installer_locked' => true/" /var/www/html/config.php
|
sed -i "s/'installer_locked' => false/'installer_locked' => true/" "$CONFIG_PHP"
|
||||||
echo "Fixed installer_locked"
|
echo "Fixed installer_locked"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Ensure Admin Wizard remains disabled
|
# Ensure adminwizard is in config
|
||||||
if ! grep -q adminwizard /var/www/html/config.php 2>/dev/null; then
|
if ! grep -q adminwizard "$CONFIG_PHP" 2>/dev/null; then
|
||||||
sed -i "/sugar_config\['site_url'\]/a\\
|
sed -i "/'site_url' =>/a\\
|
||||||
\$sugar_config['adminwizard'] = array('completed' => true);" /var/www/html/config.php 2>/dev/null || true
|
'adminwizard' => array('completed' => true)," "$CONFIG_PHP" 2>/dev/null || true
|
||||||
echo "Admin Wizard disabled"
|
echo "Admin Wizard disabled"
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
@@ -131,7 +192,7 @@ rm -f /var/www/html/config_si.php
|
|||||||
|
|
||||||
# Start cron
|
# Start cron
|
||||||
/usr/sbin/cron
|
/usr/sbin/cron
|
||||||
|
echo "Setup complete. SugarCRM 6.5.26 CE ready."
|
||||||
|
|
||||||
# Bring Apache to foreground
|
# Bring Apache to foreground
|
||||||
echo "Setup complete. SugarCRM 6.5.26 CE ready."
|
|
||||||
wait $APACHE_PID
|
wait $APACHE_PID
|
||||||
|
|||||||
Reference in New Issue
Block a user