Spotter-VM/gnuhealth.sh

49 lines
1.9 KiB
Bash
Raw Normal View History

2017-12-02 00:29:49 +01:00
#!/bin/bash
SOURCE_DIR=$(realpath $(dirname "${0}"))
# Install dependencies for GNU Health
apt-get -y --no-install-recommends install python3 python3-virtualenv virtualenv
# Donwload GNU Health
wget http://ftp.gnu.org/gnu/health/gnuhealth-3.2.8.tar.gz -O /tmp/gnuhealth.tgz
tar xzf /tmp/gnuhealth.tgz -C /srv
mv /srv/gnuhealth-3.2.8 /srv/gnuhealth
rm -f /tmp/gnuhealth.tgz
# Create Python virtualenv
virtualenv --system-site-packages -p /usr/bin/python3 /srv/gnuhealth
echo '. /srv/gnuhealth/bin/activate' >/srv/gnuhealth/.bash_profile
# Create database
export GNUHEALTH_PWD=$(head -c 18 /dev/urandom | base64 | tr -d '/+=')
envsubst <${SOURCE_DIR}/gnuhealth/tmp/gnuhealth-createdb.sql >/tmp/gnuhealth-createdb.sql
sudo -u postgres psql -f /tmp/gnuhealth-createdb.sql
rm -f /tmp/gnuhealth-createdb.sql
# Create GNU Health OS user
adduser --system --group --home /srv/gnuhealth --shell /bin/bash gnuhealth
chown -R gnuhealth:gnuhealth /srv/gnuhealth
# Install GNU Health
sudo -u gnuhealth -i /srv/gnuhealth/gnuhealth-setup install
# Configure GNU Health
envsubst <${SOURCE_DIR}/gnuhealth/srv/gnuhealth/gnuhealth/tryton/server/config/trytond.conf >/srv/gnuhealth/gnuhealth/tryton/server/config/trytond.conf
# Populate database
export GNUHEALTH_ADMIN_PWD=$(head -c 12 /dev/urandom | base64)
echo ${GNUHEALTH_ADMIN_PWD} >/srv/gnuhealth/.adminpwd
sudo -u gnuhealth -i TRYTONPASSFILE=/srv/gnuhealth/.adminpwd /srv/gnuhealth/gnuhealth/tryton/server/trytond-4.2.7/bin/trytond-admin -d gnuhealth --all -v
rm -f /srv/gnuhealth/.adminpwd
# Configure GNU Health service
cp ${SOURCE_DIR}/gnuhealth/lib/systemd/system/gnuhealth.service /lib/systemd/system/gnuhealth.service
systemctl daemon-reload
systemctl enable gnuhealth
systemctl start gnuhealth
# Add portal application definition
${SOURCE_DIR}/basic/portal-app-manager.py gnuhealth "{host}:8006" admin "${GNUHEALTH_ADMIN_PWD}"
2017-12-02 00:29:49 +01:00
${SOURCE_DIR}/basic/portal-app-manager.py gnuhealth-clients