Spotter-VM/seeddms/setup.sh

39 lines
1.5 KiB
Bash
Raw Normal View History

2018-01-08 15:06:11 +01:00
#!/bin/sh
set -e
2018-09-14 09:02:16 +02:00
SOURCE_DIR=$(realpath $(dirname "${0}"))/setup
# Check prerequisites
2018-09-14 09:02:16 +02:00
[ ! -e /run/openrc/started/postgres ] && service postgres start && STOP_POSTGRES=1
2017-06-30 18:17:07 +02:00
# Populate database
export SEEDDMS_PWD=$(head -c 18 /dev/urandom | base64)
2018-09-14 09:02:16 +02:00
envsubst <${SOURCE_DIR}/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 ${SOURCE_DIR}/custom.sql | lxc-attach -u 5432 -g 5432 postgres -- psql seeddms
2018-01-08 15:06:11 +01:00
# Copy existing files into persistent storage
2018-01-15 20:06:06 +01:00
mkdir -p /srv/seeddms/conf /srv/seeddms/data
2018-09-14 09:02:16 +02:00
cp -rp /var/lib/lxc/seddms/seeddms/srv/seeddms/conf/. /srv/seeddms/conf
cp -rp /var/lib/lxc/seddms/seeddms/srv/seeddms/data/. /srv/seeddms/data
2018-01-08 15:06:11 +01:00
chown -R 8010:8010 /srv/seeddms/data
2017-06-30 18:17:07 +02:00
# Configure SeedDMS
2018-01-08 15:06:11 +01:00
envsubst <${SOURCE_DIR}/srv/seeddms/conf/settings.xml >/srv/seeddms/conf/settings.xml
2017-09-16 21:35:44 +02:00
export SEEDDMS_ADMIN_USER=admin
export SEEDDMS_ADMIN_PWD=$(head -c 12 /dev/urandom | base64)
export SEEDDMS_ADMIN_EMAIL=admin@example.com
2018-09-14 09:02:16 +02:00
envsubst <${SOURCE_DIR}/adminpwd.sql | lxc-attach -u 5432 -g 5432 postgres -- psql seeddms
chown -R 8010:8010 /srv/seeddms/conf
2018-09-04 21:42:26 +02:00
vmmgr update-login seeddms "${SEEDDMS_ADMIN_USER}" "${SEEDDMS_ADMIN_PWD}"
2018-09-14 09:02:16 +02:00
# Install service
cp ${SOURCE_DIR}/etc/init.d/seeddms /etc/init.d/seeddms
rc-update -u
2017-10-07 23:09:08 +02:00
# Install cron job
2018-01-08 15:06:11 +01:00
cp ${SOURCE_DIR}/etc/periodic/hourly/seeddms /etc/periodic/hourly/seeddms
# Stop services required for build
2018-09-14 09:02:16 +02:00
[ ! -z ${STOP_POSTGRES} ] && service postgres stop