diff --git a/orbit/changes/14380-rpm-graceful-upgrade b/orbit/changes/14380-rpm-graceful-upgrade new file mode 100644 index 000000000..97e82c95e --- /dev/null +++ b/orbit/changes/14380-rpm-graceful-upgrade @@ -0,0 +1 @@ +* Add a conditional check in the %postun script to prevent file deletion during RPM upgrade. The check ensures that files and directories are only removed during a full uninstall ( equals 0), safeguarding necessary files from unintended deletion during an upgrade. \ No newline at end of file diff --git a/orbit/pkg/packaging/linux_shared.go b/orbit/pkg/packaging/linux_shared.go index 0ec882353..0e425790c 100644 --- a/orbit/pkg/packaging/linux_shared.go +++ b/orbit/pkg/packaging/linux_shared.go @@ -364,7 +364,11 @@ pkill fleet-desktop || true func writePostRemove(opt Options, path string) error { if err := ioutil.WriteFile(path, []byte(`#!/bin/sh -rm -rf /var/lib/orbit /var/log/orbit /usr/local/bin/orbit /etc/default/orbit /usr/lib/systemd/system/orbit.service /opt/orbit +# For RPM during uninstall, $1 is 0 +# For Debian during remove, $1 is "remove" +if [ "$1" = 0 ] || [ "$1" = "remove" ]; then + rm -rf /var/lib/orbit /var/log/orbit /usr/local/bin/orbit /etc/default/orbit /usr/lib/systemd/system/orbit.service /opt/orbit +fi `), constant.DefaultFileMode); err != nil { return fmt.Errorf("write file: %w", err) }