80 lines
3.2 KiB
Bash
80 lines
3.2 KiB
Bash
|
#!/bin/sh
|
||
|
set -ev
|
||
|
|
||
|
cd $(realpath $(dirname "${0}"))/install
|
||
|
|
||
|
# Create Postgres instance
|
||
|
mkdir -p /srv/ckan/postgres_data
|
||
|
chown -R 105432:105432 /srv/ckan/postgres_data
|
||
|
chmod 700 /srv/ckan/postgres_data
|
||
|
lxc-execute -n ckan_postgres -- initdb -D /var/lib/postgresql
|
||
|
|
||
|
# Configure Postgres
|
||
|
cp postgres_data/postgresql.conf /srv/ckan/postgres_data/postgresql.conf
|
||
|
cp postgres_data/pg_hba.conf /srv/ckan/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 '+/=')
|
||
|
lxc-start ckan_postgres #TODO: wait?
|
||
|
envsubst <createdb.sql | lxc-attach -u 5432 -g 5432 ckan_postgres -- psql
|
||
|
|
||
|
# Configure Redis
|
||
|
mkdir -p /srv/ckan/redis_conf /srv/ckan/redis_data
|
||
|
cp redis_conf/redis.conf /srv/ckan/redis_conf/redis.conf
|
||
|
chown -R 106379:106379 /srv/ckan/redis_data
|
||
|
lxc-start ckan_redis
|
||
|
|
||
|
# Configure Solr
|
||
|
mkdir -p /srv/ckan/solr_data
|
||
|
lxc-execute ckan_solr -- cat /opt/solr/server/solr/solr.xml >/srv/ckan/solr_data/solr.xml
|
||
|
chown -R 108983:108983 /srv/ckan/solr_data
|
||
|
lxc-start ckan_solr # TODO: wait?
|
||
|
|
||
|
# Configure CKAN Solr core
|
||
|
lxc-attach -u 8983 -g 8983 ckan_solr -- solr create -p 8983 -c ckan # TODO: wait to ensure creation?
|
||
|
lxc-stop ckan_solr
|
||
|
cp solr_data/ckan/conf/schema.xml /srv/ckan/solr_data/ckan/conf/schema.xml
|
||
|
cp solr_data/ckan/conf/solrconfig.xml /srv/ckan/solr_data/ckan/conf/solrconfig.xml
|
||
|
chown 108983:108983 /srv/ckan/solr_data/ckan/conf/schema.xml # TODO: je to potreba?
|
||
|
lxc-start ckan_solr # TODO: wait?
|
||
|
|
||
|
# Configure CKAN DataPusher
|
||
|
mkdir -p /srv/ckan/datapusher_conf /srv/ckan/datapusher_data
|
||
|
cp datapusher_conf/datapusher.wsgi /srv/ckan/datapusher_conf/datapusher.wsgi
|
||
|
cp datapusher_conf/datapusher_settings.py /srv/ckan/datapusher_conf/datapusher_settings.py
|
||
|
chown -R 108080:108080 /srv/ckan/datapusher_data
|
||
|
|
||
|
# Configure CKAN
|
||
|
mkdir -p /srv/ckan/ckan_conf /srv/ckan/ckan_data
|
||
|
export CKAN_SECRET=$(head -c 18 /dev/urandom | base64 | tr -d '+/=')
|
||
|
export CKAN_UUID=$(cat /proc/sys/kernel/random/uuid)
|
||
|
envsubst <ckan_conf/ckan.ini >/srv/ckan/ckan_conf/ckan.ini
|
||
|
cp ckan_conf/who.ini /srv/ckan/ckan_conf/who.ini
|
||
|
chown -R 108080:108080 /srv/ckan/ckan_data
|
||
|
|
||
|
# Populate database
|
||
|
lxc-execute ckan_ckan -- paster --plugin=ckan db init -c /etc/ckan/ckan.ini
|
||
|
lxc-execute ckan_ckan -- paster --plugin=ckanext-spatial spatial initdb -c /etc/ckan/ckan.ini
|
||
|
lxc-execute ckan_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=$(lxc-execute ckan_ckan -- python -c "from passlib.hash import pbkdf2_sha512;print pbkdf2_sha512.encrypt('${CKAN_ADMIN_PWD}')")
|
||
|
export CKAN_ADMIN_EMAIL="admin@example.com"
|
||
|
envsubst <adminpwd.sql | lxc-attach -u 5432 -g 5432 ckan_postgres -- psql ckan
|
||
|
|
||
|
# Install config update script
|
||
|
cp update-conf.sh /srv/ckan/update-conf.sh
|
||
|
|
||
|
# Stop services required for setup
|
||
|
lxc-stop ckan_solr
|
||
|
lxc-stop ckan_postgres
|
||
|
lxc-stop ckan_redis
|
||
|
|
||
|
# Register application
|
||
|
vmmgr register-app ckan ckan "${CKAN_ADMIN_USER}" "${CKAN_ADMIN_PWD}"
|