Spotter-VM/gnuhealth/install.sh
Disassembler ce325cf3d0
Squashed commit of the following:
- Bump basic OS to Alpine 3.9
 - Restructure repo and add layer versioning
 - Use JSON for all metadata
 - Merge abuild branch (but without abuild)
2019-02-26 20:24:02 +01:00

39 lines
1.3 KiB
Bash
Executable File

#!/bin/sh
set -ev
cd $(realpath $(dirname "${0}"))/install
# Check prerequisites
[ ! -e /run/openrc/started/postgres ] && service postgres start && STOP_POSTGRES=1
# Create databases
export GNUHEALTH_PWD=$(head -c 18 /dev/urandom | base64 | tr -d '/+=')
envsubst <createdb.sql | lxc-attach -u 5432 -g 5432 postgres -- psql
# Configure GNU Health
mkdir -p /srv/gnuhealth/conf/
envsubst <srv/gnuhealth/conf/trytond.conf >/srv/gnuhealth/conf/trytond.conf
# Populate database
export GNUHEALTH_ADMIN_USER="admin"
export GNUHEALTH_ADMIN_PWD=$(head -c 12 /dev/urandom | base64)
echo ${GNUHEALTH_ADMIN_PWD} >/var/lib/lxc/gnuhealth/gnuhealth/tmp/.adminpwd
lxc-execute gnuhealth -- sh -c 'TRYTONPASSFILE=/tmp/.adminpwd trytond-admin -d gnuhealth --all -v'
rm -f /var/lib/lxc/gnuhealth/gnuhealth/tmp/.adminpwd
# Populate demo database
zcat /var/lib/lxc/gnuhealth/gnuhealth/srv/gnuhealth/gnuhealth_demo.sql.gz | lxc-attach -u 5432 -g 5432 postgres -- sh -c "PGPASSWORD=${GNUHEALTH_PWD} psql gnuhealth_demo gnuhealth"
# Install service
cp etc/init.d/gnuhealth /etc/init.d/gnuhealth
rc-update -u
# Install config update script
cp srv/gnuhealth/update-conf.sh /srv/gnuhealth/update-conf.sh
# Stop services required for setup
[ ! -z ${STOP_POSTGRES} ] && service postgres stop
# Register application
vmmgr register-app gnuhealth "${GNUHEALTH_ADMIN_USER}" "${GNUHEALTH_ADMIN_PWD}"