2017-12-02 00:29:49 +01:00
|
|
|
#!/bin/bash
|
|
|
|
|
2017-12-04 17:48:37 +01:00
|
|
|
SOURCE_DIR=$(realpath $(dirname "${0}"))/gnuhealth
|
2017-12-02 00:29:49 +01:00
|
|
|
|
|
|
|
# Install dependencies for GNU Health
|
|
|
|
apt-get -y --no-install-recommends install python3 python3-virtualenv virtualenv
|
|
|
|
|
2017-12-03 22:03:24 +01:00
|
|
|
# Add NodeJS repository for Sao (Tryton web client)
|
2017-12-03 19:43:50 +01:00
|
|
|
wget https://deb.nodesource.com/gpgkey/nodesource.gpg.key -O - | apt-key add -
|
|
|
|
echo 'deb https://deb.nodesource.com/node_8.x xenial main' > /etc/apt/sources.list.d/nodejs.list
|
|
|
|
apt-get -y update
|
|
|
|
|
2017-12-03 22:03:24 +01:00
|
|
|
# Install dependencies for Sao (Tryton web client)
|
2017-12-03 19:43:50 +01:00
|
|
|
apt-get -y --no-install-recommends install nodejs
|
|
|
|
|
|
|
|
# Download GNU Health
|
2017-12-02 00:29:49 +01:00
|
|
|
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
|
|
|
|
|
2017-12-03 22:03:24 +01:00
|
|
|
# Clone Sao (Tryton web client) repository
|
2017-12-03 23:38:36 +01:00
|
|
|
git clone -b 4.2 --single-branch --depth 1 https://github.com/tryton/sao /srv/gnuhealth/sao
|
|
|
|
|
|
|
|
# Apply Sao (Tryton web client) dependencies patch
|
2017-12-04 17:48:37 +01:00
|
|
|
patch -d /srv/gnuhealth/sao -p0 <${SOURCE_DIR}/gnuhealth-sao-dependencies.patch
|
2017-12-03 19:43:50 +01:00
|
|
|
|
2017-12-02 00:29:49 +01:00
|
|
|
# Create Python virtualenv
|
|
|
|
virtualenv --system-site-packages -p /usr/bin/python3 /srv/gnuhealth
|
|
|
|
echo '. /srv/gnuhealth/bin/activate' >/srv/gnuhealth/.bash_profile
|
|
|
|
|
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 '/+=')
|
2017-12-04 17:48:37 +01:00
|
|
|
envsubst <${SOURCE_DIR}/tmp/gnuhealth-createdb.sql >/tmp/gnuhealth-createdb.sql
|
2017-12-02 00:29:49 +01:00
|
|
|
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
|
|
|
|
|
2017-12-03 22:03:24 +01:00
|
|
|
# Install Sao (Tryton web client)
|
2017-12-03 19:43:50 +01:00
|
|
|
sudo -u gnuhealth npm install --production --prefix /srv/gnuhealth/sao
|
|
|
|
sudo -u gnuhealth bash -c 'cd /srv/gnuhealth/sao && /srv/gnuhealth/sao/node_modules/grunt-cli/bin/grunt'
|
|
|
|
|
2017-12-02 00:29:49 +01:00
|
|
|
# Configure GNU Health
|
2017-12-04 17:48:37 +01:00
|
|
|
envsubst <${SOURCE_DIR}/srv/gnuhealth/gnuhealth/tryton/server/config/trytond.conf >/srv/gnuhealth/gnuhealth/tryton/server/config/trytond.conf
|
2017-12-02 00:29:49 +01:00
|
|
|
|
|
|
|
# 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
|
|
|
|
|
2017-12-04 08:57:59 +01:00
|
|
|
# Populate demo database
|
|
|
|
wget http://health.gnu.org/downloads/postgres_dumps/gnuhealth-3.2rc1.sql.gz -O /tmp/gnuhealth_demo.sql.gz
|
|
|
|
export PGPASSWORD=${GNUHEALTH_PWD}
|
|
|
|
zcat /tmp/gnuhealth_demo.sql.gz | psql gnuhealth_demo gnuhealth
|
|
|
|
unset PGPASSWORD
|
|
|
|
rm -f /tmp/gnuhealth_demo.sql.gz
|
|
|
|
|
2017-12-02 00:29:49 +01:00
|
|
|
# Configure GNU Health service
|
2017-12-04 17:48:37 +01:00
|
|
|
cp ${SOURCE_DIR}/lib/systemd/system/gnuhealth.service /lib/systemd/system/gnuhealth.service
|
2017-12-02 00:29:49 +01:00
|
|
|
systemctl daemon-reload
|
|
|
|
systemctl enable gnuhealth
|
|
|
|
systemctl start gnuhealth
|
|
|
|
|
2017-12-03 22:03:24 +01:00
|
|
|
# Create nginx site definition
|
2017-12-04 17:48:37 +01:00
|
|
|
cp ${SOURCE_DIR}/etc/nginx/sites-available/gnuhealth /etc/nginx/sites-available/gnuhealth
|
2017-12-03 22:03:24 +01:00
|
|
|
ln -s /etc/nginx/sites-available/gnuhealth /etc/nginx/sites-enabled/gnuhealth
|
|
|
|
|
|
|
|
# Restart nginx
|
|
|
|
systemctl restart nginx
|
|
|
|
|
2017-12-02 00:29:49 +01:00
|
|
|
# Add portal application definition
|
2017-12-04 17:38:48 +01:00
|
|
|
portal-app-manager gnuhealth "https://{host}:8006/index.html" admin "${GNUHEALTH_ADMIN_PWD}"
|
|
|
|
portal-app-manager gnuhealth-clients -p clienturl "{host}:8006"
|