From 0190f60077c76da7e83a2baccd94eb6be065f38d Mon Sep 17 00:00:00 2001 From: hugoShaka Date: Mon, 3 Mar 2025 11:19:44 -0500 Subject: [PATCH] Fix RPM linking logic --- build.assets/build-package.sh | 9 ++++++++- examples/systemd/before-remove | 8 ++++++-- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/build.assets/build-package.sh b/build.assets/build-package.sh index 7207873aa1f28..186d5d5684a70 100755 --- a/build.assets/build-package.sh +++ b/build.assets/build-package.sh @@ -183,6 +183,11 @@ if [[ "${RUNTIME}" == "fips" ]]; then OPTIONAL_RUNTIME_SECTION+="-fips" fi +# After install is --after-install except for RPM, we use --rpm-posttrans. +# This is because RPM runs after install scrips before the old package removal, +# so old Teleport are still here and we cannot run our teleport-update symlink logic. +AFTER_INSTALL_TARGET="--after-install" + # set variables appropriately depending on type of package being built if [[ "${TELEPORT_TYPE}" == "ent" ]]; then TARBALL_FILENAME="teleport-ent-v${TELEPORT_VERSION}-${PLATFORM}-${TARBALL_ARCH}${OPTIONAL_TARBALL_SECTION}${OPTIONAL_RUNTIME_SECTION}-bin.tar.gz" @@ -240,6 +245,8 @@ else FILE_PERMISSIONS_STANZA="--rpm-user root --rpm-group root --rpm-use-file-permissions " # the rpm/rpmmacros file suppresses the creation of .build-id files (see https://github.com/gravitational/teleport/issues/7040) EXTRA_DOCKER_OPTIONS="-v $(pwd)/rpm/rpmmacros:/root/.rpmmacros" + + AFTER_INSTALL_TARGET="--rpm-posttrans" # if we set this environment variable, don't sign RPMs (can be useful for building test RPMs # without having the signing keys) if [ "${UNSIGNED_RPM}" == "true" ]; then @@ -375,7 +382,7 @@ else --provides teleport \ --prefix / \ --verbose \ - --after-install /src/post-install \ + "$AFTER_INSTALL_TARGET" /src/post-install \ --before-remove /src/before-remove \ ${CONFIG_FILE_STANZA} \ ${FILE_PERMISSIONS_STANZA} \ diff --git a/examples/systemd/before-remove b/examples/systemd/before-remove index 2c83711d60c76..9bc9c6542999c 100755 --- a/examples/systemd/before-remove +++ b/examples/systemd/before-remove @@ -4,5 +4,9 @@ set -eu -echo "Removing symlinks from Teleport system paths..." -/opt/teleport/system/bin/teleport-update unlink-package || true +if [ $# -ge 1 ] && [ "$1" = "1" ]; then + echo "Skipping symlink removal as this is a package upgrade." +else + echo "Removing symlinks from Teleport system paths..." + /opt/teleport/system/bin/teleport-update unlink-package || true +fi