Skip to content

Fix POSTUN scriptlet on RPM upgrade and uninstall #76

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 7, 2024

Conversation

rosahaj
Copy link
Contributor

@rosahaj rosahaj commented Nov 6, 2024

As mentioned in httptoolkit/httptoolkit-website#85 (comment), upgrading or uninstalling the HttpToolkit RPM package produces the same messages as in this issue: IsmaelMartinez/teams-for-linux#958.

I was curious how other projects addressed this problem and stumbled upon pulsar-edit/pulsar@a47da8e. I combined Pulsar's upgrade check with the POSTUN scriptlet produced by electron-builder to create a custom post-uninstall script for RPM packages.

I tested the fix on Fedora 40 by

  1. building two RPM packages with increasing version numbers
  2. installing the package with the lower version number, then upgrading to the package with the higher version number
  3. uninstalling the latter package

All of these actions succeeded without any issues. Upgrading does not remove the symlink from /usr/bin/httptoolkit to /opt/HTTP Toolkit/httptoolkit. Removing the package removes the /usr/bin/httptoolkit symlink as expected.

@@ -0,0 +1,14 @@
#!/bin/bash

# This check works only for RPMs
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This check was copied from pulsar-edit/pulsar@a47da8e. I'm not sure how they came up with this solution, but it works.

exit 0
fi

# Delete the link to the binary
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I adopted the POSTUN script created by electron-builder (as verified by recreating the SPEC file):

#!/bin/bash

# Delete the link to the binary
if type update-alternatives >/dev/null 2>&1; then
    update-alternatives --remove 'httptoolkit' '/usr/bin/httptoolkit'
else
    rm -f '/usr/bin/httptoolkit'
fi


# Delete the link to the binary
if type update-alternatives >/dev/null 2>&1; then
update-alternatives --remove "httptoolkit" "/opt/HTTP Toolkit/httptoolkit"
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As explained here, the second argument to update-alternatives --remove should be /opt/HTTP Toolkit/toolkit, not /usr/bin/toolkit.

if type update-alternatives >/dev/null 2>&1; then
update-alternatives --remove "httptoolkit" "/opt/HTTP Toolkit/httptoolkit"
else
rm -f "/usr/bin/httptoolkit"
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If update-alternatives is not installed, the /usr/bin/httptoolkit is removed directly. The %post script created by electron-builder does the same thing on installs and upgrades:

#!/bin/bash

if type update-alternatives 2>/dev/null >&1; then
    # Remove previous link if it doesn't use update-alternatives
    if [ -L '/usr/bin/httptoolkit' -a -e '/usr/bin/httptoolkit' -a "`readlink '/usr/bin/httptoolkit'`" != '/etc/alternatives/httptoolkit' ]; then
        rm -f '/usr/bin/httptoolkit'
    fi
    update-alternatives --install '/usr/bin/httptoolkit' 'httptoolkit' '/opt/HTTP Toolkit/httptoolkit' 100 || ln -sf '/opt/HTTP Toolkit/httptoolkit' '/usr/bin/httptoolkit'
else
    ln -sf '/opt/HTTP Toolkit/httptoolkit' '/usr/bin/httptoolkit'
fi

Copy link
Member

@pimterry pimterry left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome work @rosahaj! Thanks for digging into this, great stuff.

I'll merge now. This won't be live immediately and I don't think it's urgent, but I'm planning to do a release next week so it'll be included there.

By the way, in case you're not aware, HTTP Toolkit Pro is totally free for all contributors. Is that something you'd be interested in? If so just let me know what email you'd like for your account - either here or by email at tim @ httptoolkit.com.

@pimterry pimterry merged commit f3bc3ab into httptoolkit:main Nov 7, 2024
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants