Spotter-VM/ckan.sh

120 lines
5.6 KiB
Bash
Raw Normal View History

#!/bin/bash
SOURCE_DIR=$(realpath $(dirname "${0}"))
# Install dependencies for CKAN
2017-11-30 10:11:59 +01:00
apt-get -y --no-install-recommends install gcc libpq-dev python-dev python-virtualenv redis-server virtualenv
# Install dependencies for Solr
apt-get -y --no-install-recommends install openjdk-8-jre-headless lsof
# Install CKAN python virtual environment
mkdir -p /srv/ckan
virtualenv --no-site-packages --python=/usr/bin/python2.7 /srv/ckan
/srv/ckan/bin/pip install -e 'git+https://github.com/ckan/ckan.git#egg=ckan'
/srv/ckan/bin/pip install -r /srv/ckan/src/ckan/requirements.txt
2017-11-30 10:11:59 +01:00
# Install Datapusher python virtual environment
mkdir -p /srv/ckan-datapusher
virtualenv --no-site-packages --python=/usr/bin/python2.7 /srv/ckan-datapusher
/srv/ckan-datapusher/bin/pip install -e 'git+https://github.com/ckan/datapusher.git#egg=datapusher'
/srv/ckan-datapusher/bin/pip install -r /srv/ckan-datapusher/src/datapusher/requirements.txt
# Patch service provider TLS verification for Datapusher
# https://github.com/ckan/ckan-service-provider/issues/36
patch -d /srv/ckan-datapusher -p0 <${SOURCE_DIR}/ckan/ckan-serviceprovider-sslverify.patch
2017-11-23 08:37:01 +01:00
# Install CKAN extensions
/srv/ckan/bin/pip install -e 'git+https://github.com/ckan/ckanext-basiccharts#egg=ckanext_basiccharts'
/srv/ckan/bin/pip install -e 'git+https://github.com/ckan/ckanext-spatial#egg=ckanext_spatial'
/srv/ckan/bin/pip install -e 'git+https://github.com/ckan/ckanext-geoview#egg=ckanext_geoview'
/srv/ckan/bin/pip install -e 'git+https://github.com/ckan/ckanext-mapviews#egg=ckanext_mapviews'
/srv/ckan/bin/pip install -e 'git+https://github.com/XVTSolutions/ckanext-spatialUI#egg=ckanext_spatialui'
/srv/ckan/bin/pip install -e 'git+https://github.com/aptivate/ckanext-datasetthumbnail#egg=ckanext_datasetthumbnail'
/srv/ckan/bin/pip install -e 'git+https://github.com/datagvat/ckanext-dgvat_xls#egg=ckanext_dgvat_xls'
/srv/ckan/bin/pip install -r /srv/ckan/src/ckanext-spatial/pip-requirements.txt
/srv/ckan/bin/pip install -r /srv/ckan/src/ckanext-datasetthumbnail/requirements.txt
/srv/ckan/bin/pip install -r /srv/ckan/src/ckanext-dgvat-xls/requirements.txt
2017-11-30 10:11:59 +01:00
# Download Solr
wget http://archive.apache.org/dist/lucene/solr/6.5.1/solr-6.5.1.tgz -O /tmp/solr-6.5.1.tgz
tar xzf /tmp/solr-6.5.1.tgz -C /opt/
mv /opt/solr-6.5.1 /opt/solr
rm -f /tmp/solr-6.5.1.tgz
# Create Solr OS user
adduser --system --group --home /var/lib/solr --shell /bin/false solr
chown -R solr:solr /opt/solr/
# Configure Solr
cp ${SOURCE_DIR}/ckan/lib/systemd/system/solr.service /lib/systemd/system/solr.service
cp -p /opt/solr/server/solr/solr.xml /var/lib/solr/
systemctl daemon-reload
systemctl enable solr
systemctl start solr
sleep 5
# Configure CKAN Solr core
sudo -u solr /opt/solr/bin/solr create -c ckan
cp ${SOURCE_DIR}/ckan/var/lib/solr/ckan/conf/solrconfig.xml /var/lib/solr/ckan/conf/solrconfig.xml
ln -s /srv/ckan/src/ckan/ckan/config/solr/schema.xml /var/lib/solr/ckan/conf/schema.xml
systemctl restart solr
# Create database
export CKAN_PWD=$(head -c 18 /dev/urandom | base64)
export CKAN_DS_PWD=$(head -c 18 /dev/urandom | base64)
envsubst <${SOURCE_DIR}/ckan/tmp/ckan-createdb.sql >/tmp/ckan-createdb.sql
sudo -u postgres psql -f /tmp/ckan-createdb.sql
rm -f /tmp/ckan-createdb.sql
# Configure CKAN
export CKAN_SECRET=$(head -c 18 /dev/urandom | base64)
2017-11-30 10:11:59 +01:00
export CKAN_UUID=$(python -c "import uuid; print uuid.uuid4()")
mkdir /etc/ckan
envsubst <${SOURCE_DIR}/ckan/etc/ckan/ckan.ini >/etc/ckan/ckan.ini
cp ${SOURCE_DIR}/ckan/etc/ckan/datapusher.wsgi /etc/ckan/datapusher.wsgi
cp ${SOURCE_DIR}/ckan/etc/ckan/datapusher_settings.py /etc/ckan/datapusher_settings.py
ln -s /srv/ckan/src/ckan/ckan/config/who.ini /etc/ckan/who.ini
cp ${SOURCE_DIR}/ckan/srv/ckan/update-ip.sh /srv/ckan/update-ip.sh
/srv/ckan/update-ip.sh
# Populate database
/srv/ckan/bin/paster --plugin=ckan db init -c /etc/ckan/ckan.ini
/srv/ckan/bin/paster --plugin=ckanext-spatial spatial initdb -c /etc/ckan/ckan.ini
/srv/ckan/bin/paster --plugin=ckan datastore set-permissions -c /etc/ckan/ckan.ini | sudo -u postgres psql
# Create CKAN OS user
adduser --system --group --home /srv/ckan --shell /bin/false ckan
chown -R ckan:ckan /srv/ckan/
chown -R ckan:ckan /srv/ckan-datapusher/
# Create admin account
export CKAN_ADMIN_USER="admin"
2017-11-30 10:11:59 +01:00
export CKAN_ADMIN_UUID=$(python -c "import uuid; print uuid.uuid4()")
export CKAN_ADMIN_APIKEY=$(python -c "import uuid; print uuid.uuid4()")
export CKAN_ADMIN_PWD=$(head -c 12 /dev/urandom | base64)
export CKAN_ADMIN_HASH=$(/srv/ckan/bin/python ${SOURCE_DIR}/ckan/ckan-adminpwd.py ${CKAN_ADMIN_PWD})
export CKAN_ADMIN_EMAIL="admin@example.com"
envsubst <${SOURCE_DIR}/ckan/tmp/ckan-adminpwd.sql >/tmp/ckan-adminpwd.sql
sudo -u postgres psql -f /tmp/ckan-adminpwd.sql ckan
rm /tmp/ckan-adminpwd.sql
# Create uwsgi and nginx app definition
cp ${SOURCE_DIR}/ckan/etc/uwsgi/apps-available/ckan.ini /etc/uwsgi/apps-available/ckan.ini
cp ${SOURCE_DIR}/ckan/etc/uwsgi/apps-available/ckan-datapusher.ini /etc/uwsgi/apps-available/ckan-datapusher.ini
ln -s /etc/uwsgi/apps-available/ckan.ini /etc/uwsgi/apps-enabled/ckan.ini
ln -s /etc/uwsgi/apps-available/ckan-datapusher.ini /etc/uwsgi/apps-enabled/ckan-datapusher.ini
cp ${SOURCE_DIR}/ckan/etc/nginx/sites-available/ckan /etc/nginx/sites-available/ckan
ln -s /etc/nginx/sites-available/ckan /etc/nginx/sites-enabled/ckan
# Restart services
systemctl restart uwsgi
systemctl restart nginx
# Install cron job
cp ${SOURCE_DIR}/ckan/srv/ckan/cron-pageviews.sh /srv/ckan/cron-pageviews.sh
cp ${SOURCE_DIR}/ckan/etc/cron.d/ckan /etc/cron.d/ckan
# Add portal application definition
${SOURCE_DIR}/basic/portal-app-manager.py ckan "https://{host}:8003/" "${CKAN_ADMIN_USER}" "${CKAN_ADMIN_PWD}"