113 lines
4.4 KiB
Bash
Executable File
113 lines
4.4 KiB
Bash
Executable File
#!/bin/bash
|
|
|
|
SOURCE_DIR=$(realpath $(dirname "${0}"))
|
|
|
|
# Install dependencies for CKAN
|
|
apt-get -y --no-install-recommends install gcc libpq-dev python-dev python-virtualenv redis-server uuid-runtime 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/activate
|
|
pip install -e 'git+https://github.com/ckan/ckan.git#egg=ckan'
|
|
pip install -e 'git+https://github.com/ckan/datapusher.git#egg=datapusher'
|
|
pip install -r /srv/ckan/src/ckan/requirements.txt
|
|
pip install -r /srv/ckan/src/datapusher/requirements.txt
|
|
deactivate
|
|
|
|
# Donwload 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 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
|
|
|
|
# Create CKAN OS user
|
|
adduser --system --group --home /srv/ckan --shell /bin/false ckan
|
|
chown -R ckan:ckan /srv/ckan/
|
|
mkdir /var/lib/ckan
|
|
chown ckan:ckan /var/lib/ckan
|
|
|
|
# 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
|
|
|
|
# Configure CKAN
|
|
export CKAN_SECRET=$(head -c 18 /dev/urandom | base64)
|
|
export CKAN_UUID=$(uuidgen -r)
|
|
export CKAN_DSJOB_SECRET=$(uuidgen -r)
|
|
export CKAN_DSJOB_USER=$(uuidgen -r)
|
|
export CKAN_DSJOB_PWD=$(uuidgen -r)
|
|
mkdir /etc/ckan
|
|
envsubst <${SOURCE_DIR}/ckan/etc/ckan/ckan.ini >/etc/ckan/ckan.ini
|
|
envsubst <${SOURCE_DIR}/ckan/etc/ckan/datapusher_settings.py >/etc/ckan/datapusher_settings.py
|
|
cp ${SOURCE_DIR}/ckan/etc/ckan/datapusher.wsgi /etc/ckan/datapusher.wsgi
|
|
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/activate
|
|
paster --plugin=ckan db init -c /etc/ckan/ckan.ini
|
|
paster --plugin=ckan datastore set-permissions -c /etc/ckan/ckan.ini | sudo -u postgres psql
|
|
|
|
# Create admin account
|
|
export CKAN_ADMIN_USER="admin"
|
|
export CKAN_ADMIN_UUID=$(uuidgen -r)
|
|
export CKAN_ADMIN_APIKEY=$(uuidgen -r)
|
|
export CKAN_ADMIN_PWD=$(head -c 12 /dev/urandom | base64)
|
|
export CKAN_ADMIN_HASH=$(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
|
|
deactivate
|
|
|
|
# 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/apps-available/ckan /etc/nginx/apps-available/ckan
|
|
ln -s /etc/nginx/apps-available/ckan /etc/nginx/apps-enabled/ckan
|
|
cp ${SOURCE_DIR}/ckan/etc/nginx/sites-available/ckan-datapusher /etc/nginx/sites-available/ckan-datapusher
|
|
ln -s /etc/nginx/sites-available/ckan-datapusher /etc/nginx/sites-enabled/ckan-datapusher
|
|
|
|
# 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 "/ckan/" "${CKAN_ADMIN_USER}" "${CKAN_ADMIN_PWD}"
|
|
|
|
# Remove compilation dependencies
|
|
apt-get -y purge gcc libpq-dev python-dev
|
|
apt-get -y --purge autoremove
|