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