2017-12-25 11:43:06 +01:00
|
|
|
#!/bin/sh
|
2017-11-28 11:00:11 +01:00
|
|
|
|
2017-12-04 17:48:37 +01:00
|
|
|
SOURCE_DIR=$(realpath $(dirname "${0}"))/crisiscleanup
|
2017-11-28 11:00:11 +01:00
|
|
|
|
2018-01-23 21:27:18 +01:00
|
|
|
# Check prerequisites
|
2018-01-30 17:34:20 +01:00
|
|
|
docker image ls | grep -q postfix || $(realpath $(dirname "${0}"))/postfix.sh
|
2018-01-23 21:27:18 +01:00
|
|
|
docker image ls | grep -q postgres || $(realpath $(dirname "${0}"))/postgres.sh
|
2018-03-16 17:30:11 +01:00
|
|
|
docker image ls | grep -q ruby || $(realpath $(dirname "${0}"))/ruby.sh
|
2018-01-23 21:27:18 +01:00
|
|
|
|
2017-12-25 11:43:06 +01:00
|
|
|
# Build Docker container
|
|
|
|
docker build -t crisiscleanup ${SOURCE_DIR}
|
2017-11-28 11:00:11 +01:00
|
|
|
|
|
|
|
# Create database
|
|
|
|
export CRISISCLEANUP_PWD=$(head -c 18 /dev/urandom | base64)
|
2017-12-25 11:43:06 +01:00
|
|
|
envsubst <${SOURCE_DIR}/createdb.sql | docker exec -i postgres psql
|
|
|
|
|
|
|
|
# Copy existing config files into persistent storage
|
|
|
|
mkdir -p /srv/crisiscleanup/conf
|
|
|
|
chown 8005:8005 /srv/crisiscleanup/conf
|
2018-01-24 15:55:47 +01:00
|
|
|
docker run --rm -v /srv/crisiscleanup/conf:/mnt/conf crisiscleanup cp -rp /srv/crisiscleanup/config/. /mnt/conf
|
2017-12-25 11:43:06 +01:00
|
|
|
chown root:root /srv/crisiscleanup/conf
|
2017-11-28 11:00:11 +01:00
|
|
|
|
|
|
|
# Configure CrisisCleanup
|
|
|
|
export CRISISCLEANUP_ADMIN_USER="Admin"
|
|
|
|
export CRISISCLEANUP_ADMIN_EMAIL="admin@example.com"
|
|
|
|
export CRISISCLEANUP_ADMIN_PWD=$(head -c 12 /dev/urandom | base64)
|
2017-12-25 11:43:06 +01:00
|
|
|
envsubst <${SOURCE_DIR}/srv/crisiscleanup/conf/database.yml >/srv/crisiscleanup/conf/database.yml
|
|
|
|
cp ${SOURCE_DIR}/srv/crisiscleanup/conf/boot.rb /srv/crisiscleanup/conf/boot.rb
|
|
|
|
cp ${SOURCE_DIR}/srv/crisiscleanup/conf/initializers/devise.rb /srv/crisiscleanup/conf/initializers/devise.rb
|
|
|
|
cp ${SOURCE_DIR}/srv/crisiscleanup/conf/environments/production.rb /srv/crisiscleanup/conf/environments/production.rb
|
2017-11-28 11:00:11 +01:00
|
|
|
|
|
|
|
# Populate database
|
2017-12-25 11:43:06 +01:00
|
|
|
envsubst <${SOURCE_DIR}/srv/crisiscleanup/db/seeds.rb >/tmp/seeds.rb
|
2018-01-18 13:59:24 +01:00
|
|
|
docker run --rm -h crisiscleanup --link postgres -v /srv/crisiscleanup/conf:/srv/crisiscleanup/config crisiscleanup rake db:schema:load
|
|
|
|
docker run --rm -h crisiscleanup --link postgres -v /srv/crisiscleanup/conf:/srv/crisiscleanup/config -v /tmp/seeds.rb:/srv/crisiscleanup/db/seeds.rb crisiscleanup rake db:seed
|
2017-12-25 11:43:06 +01:00
|
|
|
rm /tmp/seeds.rb
|
2017-11-28 11:00:11 +01:00
|
|
|
|
2017-12-26 09:32:50 +01:00
|
|
|
# Create CrisisCleanup service
|
2017-12-25 11:43:06 +01:00
|
|
|
cp ${SOURCE_DIR}/etc/init.d/crisiscleanup /etc/init.d/crisiscleanup
|
2018-02-06 21:54:11 +01:00
|
|
|
rc-update add crisiscleanup
|
2017-12-25 11:43:06 +01:00
|
|
|
service crisiscleanup start
|
2017-11-28 11:00:11 +01:00
|
|
|
|
2017-12-25 11:43:06 +01:00
|
|
|
# Create nginx app definition
|
|
|
|
cp ${SOURCE_DIR}/etc/nginx/conf.d/crisiscleanup.conf /etc/nginx/conf.d/crisiscleanup.conf
|
|
|
|
service nginx reload
|
2017-11-28 11:00:11 +01:00
|
|
|
|
|
|
|
# Add portal application definition
|
2017-12-25 11:43:06 +01:00
|
|
|
portal-app-manager crisis-cleanup "https://{host}:8405/" "${CRISISCLEANUP_ADMIN_EMAIL}" "${CRISISCLEANUP_ADMIN_PWD}"
|