#!/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 mkdir -p ${POSTGRES_DATA} chown -R 105432:105432 ${POSTGRES_DATA} chmod 700 ${POSTGRES_DATA} spoc-container exec ckan-postgres -- initdb -D /var/lib/postgresql # Configure Postgres cp postgres_data/postgresql.conf ${POSTGRES_DATA}/postgresql.conf cp 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 ${CKAN_CONF}/ckan.ini cp ckan_conf/who.ini ${CKAN_CONF}/who.ini chown -R 100000:100000 ${CKAN_CONF} chown -R 108080:108080 ${CKAN_DATA} # 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 | lxc-attach -u 5432 -g 5432 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