X-Git-Url: https://git.arvados.org/arvados.git/blobdiff_plain/586e959c9cfbe256682836be98eb451dddaf3ae9..aabea703ee77ca91da710dd9bce9716e5d35d7b2:/build/go-python-package-scripts/prerm diff --git a/build/go-python-package-scripts/prerm b/build/go-python-package-scripts/prerm index 7f4b843d61..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 + 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. - py_unit="/usr/share/doc/${pkg}/${pkg}.service" - if [ -e "${py_unit}" ] - then - rm "/lib/systemd/system/${pkg}.service" || true - fi + rm "/lib/systemd/system/${pkg}/${pkg}.service" || true fi ;; esac