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

81 lines
3.4 KiB
Bash
Executable File

#!/bin/sh
set -ev
# 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"
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"
# Create Postgres instance
install -o 105432 -g 105432 -m 700 -d ${POSTGRES_DATA}
spoc-container exec ckan-postgres -- initdb -D /var/lib/postgresql
# Configure Postgres
install postgres_data/postgresql.conf ${POSTGRES_DATA}/postgresql.conf
install postgres_data/pg_hba.conf ${POSTGRES_DATA}/pg_hba.conf
# 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 '+/=')
spoc-container start ckan-postgres
envsubst <createdb.sql | spoc-container exec ckan-postgres -- psql
# Configure Redis
install -o 100000 -g 100000 -d ${REDIS_CONF}
install -o 106379 -g 106379 -d ${REDIS_DATA}
install -o 106379 -g 106379 redis_conf/redis.conf ${REDIS_CONF}/redis.conf
spoc-container start ckan-redis
# Configure Solr
install -o 108983 -g 108983 -d ${SOLR_DATA}
install -o 108983 -g 108983 ${LAYERS_DIR}/solr6_6.5.1-200313/opt/solr/server/solr/solr.xml ${SOLR_DATA}/solr.xml
spoc-container start ckan-solr
# Configure CKAN Solr core
spoc-container exec ckan-solr -- solr create -p 8983 -c ckan
spoc-container stop ckan-solr
install -o 108983 -g 108983 solr_data/ckan/conf/schema.xml ${SOLR_DATA}/ckan/conf/schema.xml
install -o 108983 -g 108983 solr_data/ckan/conf/solrconfig.xml ${SOLR_DATA}/ckan/conf/solrconfig.xml
spoc-container start ckan-solr
# Configure CKAN DataPusher
install -o 100000 -g 100000 -d ${DATAPUSHER_CONF}
install -o 108080 -g 108080 -d ${DATAPUSHER_DATA}
install -o 100000 -g 100000 datapusher_conf/datapusher.wsgi ${DATAPUSHER_CONF}/datapusher.wsgi
install -o 100000 -g 100000 datapusher_conf/datapusher_settings.py ${DATAPUSHER_CONF}/datapusher_settings.py
# Configure CKAN
install -o 100000 -g 100000 -d ${CKAN_CONF}
install -o 108080 -g 108080 -d ${CKAN_DATA}
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 100000 /dev/stdin ${CKAN_CONF}/ckan.ini
install -o 100000 -g 100000 ckan_conf/who.ini ${CKAN_CONF}/who.ini
# Populate database
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
spoc-container exec ckan -- paster --plugin=ckan datastore set-permissions -c /etc/ckan/ckan.ini | spoc-container exec ckan-postgres -- psql
# 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 '+/=')
export CKAN_ADMIN_HASH=$(spoc-container exec ckan -- python -c "from passlib.hash import pbkdf2_sha512;print pbkdf2_sha512.encrypt('${CKAN_ADMIN_PWD}')")
export CKAN_ADMIN_EMAIL="admin@example.com"
envsubst <adminpwd.sql | spoc-container exec ckan-postgres -- psql ckan
# Stop services required for setup
spoc-container stop ckan-solr
spoc-container stop ckan-postgres
spoc-container stop ckan-redis
# Register application
vmmgr register-app ckan ckan "${CKAN_ADMIN_USER}" "${CKAN_ADMIN_PWD}"