2017-12-20 11:05:54 +01:00
|
|
|
#!/bin/sh
|
2018-10-28 16:04:11 +01:00
|
|
|
set -ev
|
2017-11-19 10:01:18 +01:00
|
|
|
|
2018-10-26 15:02:11 +02:00
|
|
|
cd $(realpath $(dirname "${0}"))/install
|
2017-11-19 10:01:18 +01:00
|
|
|
|
2018-01-23 21:27:18 +01:00
|
|
|
# Check prerequisites
|
2018-09-13 20:42:11 +02:00
|
|
|
[ ! -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
|
2018-01-23 21:27: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)
|
2018-10-25 22:22:36 +02:00
|
|
|
envsubst <createdb.sql | lxc-attach -u 5432 -g 5432 postgres -- psql
|
2017-12-16 20:41:58 +01:00
|
|
|
|
|
|
|
# Configure CKAN Solr core
|
2018-09-13 16:21:16 +02:00
|
|
|
lxc-attach -u 8983 -g 8983 solr -- solr create -p 8983 -c ckan
|
2018-10-25 22:22:36 +02:00
|
|
|
cp srv/solr/data/ckan/conf/schema.xml /srv/solr/data/ckan/conf/schema.xml
|
|
|
|
cp srv/solr/data/ckan/conf/solrconfig.xml /srv/solr/data/ckan/conf/solrconfig.xml
|
2017-12-16 20:41:58 +01:00
|
|
|
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)
|
2018-10-25 22:22:36 +02:00
|
|
|
envsubst <srv/ckan/conf/ckan.ini >/srv/ckan/conf/ckan.ini
|
|
|
|
cp srv/ckan/conf/who.ini /srv/ckan/conf/who.ini
|
2018-09-12 11:44:30 +02:00
|
|
|
chown -R 8003:8003 /srv/ckan/data
|
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-09-13 16:21:16 +02:00
|
|
|
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
|
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)
|
2018-09-13 16:21:16 +02:00
|
|
|
export CKAN_ADMIN_HASH=$(lxc-execute 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"
|
2018-10-25 22:22:36 +02:00
|
|
|
envsubst <adminpwd.sql | lxc-attach -u 5432 -g 5432 postgres -- psql ckan
|
2017-11-19 10:01:18 +01:00
|
|
|
|
|
|
|
# Install cron job
|
2018-10-25 22:22:36 +02:00
|
|
|
cp etc/periodic/hourly/ckan /etc/periodic/hourly/ckan
|
2018-07-15 21:55:35 +02:00
|
|
|
|
2018-09-05 22:20:24 +02:00
|
|
|
# Install service
|
2018-10-25 22:22:36 +02:00
|
|
|
cp etc/init.d/ckan /etc/init.d/ckan
|
2018-09-05 22:20:24 +02:00
|
|
|
rc-update -u
|
|
|
|
|
2018-09-20 15:45:00 +02:00
|
|
|
# Install config update script
|
2018-10-25 22:22:36 +02:00
|
|
|
cp srv/ckan/update-conf.sh /srv/ckan/update-conf.sh
|
2018-09-20 15:45:00 +02:00
|
|
|
|
2018-09-12 11:44:30 +02:00
|
|
|
# Stop services required for setup
|
2018-09-13 20:42:11 +02:00
|
|
|
[ ! -z ${STOP_POSTGRES} ] && service postgres stop
|
|
|
|
[ ! -z ${STOP_REDIS} ] && service redis stop
|
|
|
|
[ ! -z ${STOP_SOLR} ] && service solr stop
|
2018-10-28 19:50:35 +01:00
|
|
|
|
2018-11-03 15:53:51 +01:00
|
|
|
# Register application
|
2019-02-26 21:12:41 +01:00
|
|
|
vmmgr register-app ckan ckan "${CKAN_ADMIN_USER}" "${CKAN_ADMIN_PWD}"
|