3 USERNAME="${1:-docker}"
5 echo "[$(date)] Bootstrapping the Test container..."
8 # Perform program exit housekeeping
10 echo "[$(date)] Stopping the Web server"
13 echo "[$(date)] Stopping Privoxy"
16 echo "[$(date)] Stopping FPM"
19 echo "[$(date)] Exiting"
23 # Fix UID & GID for user
25 echo "[$(date)] Fixing filesystem permissions..."
27 ORIGPASSWD=$(cat /etc/passwd | grep "^${USERNAME}:")
28 ORIG_UID=$(echo "$ORIGPASSWD" | cut -f3 -d:)
29 ORIG_GID=$(echo "$ORIGPASSWD" | cut -f4 -d:)
30 CONTAINER_USER_HOME=$(echo "$ORIGPASSWD" | cut -f6 -d:)
31 CONTAINER_USER_UID=${CONTAINER_USER_UID:=$ORIG_UID}
32 CONTAINER_USER_GID=${CONTAINER_USER_GID:=$ORIG_GID}
34 if [ "$CONTAINER_USER_UID" != "$ORIG_UID" -o "$CONTAINER_USER_GID" != "$ORIG_GID" ]; then
35 groupmod -g "$CONTAINER_USER_GID" "${USERNAME}"
36 usermod -u "$CONTAINER_USER_UID" -g "$CONTAINER_USER_GID" "${USERNAME}"
38 if [ $(stat -c '%u' "${CONTAINER_USER_HOME}") != "${CONTAINER_USER_UID}" -o $(stat -c '%g' "${CONTAINER_USER_HOME}") != "${CONTAINER_USER_GID}" ]; then
39 chown "${CONTAINER_USER_UID}":"${CONTAINER_USER_GID}" "${CONTAINER_USER_HOME}"
40 chown -R "${CONTAINER_USER_UID}":"${CONTAINER_USER_GID}" "${CONTAINER_USER_HOME}"/.*
42 # @todo do the same chmod for ${TESTS_ROOT_DIR}, if it's not within CONTAINER_USER_HOME
44 echo "[$(date)] Fixing Apache configuration..."
46 sed -e "s?^export TESTS_ROOT_DIR=.*?export TESTS_ROOT_DIR=${TESTS_ROOT_DIR}?g" --in-place /etc/apache2/envvars
47 sed -e "s?^export APACHE_RUN_USER=.*?export APACHE_RUN_USER=${USERNAME}?g" --in-place /etc/apache2/envvars
48 sed -e "s?^export APACHE_RUN_GROUP=.*?export APACHE_RUN_GROUP=${USERNAME}?g" --in-place /etc/apache2/envvars
50 echo "[$(date)] Fixing FPM configuration..."
52 FPMCONF="/etc/php/$(php -r 'echo implode(".",array_slice(explode(".",PHP_VERSION),0,2));' 2>/dev/null)/fpm/pool.d/www.conf"
53 sed -e "s?^user =.*?user = ${USERNAME}?g" --in-place "${FPMCONF}"
54 sed -e "s?^group =.*?group = ${USERNAME}?g" --in-place "${FPMCONF}"
55 sed -e "s?^listen.owner =.*?listen.owner = ${USERNAME}?g" --in-place "${FPMCONF}"
56 sed -e "s?^listen.group =.*?listen.group = ${USERNAME}?g" --in-place "${FPMCONF}"
58 echo "[$(date)] Running Composer..."
60 # @todo if there is a composer.lock file present, there are chances it might be a leftover from when running the
61 # container using a different php version. We should then back it up / do some symlink magic to make sure that
62 # it matches the current php version and a hash of composer.json...
63 sudo "${USERNAME}" -c "cd ${TESTS_ROOT_DIR} && composer install"
67 echo "[$(date)] Starting FPM..."
70 echo "[$(date)] Starting the Web server..."
73 echo "[$(date)] Starting Privoxy..."