Merge branch '10151-cwl-dir-listing' closes #10151
[arvados.git] / build / go-python-package-scripts / postinst
1 #!/bin/sh
2
3 set -e
4
5 # NOTE: This package name detection will only work on Debian.
6 # If this postinst script ever starts doing work on Red Hat,
7 # we'll need to adapt this code accordingly.
8 script="$(basename "${0}")"
9 pkg="${script%.postinst}"
10 systemd_unit="${pkg}.service"
11
12 case "${1}" in
13     configure)
14         if [ -d /lib/systemd/system ]
15         then
16             # Python packages put all data files in /usr, so we copy
17             # them to /lib at install time.
18             py_unit="/usr/share/doc/${pkg}/${pkg}.service"
19             if [ -e "${py_unit}" ]
20             then
21                 cp "${py_unit}" /lib/systemd/system/
22             fi
23         fi
24
25         if [ -e /run/systemd/system ]; then
26             eval "$(systemctl -p UnitFileState show "${systemd_unit}")"
27             case "${UnitFileState}" in
28                 disabled)
29                     # Failing to enable or start the service is not a
30                     # package error, so don't let errors here
31                     # propagate up.
32                     systemctl enable "${systemd_unit}" || true
33                     systemctl start "${systemd_unit}" || true
34                     ;;
35                 enabled)
36                     systemctl daemon-reload || true
37                     systemctl reload-or-try-restart "${systemd_unit}" || true
38                     ;;
39             esac
40         fi
41         ;;
42 esac