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

39 lines
1.3 KiB
Bash
Raw Normal View History

2018-01-08 15:48:23 +01:00
#!/bin/sh
2018-10-28 16:04:11 +01:00
set -ev
2017-12-02 00:29:49 +01:00
2018-10-26 15:02:11 +02:00
cd $(realpath $(dirname "${0}"))/install
2017-12-02 00:29:49 +01:00
# Check prerequisites
2018-09-13 20:42:11 +02:00
[ ! -e /run/openrc/started/postgres ] && service postgres start && STOP_POSTGRES=1
2017-12-02 00:29:49 +01:00
# Create databases
2018-11-17 20:43:34 +01:00
export GNUHEALTH_PWD=$(head -c 18 /dev/urandom | base64 | tr -d '/+=')
2018-10-25 22:22:36 +02:00
envsubst <createdb.sql | lxc-attach -u 5432 -g 5432 postgres -- psql
2017-12-02 00:29:49 +01:00
# Configure GNU Health
2017-12-29 16:31:48 +01:00
mkdir -p /srv/gnuhealth/conf/
2018-10-25 22:22:36 +02:00
envsubst <srv/gnuhealth/conf/trytond.conf >/srv/gnuhealth/conf/trytond.conf
2017-12-02 00:29:49 +01:00
# Populate database
export GNUHEALTH_ADMIN_USER="admin"
2017-12-02 00:29:49 +01:00
export GNUHEALTH_ADMIN_PWD=$(head -c 12 /dev/urandom | base64)
2018-09-13 20:32:57 +02:00
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
2017-12-02 00:29:49 +01:00
# 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"
2018-09-13 20:32:57 +02:00
# Install service
2018-10-25 22:22:36 +02:00
cp etc/init.d/gnuhealth /etc/init.d/gnuhealth
2018-09-13 20:32:57 +02:00
rc-update -u
# Install config update script
2018-10-25 22:22:36 +02:00
cp srv/gnuhealth/update-conf.sh /srv/gnuhealth/update-conf.sh
2018-09-13 20:32:57 +02:00
# Stop services required for setup
2018-09-13 20:42:11 +02:00
[ ! -z ${STOP_POSTGRES} ] && service postgres stop
2018-10-28 19:50:35 +01:00
# Register application
2019-02-26 21:12:41 +01:00
vmmgr register-app gnuhealth gh "${GNUHEALTH_ADMIN_USER}" "${GNUHEALTH_ADMIN_PWD}"