2018-01-08 15:48:23 +01:00
|
|
|
#!/bin/sh
|
2018-07-15 21:55:35 +02:00
|
|
|
set -e
|
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
|
|
|
|
2018-01-23 21:27:18 +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
|
|
|
|
2017-12-04 08:57:59 +01:00
|
|
|
# Create databases
|
2017-12-02 00:29:49 +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-03 19:43:50 +01:00
|
|
|
|
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
|
2018-04-29 20:48:57 +02:00
|
|
|
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
|
2018-09-04 21:42:26 +02:00
|
|
|
vmmgr update-login gnuhealth "${GNUHEALTH_ADMIN_USER}" "${GNUHEALTH_ADMIN_PWD}"
|
2017-12-02 00:29:49 +01:00
|
|
|
|
2017-12-04 08:57:59 +01:00
|
|
|
# Populate demo database
|
2018-03-25 23:11:44 +02:00
|
|
|
wget http://health.gnu.org/downloads/postgres_dumps/gnuhealth-32-demo.sql.gz -O /tmp/gnuhealth_demo.sql.gz
|
2018-09-13 20:42:11 +02:00
|
|
|
zcat /tmp/gnuhealth_demo.sql.gz | lxc-attach -u 5432 -g 5432 postgres -- sh -c "PGPASSWORD=${GNUHEALTH_PWD} psql gnuhealth_demo gnuhealth"
|
2017-12-04 08:57:59 +01:00
|
|
|
rm -f /tmp/gnuhealth_demo.sql.gz
|
2018-07-15 21:55:35 +02:00
|
|
|
|
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
|
|
|
|
|
2018-09-20 15:45:00 +02:00
|
|
|
# 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-20 15:45:00 +02:00
|
|
|
|
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
|