diff options
Diffstat (limited to 'bin')
-rwxr-xr-x | bin/docker-cobrand | 16 | ||||
-rw-r--r-- | bin/docker.preinit | 45 | ||||
-rwxr-xr-x | bin/install-as-user | 23 | ||||
-rw-r--r-- | bin/site-specific-install.sh | 26 |
4 files changed, 94 insertions, 16 deletions
diff --git a/bin/docker-cobrand b/bin/docker-cobrand new file mode 100755 index 000000000..05c02c1ce --- /dev/null +++ b/bin/docker-cobrand @@ -0,0 +1,16 @@ +#!/bin/bash + +set -e +shopt -s nullglob + +LN_FLAGS="-s -f -v" +cobrand="/var/www/fixmystreet/cobrand" +FMS="/var/www/fixmystreet/fixmystreet" + +PATHS=(perllib/FixMyStreet/Cobrand templates/web templates/email web/cobrands conf) + +for path in "${PATHS[@]}"; do + for c in $cobrand/$path/*; do + ln $LN_FLAGS $c $FMS/$path + done +done diff --git a/bin/docker.preinit b/bin/docker.preinit new file mode 100644 index 000000000..459e89de2 --- /dev/null +++ b/bin/docker.preinit @@ -0,0 +1,45 @@ +#!/bin/sh + +# Things to do before starting FixMyStreet in Docker + +# Make sure that the Postgres environment is up and running. +echo "Testing connection to ${FMS_DB_HOST}." +while ! pg_isready -h $FMS_DB_HOST >/dev/null 2>&1 ; do + echo "Still waiting for ${FMS_DB_HOST}..." + sleep 1 +done +echo "Done." + +# If there's a password for the postgres user, set it up for root and see if we need +# to create an FMS user. This is intended for use when using a dedicated local postgres +# container. If this variable doesn't exist, we're going to assume that the FMS user +# has been created already so the stuff below will work. +if [ -n "$POSTGRES_PASSWORD" ]; then + echo "${FMS_DB_HOST}:*:*:postgres:${POSTGRES_PASSWORD}" > /root/.pgpass + chmod 0600 /root/.pgpass + psql -h $FMS_DB_HOST -U postgres postgres -c "create user \"${FMS_DB_USER}\" with CREATEDB password '${FMS_DB_PASS}'" || true +fi + +# Set up a .pgpass for the FMS user. Note that we're assuming the same name for +# both the local shell account and the DB user. +su ${FMS_DB_USER} -c "echo \"${FMS_DB_HOST}:*:*:${FMS_DB_USER}:${FMS_DB_PASS}\" > /home/${FMS_DB_USER}/.pgpass" +chmod 0600 /home/${FMS_DB_USER}/.pgpass + +# If the FMS database doesn't exist, try to create it. +if ! su $FMS_DB_USER -c "psql -h $FMS_DB_HOST -U $FMS_DB_USER -l | egrep \"^ *${FMS_DB_NAME} *\|\" > /dev/null" ; then + su $FMS_DB_USER -c "createdb -h $FMS_DB_HOST -U $FMS_DB_USER --owner \"$FMS_DB_USER\" \"$FMS_DB_NAME\"" +fi + +# Slot in cobrand, if one is present +su $FMS_DB_USER -c "${FMS_ROOT}/bin/docker-cobrand" + +# Ensure things are up to date - schema, CSS, etc +su $FMS_DB_USER -c "${FMS_ROOT}/script/update" + +# Update reports +su $FMS_DB_USER -c "${FMS_ROOT}/bin/update-all-reports" + +# If the right environment variables are present, set up a FMS superuser account. +if [ -n "$SUPERUSER_PASSWORD" ] && [ -n "$SUPERUSER_EMAIL" ]; then + su $FMS_DB_USER -c "${FMS_ROOT}/bin/createsuperuser $SUPERUSER_EMAIL $SUPERUSER_PASSWORD" +fi diff --git a/bin/install-as-user b/bin/install-as-user index e42401758..7e2a0bd74 100755 --- a/bin/install-as-user +++ b/bin/install-as-user @@ -25,6 +25,8 @@ misuse() { } [ -z "$DEVELOPMENT_INSTALL" ] && misuse DEVELOPMENT_INSTALL +[ -z "$DOCKER" ] && misuse DOCKER +[ -z "$INSTALL_DB" ] && misuse INSTALL_DB DB_NAME="fixmystreet" @@ -92,19 +94,20 @@ then fi echo $DONE_MSG -# Create the database if it doesn't exist: -echo -n "Setting up database... " -if ! psql -l | egrep "^ *$DB_NAME *\|" > /dev/null -then - createdb --owner "$UNIX_USER" "$DB_NAME" - echo 'CREATE LANGUAGE plpgsql;' | psql -U "$UNIX_USER" "$DB_NAME" || true +if [ $INSTALL_DB = true ]; then + # Create the database if it doesn't exist: + echo -n "Setting up database... " + if ! psql -l | egrep "^ *$DB_NAME *\|" > /dev/null + then + createdb --owner "$UNIX_USER" "$DB_NAME" + echo 'CREATE LANGUAGE plpgsql;' | psql -U "$UNIX_USER" "$DB_NAME" || true + fi + bin/update-schema --commit + bin/update-all-reports + echo $DONE_MSG fi -bin/update-schema --commit -echo $DONE_MSG # Generate po and mo files (these invocations taken from Kagee's script): echo "Creating locale .mo files" commonlib/bin/gettext-makemo FixMyStreet echo $DONE_MSG - -bin/update-all-reports diff --git a/bin/site-specific-install.sh b/bin/site-specific-install.sh index a92f92ef5..4d7f05f1e 100644 --- a/bin/site-specific-install.sh +++ b/bin/site-specific-install.sh @@ -26,27 +26,41 @@ misuse() { [ -z "$DISTRIBUTION" ] && misuse DISTRIBUTION [ -z "$VERSION" ] && misuse VERSION [ -z "$DEVELOPMENT_INSTALL" ] && misuse DEVELOPMENT_INSTALL +[ -z "$DOCKER" ] && misuse DOCKER +[ -z "$INSTALL_DB" ] && misuse INSTALL_DB +[ -z "$INSTALL_POSTFIX" ] && misuse INSTALL_POSTFIX add_locale cy_GB add_locale nb_NO add_locale de_CH -install_postfix +if [ $INSTALL_POSTFIX = true ]; then + install_postfix +fi if [ ! "$DEVELOPMENT_INSTALL" = true ]; then - install_nginx - add_website_to_nginx + if [ ! "$DOCKER" = true ]; then + install_nginx + add_website_to_nginx + fi # Check out the current released version su -l -c "cd '$REPOSITORY' && git checkout '$VERSION' && git submodule update" "$UNIX_USER" fi +# Create a log directoryfor Docker builds - this is normally done above. +if [ $DOCKER = true ]; then + make_log_directory +fi + install_website_packages su -l -c "touch '$DIRECTORY/admin-htpasswd'" "$UNIX_USER" -add_postgresql_user +if [ $INSTALL_DB = true ]; then + add_postgresql_user +fi -export DEVELOPMENT_INSTALL +export DEVELOPMENT_INSTALL DOCKER INSTALL_DB su -c "$REPOSITORY/bin/install-as-user '$UNIX_USER' '$HOST' '$DIRECTORY'" "$UNIX_USER" if [ ! "$DEVELOPMENT_INSTALL" = true ]; then @@ -61,7 +75,7 @@ then overwrite_rc_local fi -if [ ! "$DEVELOPMENT_INSTALL" = true ]; then +if [ ! "$DEVELOPMENT_INSTALL" = true ] && [ ! "$DOCKER" = true ]; then # Tell the user what to do next: echo Installation complete - you should now be able to view the site at: |