2018-03-25 14:37:57 +02:00
|
|
|
#!/bin/sh
|
|
|
|
|
|
|
|
SOURCE_DIR=$(realpath $(dirname "${0}"))/odk
|
|
|
|
|
|
|
|
# Check prerequisites
|
|
|
|
docker image ls | grep -q postgres || $(realpath $(dirname "${0}"))/postgres.sh
|
|
|
|
docker image ls | grep -q postfix || $(realpath $(dirname "${0}"))/postfix.sh
|
|
|
|
docker image ls | grep -q tomcat || $(realpath $(dirname "${0}"))/tomcat.sh
|
2018-04-29 20:48:57 +02:00
|
|
|
service postgres start
|
2018-03-25 14:37:57 +02:00
|
|
|
|
|
|
|
# Build Docker container
|
|
|
|
docker build -t odk ${SOURCE_DIR}
|
2018-04-29 20:48:57 +02:00
|
|
|
cp ${SOURCE_DIR}/etc/init.d/odk /etc/init.d/odk
|
|
|
|
rc-update -u
|
2018-03-25 14:37:57 +02:00
|
|
|
|
|
|
|
# Create databases
|
|
|
|
export ODK_PWD=$(head -c 18 /dev/urandom | base64)
|
|
|
|
envsubst <${SOURCE_DIR}/createdb.sql | docker exec -i postgres psql
|
|
|
|
|
|
|
|
# Configure OpenDataKit
|
|
|
|
export ODK_ADMIN_USER=admin
|
|
|
|
export ODK_ADMIN_REALM=spotter
|
|
|
|
mkdir -p /srv/odk/conf
|
|
|
|
envsubst <${SOURCE_DIR}/srv/odk/conf/jdbc.properties >/srv/odk/conf/jdbc.properties
|
|
|
|
envsubst <${SOURCE_DIR}/srv/odk/conf/security.properties >/srv/odk/conf/security.properties
|
|
|
|
cp ${SOURCE_DIR}/srv/odk/conf/server.xml /srv/odk/conf/server.xml
|
|
|
|
cp ${SOURCE_DIR}/srv/odk/update-url.sh /srv/odk/update-url.sh
|
|
|
|
chown -R 8015:8015 /srv/odk/conf
|
|
|
|
|
2018-04-29 20:48:57 +02:00
|
|
|
# Populate database
|
2018-03-25 14:37:57 +02:00
|
|
|
service odk start
|
2018-04-29 20:48:57 +02:00
|
|
|
until docker logs odk 2>&1 | grep -q 'org.apache.catalina.startup.Catalina.start'; do
|
|
|
|
sleep 1
|
|
|
|
done
|
2018-03-25 14:37:57 +02:00
|
|
|
|
|
|
|
# Update admin account
|
|
|
|
export ODK_ADMIN_PWD=$(head -c 12 /dev/urandom | base64)
|
|
|
|
export ODK_ADMIN_SALT=$(head -c 4 /dev/urandom | hexdump -e '"%x"') # Must be 8 characters
|
|
|
|
export ODK_ADMIN_BASIC_HASH=$(echo -n "${ODK_ADMIN_PWD}{${ODK_ADMIN_SALT}}" | sha1sum | tr -d " -")
|
|
|
|
export ODK_ADMIN_DIGEST_HASH=$(echo -n "${ODK_ADMIN_USER}:${ODK_ADMIN_REALM}:${ODK_ADMIN_PWD}" | md5sum | tr -d " -")
|
|
|
|
envsubst <${SOURCE_DIR}/adminpwd.sql | docker exec -i postgres psql odk
|
2018-04-29 20:48:57 +02:00
|
|
|
spotter-appmgr update-login odk "${ODK_ADMIN_USER}" "${ODK_ADMIN_PWD}"
|