Shorten ODK Aggregate handle

This commit is contained in:
Disassembler 2018-03-25 14:37:57 +02:00
parent 0d8a9634e3
commit 459d0f711e
No known key found for this signature in database
GPG Key ID: 524BD33A0EE29499
17 changed files with 93 additions and 93 deletions

View File

@ -17,7 +17,7 @@ ${SOURCE_DIR}/kanboard.sh
${SOURCE_DIR}/mifosx.sh
${SOURCE_DIR}/motech.sh
${SOURCE_DIR}/odkbuild.sh
${SOURCE_DIR}/opendatakit.sh
${SOURCE_DIR}/odk.sh
${SOURCE_DIR}/openmapkit.sh
${SOURCE_DIR}/pandora.sh
${SOURCE_DIR}/sahana.sh

View File

@ -81,7 +81,7 @@
</p>
</div>
<div class="c" id="opendatakit-clients">
<div class="c" id="odk-clients">
<h2><a href="#"><img src="img/ODK_Collect.png" alt="Open Data Kit" title="Open Data Kit">ODK Collect</a></h2>
<p>Mobilní aplikace<br>
<a href="https://play.google.com/store/apps/details?id=org.odk.collect.android"><img src="img/android.png" class="ico" alt="ODK Collect">ODK Collect pro Android</a><br>
@ -91,7 +91,7 @@
</ul>
</div>
<div class="c" id="opendatakit">
<div class="c" id="odk">
<h2><a href="#"><img src="img/ODK.png" alt="Open Data Kit" title="Open Data Kit">ODK Aggregate</a></h2>
<p><strong>Sběr dat s pomocí smartphone</strong>.<br>
<a href="http://geoodk.com">GeoODK Collect</a> - náhrada papírových dotazníků smartphonem.

44
odk.sh Executable file
View File

@ -0,0 +1,44 @@
#!/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
# Build Docker container
docker build -t odk ${SOURCE_DIR}
# 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
# Create OpenDataKit service
cp ${SOURCE_DIR}/etc/init.d/odk /etc/init.d/odk
rc-update add odk
service odk start
# 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 " -")
until docker logs odk 2>&1 | grep -q 'org.apache.catalina.startup.Catalina.start'; do
sleep 1
done
envsubst <${SOURCE_DIR}/adminpwd.sql | docker exec -i postgres psql odk
# Add application definition
spotter-appmgr add-app odk "https://odk.{host}/aggregate/" "${ODK_ADMIN_USER}" "${ODK_ADMIN_PWD}"
spotter-appmgr add-app odk-clients -p clienturl "https://odk.{host}/aggregate"

1
odk/adminpwd.sql Normal file
View File

@ -0,0 +1 @@
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}';

4
odk/createdb.sql Normal file
View File

@ -0,0 +1,4 @@
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;

28
odk/etc/init.d/odk Executable file
View File

@ -0,0 +1,28 @@
#!/sbin/openrc-run
description="OpenDataKit Aggregate docker container"
depend() {
need docker net postgres
use dns logger netmount postfix
}
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/local/bin/spotter-appmgr update-hosts odk
}
stop() {
/usr/bin/docker stop odk
}

View File

@ -0,0 +1,6 @@
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

View File

@ -38,8 +38,8 @@ security.server.superUser=
# Define a superUserUsername to insert an ODK Aggregate username that can
# access the server. The initial password for this username is 'aggregate'
security.server.superUserUsername=${OPENDATAKIT_ADMIN_USER}
security.server.superUserUsername=${ODK_ADMIN_USER}
# realm definition
# realmString -- what should be sent to users when BasicAuth or DigestAuth is done
security.server.realm.realmString=${OPENDATAKIT_ADMIN_REALM}
security.server.realm.realmString=${ODK_ADMIN_REALM}

5
odk/srv/odk/update-url.sh Executable file
View File

@ -0,0 +1,5 @@
#!/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

View File

@ -1,44 +0,0 @@
#!/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
# Build Docker container
docker build -t opendatakit ${SOURCE_DIR}
# 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
# Create OpenDataKit service
cp ${SOURCE_DIR}/etc/init.d/opendatakit /etc/init.d/opendatakit
rc-update add opendatakit
service opendatakit start
# 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 " -")
until docker logs opendatakit 2>&1 | grep -q 'org.apache.catalina.startup.Catalina.start'; do
sleep 1
done
envsubst <${SOURCE_DIR}/adminpwd.sql | docker exec -i postgres psql opendatakit
# Add application definition
spotter-appmgr add-app opendatakit "https://opendatakit.{host}/aggregate/" "${OPENDATAKIT_ADMIN_USER}" "${OPENDATAKIT_ADMIN_PWD}"
spotter-appmgr add-app opendatakit-clients -p clienturl "https://opendatakit.{host}/aggregate"

View File

@ -1 +0,0 @@
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}';

View File

@ -1,4 +0,0 @@
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;

View File

@ -1,28 +0,0 @@
#!/sbin/openrc-run
description="OpenDataKit Aggregate docker container"
depend() {
need docker net postgres
use dns logger netmount postfix
}
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/local/bin/spotter-appmgr update-hosts opendatakit
}
stop() {
/usr/bin/docker stop opendatakit
}

View File

@ -1,6 +0,0 @@
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

View File

@ -1,5 +0,0 @@
#!/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