2017-12-20 11:05:54 +01:00
|
|
|
#!/bin/sh
|
2018-07-15 21:55:35 +02:00
|
|
|
set -e
|
2017-11-19 10:01:18 +01:00
|
|
|
|
2017-12-21 10:43:54 +01:00
|
|
|
SOURCE_DIR=$(realpath $(dirname "${0}"))/ckan
|
2017-11-19 10:01:18 +01:00
|
|
|
|
2018-01-23 21:27:18 +01:00
|
|
|
# Check prerequisites
|
2018-04-29 20:48:57 +02:00
|
|
|
service postgres start
|
|
|
|
service redis start
|
|
|
|
service solr start
|
2018-01-23 21:27:18 +01:00
|
|
|
|
2018-09-05 17:41:38 +02:00
|
|
|
# Install service
|
2018-04-29 20:48:57 +02:00
|
|
|
cp ${SOURCE_DIR}/etc/init.d/ckan /etc/init.d/ckan
|
|
|
|
rc-update -u
|
2017-11-19 10:01:18 +01:00
|
|
|
|
2017-12-01 10:17:50 +01:00
|
|
|
# Create database
|
|
|
|
export CKAN_PWD=$(head -c 18 /dev/urandom | base64)
|
|
|
|
export CKAN_DS_PWD=$(head -c 18 /dev/urandom | base64)
|
2017-12-16 20:41:58 +01:00
|
|
|
envsubst <${SOURCE_DIR}/createdb.sql | docker exec -i postgres psql
|
|
|
|
|
|
|
|
# Configure CKAN Solr core
|
2017-12-19 22:17:12 +01:00
|
|
|
docker exec solr solr create -p 8983 -c ckan
|
2017-12-16 20:41:58 +01:00
|
|
|
cp ${SOURCE_DIR}/srv/solr/data/ckan/conf/schema.xml /srv/solr/data/ckan/conf/schema.xml
|
|
|
|
cp ${SOURCE_DIR}/srv/solr/data/ckan/conf/solrconfig.xml /srv/solr/data/ckan/conf/solrconfig.xml
|
|
|
|
chown 8983:8983 /srv/solr/data/ckan/conf/schema.xml
|
2017-12-19 22:17:12 +01:00
|
|
|
service solr restart
|
2017-12-01 10:17:50 +01:00
|
|
|
|
2017-11-19 10:01:18 +01:00
|
|
|
# Configure CKAN
|
2018-01-18 15:35:32 +01:00
|
|
|
mkdir -p /srv/ckan/conf /srv/ckan/data
|
2017-11-19 10:01:18 +01:00
|
|
|
export CKAN_SECRET=$(head -c 18 /dev/urandom | base64)
|
2017-12-16 20:41:58 +01:00
|
|
|
export CKAN_UUID=$(cat /proc/sys/kernel/random/uuid)
|
|
|
|
envsubst <${SOURCE_DIR}/srv/ckan/conf/ckan.ini >/srv/ckan/conf/ckan.ini
|
|
|
|
cp ${SOURCE_DIR}/srv/ckan/conf/who.ini /srv/ckan/conf/who.ini
|
2017-11-19 10:01:18 +01:00
|
|
|
|
2018-01-30 20:59:11 +01:00
|
|
|
# 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
|
|
|
|
|
2017-11-19 10:01:18 +01:00
|
|
|
# Populate database
|
2018-01-18 13:59:24 +01:00
|
|
|
docker run --rm -h ckan --link postgres --link redis --link solr -v /srv/ckan/conf:/etc/ckan -v /srv/ckan/data:/srv/ckan/storage ckan paster --plugin=ckan db init -c /etc/ckan/ckan.ini
|
|
|
|
docker run --rm -h ckan --link postgres --link redis --link solr -v /srv/ckan/conf:/etc/ckan -v /srv/ckan/data:/srv/ckan/storage ckan paster --plugin=ckanext-spatial spatial initdb -c /etc/ckan/ckan.ini
|
|
|
|
docker run --rm -h ckan --link postgres --link redis --link solr -v /srv/ckan/conf:/etc/ckan -v /srv/ckan/data:/srv/ckan/storage ckan paster --plugin=ckan datastore set-permissions -c /etc/ckan/ckan.ini | docker exec -i postgres psql
|
2018-08-14 18:25:20 +02:00
|
|
|
chown -R 8003:8003 /srv/ckan/data
|
2017-11-19 10:01:18 +01:00
|
|
|
|
|
|
|
# Create admin account
|
|
|
|
export CKAN_ADMIN_USER="admin"
|
2017-12-16 20:41:58 +01:00
|
|
|
export CKAN_ADMIN_UUID=$(cat /proc/sys/kernel/random/uuid)
|
|
|
|
export CKAN_ADMIN_APIKEY=$(cat /proc/sys/kernel/random/uuid)
|
2017-11-19 10:01:18 +01:00
|
|
|
export CKAN_ADMIN_PWD=$(head -c 12 /dev/urandom | base64)
|
2017-12-16 20:41:58 +01:00
|
|
|
export CKAN_ADMIN_HASH=$(docker run --rm ckan python -c "from passlib.hash import pbkdf2_sha512;print pbkdf2_sha512.encrypt('${CKAN_ADMIN_PWD}')")
|
2017-11-19 10:01:18 +01:00
|
|
|
export CKAN_ADMIN_EMAIL="admin@example.com"
|
2017-12-16 20:41:58 +01:00
|
|
|
envsubst <${SOURCE_DIR}/adminpwd.sql | docker exec -i postgres psql ckan
|
2018-09-04 21:42:26 +02:00
|
|
|
vmmgr update-login ckan "${CKAN_ADMIN_USER}" "${CKAN_ADMIN_PWD}"
|
2017-11-19 10:01:18 +01:00
|
|
|
|
|
|
|
# Install cron job
|
2017-12-20 22:46:18 +01:00
|
|
|
cp ${SOURCE_DIR}/etc/periodic/hourly/ckan /etc/periodic/hourly/ckan
|
2018-07-15 21:55:35 +02:00
|
|
|
|
|
|
|
# Stop services required for build
|
|
|
|
service solr stop
|
|
|
|
service redis stop
|
|
|
|
service postgres stop
|