2018-04-21 23:06:16 +02:00
|
|
|
#!/bin/sh
|
2018-07-15 21:55:35 +02:00
|
|
|
set -e
|
2018-04-21 23:06:16 +02:00
|
|
|
|
2018-09-13 21:52:38 +02:00
|
|
|
SOURCE_DIR=$(realpath $(dirname "${0}"))/setup
|
2018-04-21 23:06:16 +02:00
|
|
|
|
|
|
|
# Check prerequisites
|
2018-09-13 21:52:38 +02:00
|
|
|
[ ! -e /run/openrc/started/postgres ] && service postgres start && STOP_POSTGRES=1
|
2018-04-21 23:06:16 +02:00
|
|
|
|
|
|
|
# Create databases
|
|
|
|
export OPENDATAKITBUILD_PWD=$(head -c 18 /dev/urandom | base64)
|
2018-09-13 21:52:38 +02:00
|
|
|
envsubst <${SOURCE_DIR}/createdb.sql | lxc-attach -u 5432 -g 5432 postgres psql
|
2018-04-21 23:06:16 +02:00
|
|
|
|
|
|
|
# Configure OpenDataKit Build
|
|
|
|
export OPENDATAKITBUILD_COOKIE_SECRET=$(head -c 8 /dev/urandom | hexdump -e '"%x"')
|
|
|
|
mkdir -p /srv/opendatakit-build/conf
|
|
|
|
envsubst <${SOURCE_DIR}/srv/opendatakit-build/conf/config.yml >/srv/opendatakit-build/conf/config.yml
|
2018-09-13 21:52:38 +02:00
|
|
|
lxc-execute opendatakit-build -- sh -c 'cd /srv/opendatakit-build; rake db:migrate'
|
|
|
|
|
|
|
|
# Install service
|
|
|
|
cp ${SOURCE_DIR}/etc/init.d/opendatakit-build /etc/init.d/opendatakit-build
|
|
|
|
rc-update -u
|
2018-07-15 21:55:35 +02:00
|
|
|
|
|
|
|
# Stop services required for build
|
2018-09-13 21:52:38 +02:00
|
|
|
[ ! -z ${STOP_POSTGRES} ] && service postgres stop
|