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

85 lines
3.8 KiB
Bash
Raw Normal View History

2019-09-18 11:29:58 +02:00
#!/bin/sh
set -ev
2020-03-13 21:12:16 +01:00
# Volumes
POSTGRES_DATA="${VOLUMES_DIR}/ckan/postgres_data"
REDIS_CONF="${VOLUMES_DIR}/ckan/redis_conf"
REDIS_DATA="${VOLUMES_DIR}/ckan/redis_data"
SOLR_DATA="${VOLUMES_DIR}/ckan/solr_data"
2020-04-04 00:17:24 +02:00
SOLR_LAYER="${LAYERS_DIR}/solr6_6.5.1-200403"
2020-03-13 21:12:16 +01:00
DATAPUSHER_CONF="${VOLUMES_DIR}/ckan/datapusher_conf"
DATAPUSHER_DATA="${VOLUMES_DIR}/ckan/datapusher_data"
CKAN_CONF="${VOLUMES_DIR}/ckan/ckan_conf"
CKAN_DATA="${VOLUMES_DIR}/ckan/ckan_data"
2019-09-18 11:29:58 +02:00
# Create Postgres instance
install -o 105432 -g 105432 -m 700 -d ${POSTGRES_DATA}
2020-03-13 21:12:16 +01:00
spoc-container exec ckan-postgres -- initdb -D /var/lib/postgresql
2019-09-18 11:29:58 +02:00
# Configure Postgres
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
2019-09-18 11:29:58 +02:00
# Create database
export CKAN_PWD=$(head -c 18 /dev/urandom | base64 | tr -d '+/=')
export CKAN_DS_PWD=$(head -c 18 /dev/urandom | base64 | tr -d '+/=')
2020-03-13 21:12:16 +01:00
spoc-container start ckan-postgres
envsubst <createdb.sql | spoc-container exec ckan-postgres -- psql
2019-09-18 11:29:58 +02:00
# Configure Redis
install -o 100000 -g 106379 -m 750 -d ${REDIS_CONF}
install -o 106379 -g 106379 -m 750 -d ${REDIS_DATA}
install -o 100000 -g 106379 -m 640 redis_conf/redis.conf ${REDIS_CONF}/redis.conf
2020-03-13 21:12:16 +01:00
spoc-container start ckan-redis
2019-09-18 11:29:58 +02:00
# Configure Solr
install -o 108983 -g 108983 -m 750 -d ${SOLR_DATA}
cp -p ${SOLR_LAYER}/opt/solr/server/solr/solr.xml ${SOLR_DATA}/solr.xml
2020-03-13 21:12:16 +01:00
spoc-container start ckan-solr
2019-09-18 11:29:58 +02:00
# Configure CKAN Solr core
2020-03-13 21:12:16 +01:00
spoc-container exec ckan-solr -- solr create -p 8983 -c ckan
spoc-container stop ckan-solr
install -o 108983 -g 108983 -m 640 solr_data/ckan/conf/schema.xml ${SOLR_DATA}/ckan/conf/schema.xml
install -o 108983 -g 108983 -m 640 solr_data/ckan/conf/solrconfig.xml ${SOLR_DATA}/ckan/conf/solrconfig.xml
2020-03-13 21:12:16 +01:00
spoc-container start ckan-solr
2019-09-18 11:29:58 +02:00
# Configure CKAN DataPusher
install -o 100000 -g 108080 -m 750 -d ${DATAPUSHER_CONF}
install -o 108080 -g 108080 -m 750 -d ${DATAPUSHER_DATA}
install -o 100000 -g 108080 -m 640 datapusher_conf/add-ca-cert.env ${DATAPUSHER_CONF}/add-ca-cert.env
install -o 100000 -g 108080 -m 640 datapusher_conf/datapusher.wsgi ${DATAPUSHER_CONF}/datapusher.wsgi
install -o 100000 -g 108080 -m 640 datapusher_conf/datapusher_settings.py ${DATAPUSHER_CONF}/datapusher_settings.py
2019-09-18 11:29:58 +02:00
# Configure CKAN
install -o 100000 -g 108080 -m 750 -d ${CKAN_CONF}
install -o 108080 -g 108080 -m 750 -d ${CKAN_DATA}
2019-09-18 11:29:58 +02:00
export CKAN_SECRET=$(head -c 18 /dev/urandom | base64 | tr -d '+/=')
export CKAN_UUID=$(cat /proc/sys/kernel/random/uuid)
envsubst <ckan_conf/ckan.ini | install -o 100000 -g 108080 -m 640 /dev/stdin ${CKAN_CONF}/ckan.ini
install -o 100000 -g 108080 -m 640 ckan_conf/who.ini ${CKAN_CONF}/who.ini
2019-09-18 11:29:58 +02:00
# Populate database
2020-03-13 21:12:16 +01:00
spoc-container exec ckan -- paster --plugin=ckan db init -c /etc/ckan/ckan.ini
spoc-container exec ckan -- paster --plugin=ckanext-spatial spatial initdb -c /etc/ckan/ckan.ini
2020-03-13 22:55:12 +01:00
spoc-container exec ckan -- paster --plugin=ckan datastore set-permissions -c /etc/ckan/ckan.ini | spoc-container exec ckan-postgres -- psql
2019-09-18 11:29:58 +02:00
# Create admin account
export CKAN_ADMIN_USER="admin"
export CKAN_ADMIN_UUID=$(cat /proc/sys/kernel/random/uuid)
export CKAN_ADMIN_APIKEY=$(cat /proc/sys/kernel/random/uuid)
export CKAN_ADMIN_PWD=$(head -c 12 /dev/urandom | base64 | tr -d '+/=')
2020-03-13 21:12:16 +01:00
export CKAN_ADMIN_HASH=$(spoc-container exec ckan -- python -c "from passlib.hash import pbkdf2_sha512;print pbkdf2_sha512.encrypt('${CKAN_ADMIN_PWD}')")
2019-09-18 11:29:58 +02:00
export CKAN_ADMIN_EMAIL="admin@example.com"
2020-03-13 21:12:16 +01:00
envsubst <adminpwd.sql | spoc-container exec ckan-postgres -- psql ckan
2019-09-18 11:29:58 +02:00
# Stop services required for setup
2020-03-13 21:12:16 +01:00
spoc-container stop ckan-solr
spoc-container stop ckan-postgres
spoc-container stop ckan-redis
2019-09-18 11:29:58 +02:00
# Register application
vmmgr register-app ckan ckan "${CKAN_ADMIN_USER}" "${CKAN_ADMIN_PWD}"
vmmgr register-prop ckan email "${CKAN_ADMIN_EMAIL}"
vmmgr register-prop ckan gmaps-api-key ""