Fix the detection of rpm vs deb systems.
[arvados.git] / build / go-python-package-scripts / prerm
1 #!/bin/sh
2 # Copyright (C) The Arvados Authors. All rights reserved.
3 #
4 # SPDX-License-Identifier: AGPL-3.0
5
6 # Detect rpm-based systems: the exit code of the following command is zero
7 # on rpm-based systems
8 /usr/bin/rpm -q -f /usr/bin/rpm >/dev/null 2>&1
9
10 if [ "$?" = "0" ]; 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%.prerm}"
19     pkgtype=deb
20     prefix=/usr
21 fi
22
23 set -e
24 case "${pkgtype}-${1}" in
25     deb-remove | rpm-0)
26         if [ -e /run/systemd/system ]; then
27             systemctl stop "${pkg}" || true
28             systemctl disable "${pkg}" || true
29         fi
30         if [ -e "${prefix}/share/doc/${pkg}/${pkg}.service" ]; then
31             # Unit files from Python packages get installed by
32             # postinst so we have to remove them explicitly here.
33             rm "/lib/systemd/system/${pkg}/${pkg}.service" || true
34         fi
35         ;;
36 esac