45 lines
1.8 KiB
Bash
45 lines
1.8 KiB
Bash
#!/bin/sh
|
|
set -e
|
|
|
|
SOURCE_DIR=$(realpath $(dirname "${0}"))/setup
|
|
|
|
# Check prerequisites
|
|
# TODO: Have setup prereqs in a manifest file
|
|
for SERVICE in postgres; do
|
|
[ ! -e /run/openrc/started/${SERVICE} ] && service ${SERVICE} start && STOP_SERVICES="${STOP_SERVICES} ${SERVICE}"
|
|
done
|
|
|
|
# Create database
|
|
export CRISISCLEANUP_PWD=$(head -c 18 /dev/urandom | base64)
|
|
envsubst <${SOURCE_DIR}/createdb.sql | lxc-attach -u 5432 -g 5432 postgres -- psql
|
|
|
|
# Copy existing config files into persistent storage
|
|
mkdir -p /srv/crisiscleanup/conf
|
|
chown 8005:8005 /srv/crisiscleanup/conf
|
|
cp -r /var/lib/lxc/crisiscleanup/crisiscleanup/srv/crisiscleanup/config/. /srv/crisiscleanup/conf
|
|
|
|
# Configure CrisisCleanup
|
|
export CRISISCLEANUP_ADMIN_USER="Admin"
|
|
export CRISISCLEANUP_ADMIN_EMAIL="admin@example.com"
|
|
export CRISISCLEANUP_ADMIN_PWD=$(head -c 12 /dev/urandom | base64)
|
|
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
|
|
vmmgr update-login crisiscleanup "${CRISISCLEANUP_ADMIN_EMAIL}" "${CRISISCLEANUP_ADMIN_PWD}"
|
|
|
|
# Populate database
|
|
envsubst <${SOURCE_DIR}/srv/crisiscleanup/db/seeds.rb >/var/lib/lxc/crisiscleanup/crisiscleanup/tmp/seeds.rb
|
|
lxc-execute crisiscleanup -- rake db:schema:load
|
|
lxc-execute crisiscleanup -- rake db:seed
|
|
rm /var/lib/lxc/crisiscleanup/crisiscleanup/tmp/seeds.rb
|
|
|
|
# Install service
|
|
cp ${SOURCE_DIR}/etc/init.d/crisiscleanup /etc/init.d/crisiscleanup
|
|
rc-update -u
|
|
|
|
# Stop services required for setup
|
|
for SERVICE in ${STOP_SERVICES}; do
|
|
service ${SERVICE} stop
|
|
done
|