22001: Install PySDK earlier in run-tests.sh
[arvados.git] / build / go-python-package-scripts / postinst
1 #!/bin/sh
2 # Copyright (C) The Arvados Authors. All rights reserved.
3 #
4 # SPDX-License-Identifier: AGPL-3.0
5
6 set -e
7
8 # Detect rpm-based systems: the exit code of the following command is zero
9 # on rpm-based systems
10 if /usr/bin/rpm -q -f /usr/bin/rpm >/dev/null 2>&1; then
11     # Red Hat ("%{...}" is interpolated at package build time)
12     pkg="%{name}"
13     pkgtype=rpm
14     prefix="${RPM_INSTALL_PREFIX}"
15 else
16     # Debian
17     script="$(basename "${0}")"
18     pkg="${script%.postinst}"
19     pkgtype=deb
20     prefix=/usr
21 fi
22
23 case "${pkgtype}-${1}" in
24     deb-configure | rpm-1)
25         dest_dir="/lib/systemd/system"
26         if ! [ -d "${dest_dir}" ]; then
27             exit 0
28         fi
29
30         # Find the unit file we need to install.
31         unit_file="${pkg}.service"
32         for dir in \
33             "${prefix}/share/doc/${pkg}" \
34             "${dest_dir}"; do
35             if [ -e "${dir}/${unit_file}" ]; then
36                 src_dir="${dir}"
37                 break
38             fi
39         done
40         if [ -z "${src_dir}" ]; then
41             echo >&2 "WARNING: postinst script did not find ${unit_file} anywhere."
42             exit 0
43         fi
44
45         # Install/update the unit file if necessary.
46         if [ "${src_dir}" != "${dest_dir}" ]; then
47             cp "${src_dir}/${unit_file}" "${dest_dir}/" || exit 0
48         fi
49
50         # Enable service, and make sure systemd re-reads the unit
51         # file, in case we changed it.
52         if [ -e /run/systemd/system ]; then
53             systemctl daemon-reload || true
54             eval "$(systemctl -p UnitFileState show "${pkg}")"
55             case "${UnitFileState}" in
56                 disabled)
57                     # Failing to enable or start the service is not a
58                     # package error, so don't let errors here
59                     # propagate up.
60                     systemctl enable "${pkg}" || true
61                     systemctl start "${pkg}" || true
62                     ;;
63                 enabled)
64                     systemctl reload-or-try-restart "${pkg}" || true
65                     ;;
66             esac
67         fi
68         ;;
69 esac