216.2. gnuhealth-5.0.7
Hospital and clinic information system — patients, labs, pharmacy, imaging and stock, on Tryton
| Version | 5.0.7, release 2 |
| Shelf | bioscience — Bioinformatics, chemistry and medical informatics or imaging |
| Phase | 42_graphics (Graphics Stack), 62 of 189 in build order |
| Licence | GPL-3.0-or-later |
| Homepage | https://www.gnuhealth.org/ |
| Build time | 1.1 SBU |
| Installed size | 119.6 MiB in 5292 files |
| Recipe | ports/core/bioscience/gnuhealth/kpkgbuild |
About
GNU Health is a hospital and clinic information system: patients, appointments, laboratory, pharmacy, imaging, genetics and stock. It is a set of modules for the Tryton application server, trytond, which keeps its data in PostgreSQL and serves the Tryton desktop client on TCP port 8000. The port installs the server, the Tryton modules GNU Health builds on, and GNU Health’s own modules, in a prefix of their own, /usr/lib/gnuhealth, and the service 85_gnuhealth, which stays off until a database is configured (Services).
Sources
gnuhealth-5.0.7.tar.gz(17.1 MiB)
sha25612d5c10c82797bcedefc2a90147331b4018fc8a540a33fba08a136bd4c8a13c6
upstream: https://codeberg.org/gnuhealth/his/archive/5.0.7.tar.gz
archive copy: sources-1/bioscience--gnuhealth-5.0.7.tar.gzgnuhealth-vendor-5.0.7.tar.xz(20.5 MiB)
sha2566a8a23e0690f2be83914b774e0f11067ce7b6c5edc2b7fd147494a5da0678e86
a vendor bundle: the dependencies upstream’s own tool would download, packed once
archive copy: sources-1/bioscience--gnuhealth-vendor-5.0.7.tar.xz
Dependencies
Depends on: python3, python3-setuptools, python3-setuptools-scm, python3-pip, python3-wheel, python3-poetry-core, python3-flit-core, python3-hatchling, python3-hatch-tryton, postgresql, python3-psycopg2, python3-lxml, python3-dateutil, python3-pytz, python3-six, python3-pillow, python3-markupsafe, python3-packaging, python3-psutil, python3-qrcode, matplotlib, util-linux.
Required by: no port names it.
Installation
From the repository root, inside the build container, this is the line kdosbuild runs for the port:
script/chroot/exec.sh bash -c 'source script/phases/42_graphics/phase.env && kpkg install gnuhealth'
What kpkg does
kpkg runs these steps, in this order, as root inside the chroot. The port directory is /ports/core/bioscience/gnuhealth.
1. Verify every declared source. Each file a sha256 = line names, found in the port directory or in /var/cache/kpkg/sources, must hash to its line; a mismatch stops the build before anything is unpacked.
cd /ports/core/bioscience/gnuhealth
echo '12d5c10c82797bcedefc2a90147331b4018fc8a540a33fba08a136bd4c8a13c6 gnuhealth-5.0.7.tar.gz' | sha256sum -c -
echo '6a8a23e0690f2be83914b774e0f11067ce7b6c5edc2b7fd147494a5da0678e86 gnuhealth-vendor-5.0.7.tar.xz' | sha256sum -c -
2. Unpack. The work directory is emptied and the first source is unpacked into $SRC with its top directory stripped; any later tarball lands unstripped beside it in $SRC_ROOT, and a file that is not a tarball is copied into $SRC.
SRC_ROOT=/var/cache/kpkg/work/gnuhealth
SRC=$SRC_ROOT/gnuhealth-5.0.7
PKG=$SRC_ROOT/pkg
rm -rf "$SRC_ROOT"
mkdir -p "$SRC" "$PKG"
tar --no-same-permissions --warning=no-unknown-keyword -xf gnuhealth-5.0.7.tar.gz -C "$SRC" --strip-components=1
Every config.guess and config.sub older than automake’s is then replaced with automake’s, so a configure script recognises the musl target.
3. Build. build.sh is sourced in a subshell under set -e, from $SRC, with name, version, release and the recipe’s helpers pyrequirements, pyruntime and the five paths PKGNAME, PORT_SRC, SRC_ROOT, SRC and PKG set as shell variables. Its body, verbatim:
_home=/usr/lib/gnuhealth
mkdir -p vendor
tar -xf $PORT_SRC/$name-vendor-$version.tar.xz --strip-components=1 -C vendor
_mods=
for d in tryton/health*; do
case ${d##*/} in
health_federation|health_genetics_uniprot|health_orthanc) ;;
*) _mods="$_mods $d" ;;
esac
done
pip3 install --no-deps --no-index --find-links=vendor --no-build-isolation \
--ignore-installed --root=$PKG --prefix=$_home \
defusedxml genshi passlib polib proteus puremagic pycountry \
pydicom python-barcode python-sql python-stdnum pywebdav3-gnuhealth \
relatorio simpleeval werkzeug vobject \
trytond trytond-account trytond-account-invoice trytond-account-product \
trytond-company trytond-country trytond-currency trytond-party \
trytond-product trytond-stock trytond-stock-lot \
gnuhealth-control $_mods
find "$PKG$_home" -path '*/trytond/modules/*/locale/*.po' -delete
install -Dm644 tryton/COPYING "$PKG/usr/share/licenses/$name/COPYING"
install -Dm644 tryton/LICENSES/CC-BY-SA-4.0.txt "$PKG/usr/share/licenses/$name/CC-BY-SA-4.0.txt"
install -d "$PKG$_home/libexec" "$PKG/usr/bin"
cat > "$PKG$_home/libexec/launch" <<'KDOS_SH'
#!/bin/sh
home=/usr/lib/gnuhealth
site=$(python3 -c 'import sys, sysconfig; print(sysconfig.get_path("purelib", vars={"base": sys.argv[1]}))' "$home") || exit 1
plat=$(python3 -c 'import sys, sysconfig; print(sysconfig.get_path("platlib", vars={"platbase": sys.argv[1]}))' "$home") || exit 1
PYTHONPATH=$site:$plat${PYTHONPATH:+:$PYTHONPATH}
TRYTOND_CONFIG=${TRYTOND_CONFIG:-/etc/gnuhealth/trytond.conf}
export PYTHONPATH TRYTOND_CONFIG
exec "$home/bin/${0##*/}" "$@"
KDOS_SH
chmod 755 "$PKG$_home/libexec/launch"
for p in trytond trytond-admin trytond-cron trytond-worker trytond-console \
trytond-stat ghcontrol; do
test -x "$PKG$_home/bin/$p"
ln -s "../lib/gnuhealth/libexec/launch" "$PKG/usr/bin/$p"
done
install -dm750 "$PKG/var/lib/gnuhealth" "$PKG/var/lib/gnuhealth/attach"
install -Dm644 /dev/stdin "$PKG/etc/gnuhealth/trytond.conf" <<'CFG'
# GNU Health server (trytond 7.0).
#
# To bring up a clinic database, once PostgreSQL has a cluster and runs:
#
# su - postgres -s /bin/sh -c 'createuser gnuhealth'
# su - postgres -s /bin/sh -c 'createdb -O gnuhealth -E UTF8 health'
# su gnuhealth -s /bin/sh -c 'trytond-admin -d health --all --email admin@localhost'
# su gnuhealth -s /bin/sh -c 'trytond-admin -d health -u health --activate-dependencies'
#
# then uncomment the uri below and start the service. The Tryton client
# connects to <this machine>:8000, database "health".
[database]
# The role is the unix account the server runs as (peer authentication over
# the local socket), so the uri names no user and no password.
#uri = postgresql:///
path = /var/lib/gnuhealth/attach
[web]
listen = 0.0.0.0:8000
CFG
install -d "$PKG/etc/init.d"
cat > "$PKG/etc/init.d/85_gnuhealth.sh" <<'KDOS_SH'
#!/bin/bash
. /etc/init.d/service_helper
NAME="gnuhealth"
DAEMON="/usr/bin/trytond"
CONF="/etc/gnuhealth/trytond.conf"
case "$1" in
start)
[ ! -x "$DAEMON" ] && { echo "[SKIP] $NAME: $DAEMON not found"; exit 0; }
# The postinstall creates the account in /etc/passwd itself.
if ! grep -q '^gnuhealth:' /etc/passwd 2>/dev/null; then
echo "[SKIP] $NAME: no gnuhealth account (the port's postinstall makes it)"
exit 0
fi
if ! grep -q '^uri *=' "$CONF" 2>/dev/null; then
echo "[SKIP] $NAME: no database uri in $CONF"
exit 0
fi
echo "[KDOS] Starting $NAME..."
supervise "$NAME" setpriv --reuid=gnuhealth --regid=gnuhealth \
--init-groups "$DAEMON" -c "$CONF"
;;
stop) stop_service "$NAME" ;;
status) check_status "$NAME" ;;
*) echo "Usage: $0 {start|stop|status}"; exit 1 ;;
esac
KDOS_SH
chmod 755 "$PKG/etc/init.d/85_gnuhealth.sh"
The switches, and why each is set:
--prefix=$_home— Install every Python distribution of the bundle under/usr/lib/gnuhealthinstead of/usr, scripts in itsbin/and modules in its ownsite-packages. Nothing outside the port finds them there; thelaunchwrapper puts that prefix onPYTHONPATHfor each command.
The common switches of each build system are explained in the Flag glossary.
postinstall.sh runs on the installed system after the package is adopted:
# The server runs as this account, and PostgreSQL's peer authentication maps
# it to the database role of the same name, so the account owns the
# attachment store the server writes.
#
# Everything is written under PKG_ROOT, the root kpkgadd is installing into:
# --root and an A/B update install into a tree that is not the running one, and
# an account made in / instead would be missing from the system that needs it.
#
# The guard reads PKG_ROOT's files: getent answers for the running root, not
# the tree being installed, and would let useradd run against an account the
# target already has.
root="${PKG_ROOT:-/}"
grep -q '^gnuhealth:' "$root/etc/group" 2>/dev/null || groupadd -R "$root" -r gnuhealth
grep -q '^gnuhealth:' "$root/etc/passwd" 2>/dev/null || \
useradd -R "$root" -r -g gnuhealth -d /var/lib/gnuhealth -s /sbin/nologin gnuhealth
# chown resolves a name against the running root's passwd, so the ids are read
# out of PKG_ROOT's.
# The mode is set as well: kpkgadd creates every directory 0755, whatever mode
# it was packaged with, because the package carries no group to give it.
while IFS=: read -r n _ uid gid _; do
[ "$n" = gnuhealth ] || continue
chown "$uid:$gid" "$root/var/lib/gnuhealth" "$root/var/lib/gnuhealth/attach"
chmod 750 "$root/var/lib/gnuhealth" "$root/var/lib/gnuhealth/attach"
done < "$root/etc/passwd"
4. Package. kpkg removes libtool archives, the info directory index, mimeinfo.cache and every fonts.dir from $PKG, copies the source’s licence files into /usr/share/licenses/gnuhealth, prunes what the image does not ship, lints the tree and rolls it reproducibly:
tar --sort=name --format=gnu --numeric-owner --owner=0 --group=0 \
--mtime=@$SOURCE_DATE_EPOCH \
--use-compress-program='xz -9 -T0 --block-size=32MiB --no-adjust' \
-cf gnuhealth-5.0.7-2.tar.xz -C "$PKG" .
5. Adopt. kpkgadd installs the package’s files over the root, refusing a path another package owns, records the file list in /var/lib/kpkg/db/gnuhealth, and runs the triggers its paths call for.
Contents
Installed programs: ghcontrol, trytond, trytond-admin, trytond-console, trytond-cron, trytond-stat, trytond-worker.
Installed directories: /etc/gnuhealth, /usr/lib/gnuhealth, /usr/share/licenses/gnuhealth, /var/lib/gnuhealth.
Notes
- The vendor bundle is the
pypackagesclosure.pypackagesnames every distribution the server installs from the bundle, several pinned (trytond:7.0.57and thetrytond-*modules,proteus,gnuhealth-control,vobject).ports/fetchdownloads that list without resolving dependencies and adds only the build backends the source distributions declare (setuptools, setuptools_scm, flit_core, hatchling, hatch-tryton, poetry_core and their own requirements), which this build never installs:--no-build-isolationbuilds every distribution with the backends that are ports independs.pyrequirements = noandpyruntime = nochange nothing here, because the source tree has no top-levelrequirements.txtor project file for them to act on. Everything else GNU Health imports at run time (psycopg2, lxml, dateutil, pytz, Pillow, qrcode, matplotlib and the rest) is a port independs. Thepip3 installline must name the same set; a name missing there is in the bundle and never installed.vobjectis pinned to 0.9.8 because 0.9.9 reads its version withattr: vobject.VERSION, which imports the package and through it six and dateutil, and the isolated build thatpip downloadruns to read metadata has neither. - Three modules are left out. The loop over
tryton/health*installs every GNU Health module in the source excepthealth_federation,health_genetics_uniprotandhealth_orthanc.health_orthanctalks to an Orthanc PACS throughpyorthanc, which is neither a port nor in the bundle;health_federationtalks to Thalamus, the GNU Health Federation message server, throughrequests, whichdependsdoes not name;health_genetics_uniprotis data only: 39 MB of UniProtKB protein-disease, gene-variant and variant-phenotype records as XML, loaded into the database when the module is activated, on top ofhealth_genetics, which is installed and works without it. - Translations are deleted by hand. Tryton modules carry their translations as
.pofiles undertrytond/modules/*/locale/, which the tree-wide language prune does not match (it removes.mo,.gmoand.qmcatalogs), sobuild.shdeletes them itself; see Size and language policy. - The commands are one wrapper.
trytond,trytond-admin,trytond-cron,trytond-worker,trytond-console,trytond-statandghcontrolin/usr/binare symbolic links to/usr/lib/gnuhealth/libexec/launch, which computes the prefix’spurelibandplatlibdirectories withsysconfig, adds them toPYTHONPATH, setsTRYTOND_CONFIGto/etc/gnuhealth/trytond.confunless it is already set, and runs the real script of the same name. Thetest -xbefore each link stops the build if pip did not install that script. - The service waits for configuration.
85_gnuhealthskips itself while thegnuhealthaccount is missing ortrytond.confhas nouriline, and otherwise runstrytondunder the supervisor asgnuhealththroughsetpriv. The shippedtrytond.conflists the commands that create the database role and the database and initialise it; itsuriis commented out. The database URI names no user, because PostgreSQL’s peer authentication over the local socket maps thegnuhealthaccount to the role of the same name. - The postinstall writes into the target root.
postinstall.shcreates thegnuhealthgroup and system account underPKG_ROOT, reads the ids back out of that root’s/etc/passwdtochown/var/lib/gnuhealthand itsattach/store, and sets both to0750, becausekpkgaddcreates every directory0755; see postinstall.sh.