Spotter-VM/ckan/install.sh

69 lines
2.6 KiB
Bash
Raw Normal View History

#!/bin/sh
2018-10-28 16:04:11 +01:00
set -ev
2018-10-26 15:02:11 +02:00
cd $(realpath $(dirname "${0}"))/install
# 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
# 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
# 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
chown 8983:8983 /srv/solr/data/ckan/conf/schema.xml
2017-12-19 22:17:12 +01:00
service solr restart
# Configure CKAN
mkdir -p /srv/ckan/conf /srv/ckan/data
export CKAN_SECRET=$(head -c 18 /dev/urandom | base64)
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
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
# 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
# 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)
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}')")
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
# Install cron job
2018-10-25 22:22:36 +02:00
cp etc/periodic/hourly/ckan /etc/periodic/hourly/ckan
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
# 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-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
# Register application
vmmgr register-app ckan "${CKAN_ADMIN_USER}" "${CKAN_ADMIN_PWD}"
2018-10-28 19:50:35 +01:00
exit 0