#!/bin/sh set -ev cd $(realpath $(dirname "${0}"))/install # Check prerequisites [ ! -e /run/openrc/started/postgres ] && service postgres start && STOP_POSTGRES=1 [ ! -e /run/openrc/started/redis ] && service redis start && STOP_REDIS=1 [ ! -e /run/openrc/started/solr ] && service solr start && STOP_SOLR=1 # 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 '+/=') envsubst /srv/ckan/conf/ckan.ini cp srv/ckan/conf/who.ini /srv/ckan/conf/who.ini chown -R 8003:8003 /srv/ckan/data # Set "production values" (increases performance) only if the DEBUG environment variable is not set if [ ${DEBUG:-0} -eq 0 ]; then sed -i 's/debug = true/debug = false/' /srv/ckan/conf/ckan.ini fi # Populate database lxc-execute ckan -- paster --plugin=ckan db init -c /etc/ckan/ckan.ini lxc-execute ckan -- paster --plugin=ckanext-spatial spatial initdb -c /etc/ckan/ckan.ini lxc-execute ckan -- paster --plugin=ckan datastore set-permissions -c /etc/ckan/ckan.ini | lxc-attach -u 5432 -g 5432 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=$(lxc-execute ckan -- python -c "from passlib.hash import pbkdf2_sha512;print pbkdf2_sha512.encrypt('${CKAN_ADMIN_PWD}')") export CKAN_ADMIN_EMAIL="admin@example.com" envsubst