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
|
|
|
|
2018-10-26 15:02:11 +02:00
|
|
|
cd $(realpath $(dirname "${0}"))/install
|
2018-04-21 22:57:56 +02:00
|
|
|
|
|
|
|
# Check prerequisites
|
2018-09-13 21:30:38 +02:00
|
|
|
[ ! -e /run/openrc/started/postgres ] && service postgres start && STOP_POSTGRES=1
|
2018-04-21 22:57:56 +02:00
|
|
|
|
|
|
|
# Create databases
|
|
|
|
export OPENDATAKIT_PWD=$(head -c 18 /dev/urandom | base64)
|
2018-10-25 22:22:36 +02:00
|
|
|
envsubst <createdb.sql | lxc-attach -u 5432 -g 5432 postgres -- psql
|
2018-04-21 22:57:56 +02:00
|
|
|
|
|
|
|
# Configure OpenDataKit
|
|
|
|
mkdir -p /srv/opendatakit/conf
|
2018-09-21 15:05:48 +02:00
|
|
|
export OPENDATAKIT_ADMIN_USER=admin
|
|
|
|
export OPENDATAKIT_ADMIN_REALM=spotter
|
2018-10-25 22:22:36 +02:00
|
|
|
envsubst <srv/opendatakit/conf/jdbc.properties >/srv/opendatakit/conf/jdbc.properties
|
|
|
|
envsubst <srv/opendatakit/conf/security.properties >/srv/opendatakit/conf/security.properties
|
|
|
|
cp srv/opendatakit/conf/server.xml /srv/opendatakit/conf/server.xml
|
2018-04-21 22:57:56 +02:00
|
|
|
chown -R 8015:8015 /srv/opendatakit/conf
|
|
|
|
|
2018-09-13 21:30:38 +02:00
|
|
|
# Install service
|
2018-10-25 22:22:36 +02:00
|
|
|
cp etc/init.d/opendatakit /etc/init.d/opendatakit
|
2018-09-13 21:30:38 +02:00
|
|
|
rc-update -u
|
|
|
|
|
2018-04-21 22:57:56 +02:00
|
|
|
# Populate database
|
|
|
|
service opendatakit start
|
2018-09-13 21:30:38 +02:00
|
|
|
until grep -q 'org.apache.catalina.startup.Catalina.start' /var/log/lxc/opendatakit.log; do
|
2018-04-21 22:57:56 +02:00
|
|
|
sleep 1
|
|
|
|
done
|
2018-07-15 21:55:35 +02:00
|
|
|
service opendatakit stop
|
2018-04-21 22:57:56 +02:00
|
|
|
|
|
|
|
# Update admin account
|
|
|
|
export OPENDATAKIT_ADMIN_PWD=$(head -c 12 /dev/urandom | base64)
|
|
|
|
export OPENDATAKIT_ADMIN_SALT=$(head -c 4 /dev/urandom | hexdump -e '"%x"') # Must be 8 characters
|
|
|
|
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 " -")
|
2018-10-25 22:22:36 +02:00
|
|
|
envsubst <adminpwd.sql | lxc-attach -u 5432 -g 5432 postgres -- psql opendatakit
|
2018-09-04 21:42:26 +02:00
|
|
|
vmmgr update-login opendatakit "${OPENDATAKIT_ADMIN_USER}" "${OPENDATAKIT_ADMIN_PWD}"
|
2018-07-15 21:55:35 +02:00
|
|
|
|
2018-09-20 15:45:00 +02:00
|
|
|
# Install config update script
|
2018-10-25 22:22:36 +02:00
|
|
|
cp srv/opendatakit/update-conf.sh /srv/opendatakit/update-conf.sh
|
2018-09-20 15:45:00 +02:00
|
|
|
|
2018-07-15 21:55:35 +02:00
|
|
|
# Stop services required for build
|
2018-09-13 21:30:38 +02:00
|
|
|
[ ! -z ${STOP_POSTGRES} ] && service postgres stop
|