2017-11-19 10:01:18 +01:00
|
|
|
#!/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
|
2017-11-19 10:01:18 +01:00
|
|
|
|
|
|
|
# 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
|
2017-11-22 20:38:40 +01:00
|
|
|
/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
|
2017-11-19 10:01:18 +01:00
|
|
|
|
2017-12-01 10:17:50 +01:00
|
|
|
# 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
|
2017-11-19 10:01:18 +01:00
|
|
|
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
|
|
|
|
|
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)
|
|
|
|
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
|
|
|
|
|
2017-11-19 10:01:18 +01:00
|
|
|
# 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()")
|
2017-11-19 10:01:18 +01:00
|
|
|
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
|
2017-11-28 19:33:36 +01:00
|
|
|
cp ${SOURCE_DIR}/ckan/etc/ckan/datapusher_settings.py /etc/ckan/datapusher_settings.py
|
2017-11-19 10:01:18 +01:00
|
|
|
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
|
2017-12-01 10:17:50 +01:00
|
|
|
/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/
|
2017-11-19 10:01:18 +01:00
|
|
|
|
|
|
|
# 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()")
|
2017-11-19 10:01:18 +01:00
|
|
|
export CKAN_ADMIN_PWD=$(head -c 12 /dev/urandom | base64)
|
2017-11-22 20:38:40 +01:00
|
|
|
export CKAN_ADMIN_HASH=$(/srv/ckan/bin/python ${SOURCE_DIR}/ckan/ckan-adminpwd.py ${CKAN_ADMIN_PWD})
|
2017-11-19 10:01:18 +01:00
|
|
|
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
|
2017-11-22 19:18:38 +01:00
|
|
|
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
|
2017-11-19 10:01:18 +01:00
|
|
|
|
|
|
|
# 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
|
2017-11-22 19:18:38 +01:00
|
|
|
${SOURCE_DIR}/basic/portal-app-manager.py ckan "https://{host}:8003/" "${CKAN_ADMIN_USER}" "${CKAN_ADMIN_PWD}"
|