48 lines
1.8 KiB
Bash
Executable File
48 lines
1.8 KiB
Bash
Executable File
#!/bin/sh
|
|
set -ev
|
|
|
|
cd $(realpath $(dirname "${0}"))/install
|
|
|
|
# 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 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 108010:108010 /srv/seeddms/conf
|
|
chown 108010:108010 /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 108010:108010 /srv/seeddms/seeddms_conf
|
|
|
|
# Install config update script
|
|
cp update-conf.sh /srv/seeddms/update-conf.sh
|
|
|
|
# Stop services required for setup
|
|
service seeddms-postgres stop
|
|
|
|
# Register application
|
|
vmmgr register-app seeddms dms "${SEEDDMS_ADMIN_USER}" "${SEEDDMS_ADMIN_PWD}"
|
|
|
|
# TODO: cron
|