13200:test update on version in gittaggers on sdk python
[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 if [ "%{name}" != "%\{name\}" ]; then
9     # Red Hat ("%{...}" is interpolated at package build time)
10     pkg="%{name}"
11     pkgtype=rpm
12     prefix="${RPM_INSTALL_PREFIX}"
13 else
14     # Debian
15     script="$(basename "${0}")"
16     pkg="${script%.postinst}"
17     pkgtype=deb
18     prefix=/usr
19 fi
20
21 case "${pkgtype}-${1}" in
22     deb-configure | rpm-1)
23         dest_dir="/lib/systemd/system"
24         if ! [ -d "${dest_dir}" ]; then
25             exit 0
26         fi
27
28         # Find the unit file we need to install.
29         unit_file="${pkg}.service"
30         for dir in \
31             "${prefix}/share/doc/${pkg}" \
32             "${dest_dir}"; do
33             if [ -e "${dir}/${unit_file}" ]; then
34                 src_dir="${dir}"
35                 break
36             fi
37         done
38         if [ -z "${src_dir}" ]; then
39             echo >&2 "WARNING: postinst script did not find ${unit_file} anywhere."
40             exit 0
41         fi
42
43         # Install/update the unit file if necessary.
44         if [ "${src_dir}" != "${dest_dir}" ]; then
45             cp "${src_dir}/${unit_file}" "${dest_dir}/" || exit 0
46         fi
47
48         # Enable service, and make sure systemd re-reads the unit
49         # file, in case we changed it.
50         if [ -e /run/systemd/system ]; then
51             systemctl daemon-reload || true
52             eval "$(systemctl -p UnitFileState show "${pkg}")"
53             case "${UnitFileState}" in
54                 disabled)
55                     # Failing to enable or start the service is not a
56                     # package error, so don't let errors here
57                     # propagate up.
58                     systemctl enable "${pkg}" || true
59                     systemctl start "${pkg}" || true
60                     ;;
61                 enabled)
62                     systemctl reload-or-try-restart "${pkg}" || true
63                     ;;
64             esac
65         fi
66         ;;
67 esac