Spotter-VM/seeddms/install.sh
2018-10-28 16:04:11 +01:00

42 lines
1.5 KiB
Bash
Executable File

#!/bin/sh
set -ev
cd $(realpath $(dirname "${0}"))/install
# Check prerequisites
[ ! -e /run/openrc/started/postgres ] && service postgres start && STOP_POSTGRES=1
# Populate database
export SEEDDMS_PWD=$(head -c 18 /dev/urandom | base64)
envsubst <createdb.sql | lxc-attach -u 5432 -g 5432 postgres -- psql
cat /var/lib/lxc/seeddms/seeddms/srv/seeddms/create_tables-postgres.sql | lxc-attach postgres -- sh -c "PGPASSWORD=${SEEDDMS_PWD} psql seeddms seeddms"
cat custom.sql | lxc-attach -u 5432 -g 5432 postgres -- psql seeddms
# Copy existing files into persistent storage
mkdir -p /srv/seeddms/conf /srv/seeddms/data
cp -rp /var/lib/lxc/seeddms/seeddms/srv/seeddms/conf/. /srv/seeddms/conf
cp -rp /var/lib/lxc/seeddms/seeddms/srv/seeddms/data/. /srv/seeddms/data
chown -R 8010:8010 /srv/seeddms/data
# Configure SeedDMS
envsubst <srv/seeddms/conf/settings.xml >/srv/seeddms/conf/settings.xml
export SEEDDMS_ADMIN_USER=admin
export SEEDDMS_ADMIN_PWD=$(head -c 12 /dev/urandom | base64)
export SEEDDMS_ADMIN_EMAIL=admin@example.com
envsubst <adminpwd.sql | lxc-attach -u 5432 -g 5432 postgres -- psql seeddms
chown -R 8010:8010 /srv/seeddms/conf
vmmgr update-login seeddms "${SEEDDMS_ADMIN_USER}" "${SEEDDMS_ADMIN_PWD}"
# Install cron job
cp etc/periodic/hourly/seeddms /etc/periodic/hourly/seeddms
# Install service
cp etc/init.d/seeddms /etc/init.d/seeddms
rc-update -u
# Install config update script
cp srv/seeddms/update-conf.sh /srv/seeddms/update-conf.sh
# Stop services required for build
[ ! -z ${STOP_POSTGRES} ] && service postgres stop