39 lines
1.5 KiB
Bash
Executable File
39 lines
1.5 KiB
Bash
Executable File
#!/bin/sh
|
|
set -ev
|
|
|
|
# Create Postgres instance
|
|
mkdir -p /srv/gnuhealth/postgres_data
|
|
chown -R 105432:105432 /srv/gnuhealth/postgres_data
|
|
chmod 700 /srv/gnuhealth/postgres_data
|
|
lxc-execute -n gnuhealth-postgres -- initdb -D /var/lib/postgresql
|
|
|
|
# Configure Postgres
|
|
cp postgres_data/postgresql.conf /srv/gnuhealth/postgres_data/postgresql.conf
|
|
cp postgres_data/pg_hba.conf /srv/gnuhealth/postgres_data/pg_hba.conf
|
|
|
|
# Create databases
|
|
export GNUHEALTH_PWD=$(head -c 18 /dev/urandom | base64 | tr -d '+/=')
|
|
service gnuhealth-postgres start
|
|
envsubst <createdb.sql | lxc-attach -u 5432 -g 5432 gnuhealth-postgres -- psql
|
|
|
|
# Configure GNU Health
|
|
mkdir -p /srv/gnuhealth/gnuhealth_conf/
|
|
envsubst <gnuhealth_conf/trytond.conf >/srv/gnuhealth/gnuhealth_conf/trytond.conf
|
|
|
|
# Populate database
|
|
export GNUHEALTH_ADMIN_USER="admin"
|
|
export GNUHEALTH_ADMIN_PWD=$(head -c 12 /dev/urandom | base64 | tr -d '+/=')
|
|
lxc-execute gnuhealth -- sh -c "echo ${GNUHEALTH_ADMIN_PWD} >/tmp/.adminpwd; TRYTONPASSFILE=/tmp/.adminpwd trytond-admin -d gnuhealth --all -v; rm /tmp/.adminpwd"
|
|
|
|
# Populate demo database
|
|
lxc-execute gnuhealth -- zcat /srv/gnuhealth/gnuhealth_demo.sql.gz | lxc-attach -u 5432 -g 5432 gnuhealth-postgres -- sh -c "PGPASSWORD=${GNUHEALTH_PWD} psql gnuhealth_demo gnuhealth"
|
|
|
|
# Install config update script
|
|
cp update-conf.sh /srv/gnuhealth/update-conf.sh
|
|
|
|
# Stop services required for setup
|
|
service gnuhealth-postgres stop
|
|
|
|
# Register application
|
|
vmmgr register-app gnuhealth gh "${GNUHEALTH_ADMIN_USER}" "${GNUHEALTH_ADMIN_PWD}"
|