9945: first set of changes.
[arvados.git] / build / python-package-scripts / before-remove.sh
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 # Detect rpm-based systems: the exit code of the following command is zero
9 # on rpm-based systems
10 if /usr/bin/rpm -q -f /usr/bin/rpm >/dev/null 2>&1; 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 # populated from the build script
24 # dash only supports one array, $@
25 if [ "%FPM_BINARIES" != "" ]; then
26   set %FPM_BINARIES
27 fi
28
29 if [ "$pkg" != "" ]; then
30   # Remove the binary python files so the package manager doesn't throw warnings
31   # on removing the package.
32   find /usr/share/%PYTHON/dist/$pkg -iname *.pyc -exec rm {} \; || true
33   find /usr/share/%PYTHON/dist/$pkg -iname *.pyo -exec rm {} \; || true
34
35   if [ "%FPM_BINARIES" != "" ]; then
36     # read from $@
37     for binary do
38       if [ -L /usr/bin/$binary ]; then
39         # Remove the symlinks we installed
40         rm -f /usr/bin/$binary
41       fi
42     done
43   fi
44
45   if [ "${pkg#python-}" = "arvados-cwl-runner" ]; then
46     if [ -L /usr/bin/cwl-runner ]; then
47       rm -f /usr/bin/cwl-runner
48     fi
49   fi
50 fi