Spotter-VM/lxc-apps/opendatakit/install.sh

57 lines
2.6 KiB
Bash
Raw Normal View History

2018-04-21 22:57:56 +02:00
#!/bin/sh
2018-10-28 16:04:11 +01:00
set -ev
2018-04-21 22:57:56 +02:00
2020-03-21 22:42:35 +01:00
# Volumes
POSTGRES_DATA="${VOLUMES_DIR}/opendatakit/postgres_data"
ODK_CONF="${VOLUMES_DIR}/opendatakit/odk_conf"
ODKBUILD_CONF="${VOLUMES_DIR}/opendatakit/odkbuild_conf"
2019-10-05 14:37:43 +02:00
# Create Postgres instance
2020-03-21 22:42:35 +01:00
install -o 105432 -g 105432 -m 700 -d ${POSTGRES_DATA}
spoc-container exec opendatakit-postgres -- initdb -D /var/lib/postgresql
2019-10-05 14:37:43 +02:00
# Configure Postgres
2020-03-21 22:42:35 +01:00
install -o 105432 -g 105432 -m 600 postgres_data/postgresql.conf ${POSTGRES_DATA}/postgresql.conf
install -o 105432 -g 105432 -m 600 postgres_data/pg_hba.conf ${POSTGRES_DATA}/pg_hba.conf
2018-04-21 22:57:56 +02:00
# Create databases
2019-06-05 18:55:15 +02:00
export OPENDATAKIT_PWD=$(head -c 18 /dev/urandom | base64 | tr -d '+/=')
2019-10-05 14:37:43 +02:00
export OPENDATAKITBUILD_PWD=$(head -c 18 /dev/urandom | base64 | tr -d '+/=')
2020-03-21 22:42:35 +01:00
spoc-container start opendatakit-postgres
envsubst <createdb.sql | spoc-container exec opendatakit-postgres -- psql
2018-04-21 22:57:56 +02:00
# Configure OpenDataKit
2018-09-21 15:05:48 +02:00
export OPENDATAKIT_ADMIN_USER=admin
export OPENDATAKIT_ADMIN_REALM=spotter
2020-03-21 22:42:35 +01:00
install -o 108080 -g 108080 -m 750 -d ${ODK_CONF}
envsubst <odk_conf/jdbc.properties | install -o 108080 -g 108080 -m 640 /dev/stdin ${ODK_CONF}/jdbc.properties
envsubst <odk_conf/security.properties | install -o 108080 -g 108080 -m 640 /dev/stdin ${ODK_CONF}/security.properties
install -o 108080 -g 108080 -m 640 odk_conf/server.xml ${ODK_CONF}/server.xml
2019-10-05 14:37:43 +02:00
# Configure OpenDataKit Build
export OPENDATAKITBUILD_COOKIE_SECRET=$(head -c 8 /dev/urandom | hexdump -e '"%x"')
2020-03-21 22:42:35 +01:00
install -o 108080 -g 108080 -m 750 -d ${ODKBUILD_CONF}
envsubst <odkbuild_conf/config.yml | install -o 108080 -g 108080 -m 640 /dev/stdin ${ODKBUILD_CONF}/config.yml
spoc-container exec opendatakit-build -- sh -c 'cd /srv/opendatakit-build; rake db:migrate'
2018-09-13 21:30:38 +02:00
2018-04-21 22:57:56 +02:00
# Populate database
2020-03-21 22:42:35 +01:00
spoc-container start opendatakit
until grep -q 'org.apache.catalina.startup.Catalina.start Server startup' /var/log/spoc/opendatakit.log; do
2018-04-21 22:57:56 +02:00
sleep 1
done
2020-03-21 22:42:35 +01:00
spoc-container stop opendatakit
2018-04-21 22:57:56 +02:00
# Update admin account
2019-06-05 18:55:15 +02:00
export OPENDATAKIT_ADMIN_PWD=$(head -c 12 /dev/urandom | base64 | tr -d '+/=')
2019-10-05 14:37:43 +02:00
export OPENDATAKIT_ADMIN_SALT=$(head -c 4 /dev/urandom | hexdump -e '"%x"') # Must be exactly 8 characters
2018-04-21 22:57:56 +02:00
export OPENDATAKIT_ADMIN_BASIC_HASH=$(echo -n "${OPENDATAKIT_ADMIN_PWD}{${OPENDATAKIT_ADMIN_SALT}}" | sha1sum | tr -d " -")
export OPENDATAKIT_ADMIN_DIGEST_HASH=$(echo -n "${OPENDATAKIT_ADMIN_USER}:${OPENDATAKIT_ADMIN_REALM}:${OPENDATAKIT_ADMIN_PWD}" | md5sum | tr -d " -")
2020-03-21 22:42:35 +01:00
envsubst <adminpwd.sql | spoc-container exec opendatakit-postgres -- psql opendatakit
2019-10-05 14:37:43 +02:00
# Stop services required for setup
2020-03-21 22:42:35 +01:00
spoc-container stop opendatakit-postgres
2018-10-28 19:50:35 +01:00
# Register application
2019-02-26 21:12:41 +01:00
vmmgr register-app opendatakit odk "${OPENDATAKIT_ADMIN_USER}" "${OPENDATAKIT_ADMIN_PWD}"
2019-10-05 14:37:43 +02:00
vmmgr register-app opendatakit-build odkbuild