diff --git a/00-install.sh b/00-install.sh index 7c1f637..8c9bba4 100755 --- a/00-install.sh +++ b/00-install.sh @@ -17,8 +17,8 @@ ${SOURCE_DIR}/gnuhealth.sh ${SOURCE_DIR}/kanboard.sh ${SOURCE_DIR}/mifosx.sh ${SOURCE_DIR}/motech.sh -${SOURCE_DIR}/odkbuild.sh -${SOURCE_DIR}/odk.sh +${SOURCE_DIR}/opendatakit-build.sh +${SOURCE_DIR}/opendatakit.sh ${SOURCE_DIR}/omk.sh ${SOURCE_DIR}/pandora.sh ${SOURCE_DIR}/sahana.sh diff --git a/odk.sh b/odk.sh deleted file mode 100755 index d6250bd..0000000 --- a/odk.sh +++ /dev/null @@ -1,42 +0,0 @@ -#!/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 -service postgres start - -# Build Docker container -docker build -t odk ${SOURCE_DIR} -cp ${SOURCE_DIR}/etc/init.d/odk /etc/init.d/odk -rc-update -u - -# 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 - -# Populate database -service odk start -until docker logs odk 2>&1 | grep -q 'org.apache.catalina.startup.Catalina.start'; do - sleep 1 -done - -# 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 -spotter-appmgr update-login odk "${ODK_ADMIN_USER}" "${ODK_ADMIN_PWD}" diff --git a/odk/adminpwd.sql b/odk/adminpwd.sql deleted file mode 100644 index 9424cfb..0000000 --- a/odk/adminpwd.sql +++ /dev/null @@ -1 +0,0 @@ -UPDATE _registered_users SET "BASIC_AUTH_PASSWORD" = '${ODK_ADMIN_BASIC_HASH}', "BASIC_AUTH_SALT" = '${ODK_ADMIN_SALT}', "DIGEST_AUTH_PASSWORD" = '${ODK_ADMIN_DIGEST_HASH}' WHERE "LOCAL_USERNAME" = '${ODK_ADMIN_USER}'; diff --git a/odk/createdb.sql b/odk/createdb.sql deleted file mode 100644 index e2cc678..0000000 --- a/odk/createdb.sql +++ /dev/null @@ -1,4 +0,0 @@ -CREATE ROLE odk NOSUPERUSER NOCREATEDB NOCREATEROLE NOINHERIT LOGIN ENCRYPTED PASSWORD '${ODK_PWD}'; -CREATE DATABASE odk; -REVOKE ALL ON DATABASE odk FROM public; -ALTER DATABASE odk OWNER TO odk; diff --git a/odk/etc/init.d/odk b/odk/etc/init.d/odk deleted file mode 100755 index 75fbbb0..0000000 --- a/odk/etc/init.d/odk +++ /dev/null @@ -1,31 +0,0 @@ -#!/sbin/openrc-run - -description="OpenDataKit Aggregate docker container" - -depend() { - need docker postfix postgres -} - -start() { - /usr/bin/docker run -d --rm \ - --name odk \ - -h odk \ - --link postfix \ - --link postgres \ - -v /srv/odk/conf/server.xml:/srv/tomcat/conf/server.xml \ - -v /srv/odk/conf/jdbc.properties:/srv/tomcat/webapps/aggregate/WEB-INF/classes/jdbc.properties \ - -v /srv/odk/conf/security.properties:/srv/tomcat/webapps/aggregate/WEB-INF/classes/security.properties \ - odk -} - -start_post() { - /usr/bin/spotter-appmgr register-proxy odk -} - -stop_pre() { - /usr/bin/spotter-appmgr unregister-proxy odk -} - -stop() { - /usr/bin/docker stop odk -} diff --git a/odk/srv/odk/conf/jdbc.properties b/odk/srv/odk/conf/jdbc.properties deleted file mode 100644 index 4f464ac..0000000 --- a/odk/srv/odk/conf/jdbc.properties +++ /dev/null @@ -1,6 +0,0 @@ -jdbc.driverClassName=org.postgresql.Driver -jdbc.resourceName=jdbc/odk_aggregate -jdbc.url=jdbc:postgresql://postgres/odk?autoDeserialize=true -jdbc.username=odk -jdbc.password=${ODK_PWD} -jdbc.schema=public diff --git a/odk/srv/odk/update-url.sh b/odk/srv/odk/update-url.sh deleted file mode 100755 index 1be8cc7..0000000 --- a/odk/srv/odk/update-url.sh +++ /dev/null @@ -1,5 +0,0 @@ -#!/bin/sh - -sed -i "s|\(^\s\+proxyName\).*|\1=\"${1}\"|g" /srv/odk/conf/server.xml -sed -i "s|\(^\s\+proxyPort\).*|\1=\"${2}\"|g" /srv/odk/conf/server.xml -sed -i "s|^security\.server\.securePort.*|security.server.securePort=${2}|" /srv/odk/conf/security.properties diff --git a/opendatakit.sh b/opendatakit.sh new file mode 100755 index 0000000..5244c0c --- /dev/null +++ b/opendatakit.sh @@ -0,0 +1,42 @@ +#!/bin/sh + +SOURCE_DIR=$(realpath $(dirname "${0}"))/opendatakit + +# 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 +service postgres start + +# Build Docker container +docker build -t opendatakit ${SOURCE_DIR} +cp ${SOURCE_DIR}/etc/init.d/opendatakit /etc/init.d/opendatakit +rc-update -u + +# Create databases +export OPENDATAKIT_PWD=$(head -c 18 /dev/urandom | base64) +envsubst <${SOURCE_DIR}/createdb.sql | docker exec -i postgres psql + +# Configure OpenDataKit +export OPENDATAKIT_ADMIN_USER=admin +export OPENDATAKIT_ADMIN_REALM=spotter +mkdir -p /srv/opendatakit/conf +envsubst <${SOURCE_DIR}/srv/opendatakit/conf/jdbc.properties >/srv/opendatakit/conf/jdbc.properties +envsubst <${SOURCE_DIR}/srv/opendatakit/conf/security.properties >/srv/opendatakit/conf/security.properties +cp ${SOURCE_DIR}/srv/opendatakit/conf/server.xml /srv/opendatakit/conf/server.xml +cp ${SOURCE_DIR}/srv/opendatakit/update-url.sh /srv/opendatakit/update-url.sh +chown -R 8015:8015 /srv/opendatakit/conf + +# Populate database +service opendatakit start +until docker logs opendatakit 2>&1 | grep -q 'org.apache.catalina.startup.Catalina.start'; do + sleep 1 +done + +# 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 " -") +envsubst <${SOURCE_DIR}/adminpwd.sql | docker exec -i postgres psql opendatakit +spotter-appmgr update-login opendatakit "${OPENDATAKIT_ADMIN_USER}" "${OPENDATAKIT_ADMIN_PWD}" diff --git a/odk/Dockerfile b/opendatakit/Dockerfile similarity index 88% rename from odk/Dockerfile rename to opendatakit/Dockerfile index 3d1e166..75cf273 100644 --- a/odk/Dockerfile +++ b/opendatakit/Dockerfile @@ -5,9 +5,9 @@ RUN \ # Install build dependencies apk --no-cache add --virtual .deps git git-lfs openjdk8 \ # Clone ODK aggregate - && git clone --depth 1 https://github.com/opendatakit/aggregate.git /srv/odk \ + && git clone --depth 1 https://github.com/opendatakit/aggregate.git /srv/opendatakit \ # Compile Java web archive - && cd /srv/odk \ + && cd /srv/opendatakit \ && cp gradle.properties.example gradle.properties \ && ./gradlew war \ # Deploy web archive @@ -19,7 +19,7 @@ RUN \ && chown -R odk:odk /srv/tomcat/conf /srv/tomcat/logs /srv/tomcat/temp /srv/tomcat/webapps /srv/tomcat/work \ # Cleanup && apk --no-cache del .deps \ - && rm -rf /root/.gradle /root/.java /srv/odk + && rm -rf /root/.gradle /root/.java /srv/opendatakit EXPOSE 8080 diff --git a/opendatakit/adminpwd.sql b/opendatakit/adminpwd.sql new file mode 100644 index 0000000..f5393c0 --- /dev/null +++ b/opendatakit/adminpwd.sql @@ -0,0 +1 @@ +UPDATE _registered_users SET "BASIC_AUTH_PASSWORD" = '${OPENDATAKIT_ADMIN_BASIC_HASH}', "BASIC_AUTH_SALT" = '${OPENDATAKIT_ADMIN_SALT}', "DIGEST_AUTH_PASSWORD" = '${OPENDATAKIT_ADMIN_DIGEST_HASH}' WHERE "LOCAL_USERNAME" = '${OPENDATAKIT_ADMIN_USER}'; diff --git a/opendatakit/createdb.sql b/opendatakit/createdb.sql new file mode 100644 index 0000000..897f489 --- /dev/null +++ b/opendatakit/createdb.sql @@ -0,0 +1,4 @@ +CREATE ROLE opendatakit NOSUPERUSER NOCREATEDB NOCREATEROLE NOINHERIT LOGIN ENCRYPTED PASSWORD '${OPENDATAKIT_PWD}'; +CREATE DATABASE opendatakit; +REVOKE ALL ON DATABASE opendatakit FROM public; +ALTER DATABASE opendatakit OWNER TO opendatakit; diff --git a/opendatakit/etc/init.d/opendatakit b/opendatakit/etc/init.d/opendatakit new file mode 100755 index 0000000..7b53298 --- /dev/null +++ b/opendatakit/etc/init.d/opendatakit @@ -0,0 +1,31 @@ +#!/sbin/openrc-run + +description="OpenDataKit Aggregate docker container" + +depend() { + need docker postfix postgres +} + +start() { + /usr/bin/docker run -d --rm \ + --name opendatakit \ + -h opendatakit \ + --link postfix \ + --link postgres \ + -v /srv/opendatakit/conf/server.xml:/srv/tomcat/conf/server.xml \ + -v /srv/opendatakit/conf/jdbc.properties:/srv/tomcat/webapps/aggregate/WEB-INF/classes/jdbc.properties \ + -v /srv/opendatakit/conf/security.properties:/srv/tomcat/webapps/aggregate/WEB-INF/classes/security.properties \ + opendatakit +} + +start_post() { + /usr/bin/spotter-appmgr register-proxy opendatakit +} + +stop_pre() { + /usr/bin/spotter-appmgr unregister-proxy opendatakit +} + +stop() { + /usr/bin/docker stop opendatakit +} diff --git a/opendatakit/srv/opendatakit/conf/jdbc.properties b/opendatakit/srv/opendatakit/conf/jdbc.properties new file mode 100644 index 0000000..43d8134 --- /dev/null +++ b/opendatakit/srv/opendatakit/conf/jdbc.properties @@ -0,0 +1,6 @@ +jdbc.driverClassName=org.postgresql.Driver +jdbc.resourceName=jdbc/odk_aggregate +jdbc.url=jdbc:postgresql://postgres/opendatakit?autoDeserialize=true +jdbc.username=opendatakit +jdbc.password=${OPENDATAKIT_PWD} +jdbc.schema=public diff --git a/odk/srv/odk/conf/security.properties b/opendatakit/srv/opendatakit/conf/security.properties similarity index 89% rename from odk/srv/odk/conf/security.properties rename to opendatakit/srv/opendatakit/conf/security.properties index dc914c1..0295a7e 100644 --- a/odk/srv/odk/conf/security.properties +++ b/opendatakit/srv/opendatakit/conf/security.properties @@ -36,10 +36,10 @@ wink.handlersFactoryClass=org.opendatakit.aggregate.odktables.impl.api.wink.AppE # this should be of the form: 'mailto:user@gmail.com' security.server.superUser= -# Define a superUserUsername to insert an ODK Aggregate username that can +# Define a superUserUsername to insert an OPENDATAKIT Aggregate username that can # access the server. The initial password for this username is 'aggregate' -security.server.superUserUsername=${ODK_ADMIN_USER} +security.server.superUserUsername=${OPENDATAKIT_ADMIN_USER} # realm definition # realmString -- what should be sent to users when BasicAuth or DigestAuth is done -security.server.realm.realmString=${ODK_ADMIN_REALM} +security.server.realm.realmString=${OPENDATAKIT_ADMIN_REALM} diff --git a/odk/srv/odk/conf/server.xml b/opendatakit/srv/opendatakit/conf/server.xml similarity index 100% rename from odk/srv/odk/conf/server.xml rename to opendatakit/srv/opendatakit/conf/server.xml diff --git a/opendatakit/srv/opendatakit/update-url.sh b/opendatakit/srv/opendatakit/update-url.sh new file mode 100755 index 0000000..76e59e9 --- /dev/null +++ b/opendatakit/srv/opendatakit/update-url.sh @@ -0,0 +1,5 @@ +#!/bin/sh + +sed -i "s|\(^\s\+proxyName\).*|\1=\"${1}\"|g" /srv/opendatakit/conf/server.xml +sed -i "s|\(^\s\+proxyPort\).*|\1=\"${2}\"|g" /srv/opendatakit/conf/server.xml +sed -i "s|^security\.server\.securePort.*|security.server.securePort=${2}|" /srv/opendatakit/conf/security.properties