2017-12-20 11:05:54 +01:00
|
|
|
#!/bin/sh
|
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
|
|
|
|
2017-12-16 20:41:58 +01:00
|
|
|
# Build Docker container
|
|
|
|
docker build -t ckan ${SOURCE_DIR}
|
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
|
|
|
|
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)
|
2017-12-19 22:17:12 +01:00
|
|
|
mkdir -p /srv/ckan/conf
|
|
|
|
mkdir /srv/ckan/data
|
2017-12-16 20:41:58 +01:00
|
|
|
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
|
|
|
|
chown -R 8003:8003 /srv/ckan/data
|
2017-12-04 17:48:37 +01:00
|
|
|
cp ${SOURCE_DIR}/srv/ckan/update-ip.sh /srv/ckan/update-ip.sh
|
2017-11-19 10:01:18 +01:00
|
|
|
/srv/ckan/update-ip.sh
|
|
|
|
|
|
|
|
# Populate database
|
2017-12-16 20:41:58 +01:00
|
|
|
docker run --rm --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 --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 --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
|
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
|
|
|
|
|
|
|
|
# Configure CKAN service
|
2017-12-19 22:17:12 +01:00
|
|
|
cp ${SOURCE_DIR}/etc/init.d/ckan /etc/init.d/ckan
|
|
|
|
rc-update add ckan boot
|
|
|
|
service ckan start
|
2017-11-19 10:01:18 +01:00
|
|
|
|
2017-12-19 22:17:12 +01:00
|
|
|
# Create nginx app definition
|
|
|
|
cp ${SOURCE_DIR}/etc/nginx/apps/ckan /etc/nginx/apps/ckan
|
|
|
|
cp ${SOURCE_DIR}/etc/nginx/conf.d/ckan.conf /etc/nginx/conf.d/ckan.conf
|
|
|
|
service nginx reload
|
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
|
2017-11-19 10:01:18 +01:00
|
|
|
|
|
|
|
# Add portal application definition
|
2017-12-19 22:17:12 +01:00
|
|
|
portal-app-manager ckan "https://{host}:8403/" "${CKAN_ADMIN_USER}" "${CKAN_ADMIN_PWD}"
|