Spotter-VM/lxc-apps/seeddms/install.sh

44 lines
1.8 KiB
Bash
Executable File

#!/bin/sh
set -ev
# Create Postgres instance
mkdir -p /srv/seeddms/postgres_data
chown -R 105432:105432 /srv/seeddms/postgres_data
chmod 700 /srv/seeddms/postgres_data
lxc-execute -n seeddms-postgres -- initdb -D /var/lib/postgresql
# Configure Postgres
cp postgres_data/postgresql.conf /srv/seeddms/postgres_data/postgresql.conf
cp postgres_data/pg_hba.conf /srv/seeddms/postgres_data/pg_hba.conf
# Populate database
export SEEDDMS_PWD=$(head -c 18 /dev/urandom | base64 | tr -d '+/=')
service lxc-seeddms-postgres start
envsubst <createdb.sql | lxc-attach -u 5432 -g 5432 seeddms-postgres -- psql
lxc-execute seeddms -- cat /srv/seeddms/create_tables-postgres.sql | lxc-attach seeddms-postgres -- sh -c "PGPASSWORD=${SEEDDMS_PWD} psql seeddms seeddms"
cat custom.sql | lxc-attach -u 5432 -g 5432 seeddms-postgres -- psql seeddms
# Copy existing files into persistent storage
mkdir -p /srv/seeddms/seeddms_conf /srv/seeddms/seeddms)data
chown 108080:108080 /srv/seeddms/conf
chown 108080:108080 /srv/seeddms/data
lxc-execute seeddms -- tar -cC /srv/seeddms/conf . | tar -xC /srv/seeddms/seeddms_conf
lxc-execute seeddms -- tar -cC /srv/seeddms/data . | tar -xC /srv/seeddms/seeddms_data
# Configure SeedDMS
envsubst <seeddms_conf/settings.xml >/srv/seeddms/seeddms_conf/settings.xml
export SEEDDMS_ADMIN_USER=admin
export SEEDDMS_ADMIN_PWD=$(head -c 12 /dev/urandom | base64 | tr -d '+/=')
export SEEDDMS_ADMIN_EMAIL=admin@example.com
envsubst <adminpwd.sql | lxc-attach -u 5432 -g 5432 seeddms-postgres -- psql seeddms
chown -R 108080:108080 /srv/seeddms/seeddms_conf
# Install config update script
cp update-conf.sh /srv/seeddms/update-conf.sh
# Stop services required for setup
service lxc-seeddms-postgres stop
# Register application
vmmgr register-app seeddms dms "${SEEDDMS_ADMIN_USER}" "${SEEDDMS_ADMIN_PWD}"