X-Git-Url: https://git.arvados.org/arvados.git/blobdiff_plain/fd3e91e6cd737554b4ae491a558e52f41bad3d07..2e74236fa27822addd856f194befc28382990ce0:/build/go-python-package-scripts/prerm diff --git a/build/go-python-package-scripts/prerm b/build/go-python-package-scripts/prerm index c6ec18ca10..c0f45d60c6 100755 --- a/build/go-python-package-scripts/prerm +++ b/build/go-python-package-scripts/prerm @@ -1,27 +1,35 @@ #!/bin/sh +# Copyright (C) The Arvados Authors. All rights reserved. +# +# SPDX-License-Identifier: AGPL-3.0 set -e -# NOTE: This package name detection will only work on Debian. -# If this prerm script ever starts doing work on Red Hat, -# we'll need to adapt this code accordingly. -script="$(basename "${0}")" -pkg="${script%.prerm}" -systemd_unit="${pkg}.service" +# Detect rpm-based systems: the exit code of the following command is zero +# on rpm-based systems +if /usr/bin/rpm -q -f /usr/bin/rpm >/dev/null 2>&1; then + # Red Hat ("%{...}" is interpolated at package build time) + pkg="%{name}" + pkgtype=rpm + prefix="${RPM_INSTALL_PREFIX}" +else + # Debian + script="$(basename "${0}")" + pkg="${script%.prerm}" + pkgtype=deb + prefix=/usr +fi -case "${1}" in - remove) +case "${pkgtype}-${1}" in + deb-remove | rpm-0) if [ -e /run/systemd/system ]; then - systemctl stop "${systemd_unit}" || true - systemctl disable "${systemd_unit}" || true + systemctl stop "${pkg}" || true + systemctl disable "${pkg}" || true fi - - # Unit files from Python packages get installed by postinst so - # we have to remove them explicitly here. - py_unit="/usr/share/doc/${pkg}/${pkg}.service" - if [ -e "${py_unit}" ] - then - rm "/lib/systemd/system/${pkg}.service" || true + if [ -e "${prefix}/share/doc/${pkg}/${pkg}.service" ]; then + # Unit files from Python packages get installed by + # postinst so we have to remove them explicitly here. + rm "/lib/systemd/system/${pkg}/${pkg}.service" || true fi ;; esac