40 lines
1.6 KiB
Bash
Executable File
40 lines
1.6 KiB
Bash
Executable File
#!/bin/sh
|
|
set -e
|
|
|
|
SOURCE_DIR=$(realpath $(dirname "${0}"))/setup
|
|
|
|
# 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 <${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
|
|
|
|
# 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
|
|
cp ${SOURCE_DIR}/srv/seeddms/update-conf.sh /srv/seeddms/update-conf.sh
|
|
envsubst <${SOURCE_DIR}/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 <${SOURCE_DIR}/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 service
|
|
cp ${SOURCE_DIR}/etc/init.d/seeddms /etc/init.d/seeddms
|
|
rc-update -u
|
|
|
|
# Install cron job
|
|
cp ${SOURCE_DIR}/etc/periodic/hourly/seeddms /etc/periodic/hourly/seeddms
|
|
|
|
# Stop services required for build
|
|
[ ! -z ${STOP_POSTGRES} ] && service postgres stop
|