|
| 1 | +#!/bin/bash |
| 2 | + |
| 3 | +WEB_ROOT=/var/www/html |
| 4 | + |
| 5 | +function init_settings { |
| 6 | + # Initialize settings.php file |
| 7 | + cp "$WEB_ROOT/sites/default/default.settings.php" "$WEB_ROOT/sites/default/settings.php" |
| 8 | + chmod a+w "$WEB_ROOT/sites/default/settings.php" |
| 9 | + chmod a+w "$WEB_ROOT/sites/default" |
| 10 | + setenforce 0 |
| 11 | +} |
| 12 | + |
| 13 | +function init_db { |
| 14 | + # is a mysql or postgresql database linked? |
| 15 | + # requires that the mysql or postgresql containers have exposed |
| 16 | + # port 3306 and 5432 respectively. |
| 17 | + if [ -n "${MYSQL_PORT_3306_TCP_ADDR}" ]; then |
| 18 | + DB_TYPE=mysql |
| 19 | + DB_HOST=${DB_HOST:-${MYSQL_PORT_3306_TCP_ADDR}} |
| 20 | + DB_PORT=${DB_PORT:-${MYSQL_PORT_3306_TCP_PORT}} |
| 21 | + DB_PASS=${DB_PASS:-${MYSQL_ENV_MYSQL_PASSWORD}} |
| 22 | + DB_USER=${DB_USER:-${MYSQL_ENV_MYSQL_USER}} |
| 23 | + DB_NAME=${DB_NAME:-${MYSQL_ENV_MYSQL_DATABASE}} |
| 24 | + DB_DRIVER="mysql" |
| 25 | + elif [ -n "${MARIADB_PORT_3306_TCP_ADDR}" ]; then |
| 26 | + DB_TYPE=mysql |
| 27 | + DB_HOST=${DB_HOST:-${MARIADB_PORT_3306_TCP_ADDR}} |
| 28 | + DB_PORT=${DB_PORT:-${MARIADB_PORT_3306_TCP_PORT}} |
| 29 | + DB_PASS=${DB_PASS:-${MARIADB_ENV_MYSQL_PASSWORD}} |
| 30 | + DB_USER=${DB_USER:-${MARIADB_ENV_MYSQL_USER}} |
| 31 | + DB_NAME=${DB_NAME:-${MARIADB_ENV_MYSQL_DATABASE}} |
| 32 | + DB_DRIVER="mysql" |
| 33 | + |
| 34 | +# elif [ -n "${POSTGRESQL_PORT_5432_TCP_ADDR}" ]; then |
| 35 | +# DB_TYPE=postgres |
| 36 | +# DB_HOST=${DB_HOST:-${POSTGRESQL_PORT_5432_TCP_ADDR}} |
| 37 | +# DB_PORT=${DB_PORT:-${POSTGRESQL_PORT_5432_TCP_PORT}} |
| 38 | +# # support for linked official postgres image |
| 39 | +# DB_USER=${DB_USER:-${POSTGRESQL_ENV_POSTGRES_USER}} |
| 40 | +# DB_PASS=${DB_PASS:-${POSTGRESQL_ENV_POSTGRES_PASS}} |
| 41 | +# DB_NAME=${DB_NAME:-${DB_USER}} |
| 42 | +# DB_DRIVER="pgsql" |
| 43 | + elif [ -n "${DB_DRIVER}" ] || [ -n "${DB_NAME}" ] || [ -n "${DB_HOST}"] || [ -n "${DB_USER}" ] || [ -n "${DB_PASS}" ]; then |
| 44 | + echo "Error: DB must be alias'ed correctly, or all DB parameters must be specified." |
| 45 | + exit 1 |
| 46 | + fi |
| 47 | + |
| 48 | + cat >> "$WEB_ROOT/sites/default/settings.php" <<- EOFDBSETTINGS |
| 49 | +\$databases['default']['default'] = array( |
| 50 | + 'driver' => '$DB_DRIVER', |
| 51 | + 'database' => "$DB_NAME", |
| 52 | + 'username' => "$DB_USER", |
| 53 | + 'password' => "$DB_PASS", |
| 54 | + 'host' => "$DB_HOST", |
| 55 | + 'prefix' => "$DB_PREFIX", |
| 56 | + ); |
| 57 | +EOFDBSETTINGS |
| 58 | +} |
| 59 | + |
| 60 | +function init_apache_php_settings { |
| 61 | + |
| 62 | + PHP_MEMORY_LIMIT=${PHP_MEMORY_LIMIT:-"1024M"} |
| 63 | + PHP_MAX_EXECUTION_TIME=${PHP_MAX_EXECUTION_TIME:-"900"} |
| 64 | + PHP_POST_MAX_SIZE=${PHP_POST_MAX_SIZE:-"256M"} |
| 65 | + PHP_UPLOAD_MAX_FILE_SIZE=${PHP_UPLOAD_MAX_FILE_SIZE:-"256M"} |
| 66 | + PHP_MAX_FILE_UPLOADS=${PHP_MAX_FILE_UPLOADS:-"100"} |
| 67 | + sed -i \ |
| 68 | + -e "s/^memory_limit.*$/memory_limit = $PHP_MEMORY_LIMIT/g" \ |
| 69 | + -e "s/^max_execution_time.*$/max_execution_time = $PHP_MAX_EXECUTION_TIME/g" \ |
| 70 | + -e "s/^session.save_handler.*$/session.save_handler = memcache/g" \ |
| 71 | + -e "s/^post_max_size.*$/post_max_size = $PHP_POST_MAX_SIZE/g" \ |
| 72 | + -e "s/^upload_max_file_size.*$/upload_max_file_size = $PHP_UPLOAD_MAX_FILE_SIZE/g" \ |
| 73 | + -e "s/^max_file_uploads.*$/max_file_uploads = $PHP_MAX_FILE_UPLOADS/g" \ |
| 74 | + /etc/php5/apache2/php.ini |
| 75 | + |
| 76 | +} |
| 77 | + |
| 78 | +function fix_perm { |
| 79 | + chmod 644 "$WEB_ROOT/sites/default/settings.php" |
| 80 | + chmod 755 "$WEB_ROOT/sites/default" |
| 81 | +} |
| 82 | + |
| 83 | +if [ -e "/.bootstrap" ] ; then |
| 84 | + echo ".bootstrap file found. skipping initial configuration." |
| 85 | +else |
| 86 | + echo "Bootstrapping..." |
| 87 | + init_settings |
| 88 | + init_db |
| 89 | + |
| 90 | + touch /.bootstrap |
| 91 | +fi |
| 92 | + |
| 93 | +if [ -e "/.bootstrap" ] ; then |
| 94 | + supervisord |
| 95 | +fi |
0 commit comments