You're right that updating an app does run the "remove" scripts (and also the install scripts, for the next version).
However, the package system will also pass command line parameters to the scripts, and you can use those to determine which scenario you're in: upgrade, or uninstall.
If you just want to reverse engineer what parameters were passed to the script, place this in the script (e.g. postrm
):
echo "postrm called with args= " $1 $2
When I install an update, and remove a package, I then see this:
iPhone5:~ root# dpkg -i /Applications/HelloJB.deb
(Reading database ... 3530 files and directories currently installed.)
Preparing to replace com.mycompany.hellojb 1.0-73 (using /Applications/HelloJB.deb) ...
prerm called with args= upgrade 1.0-73
Unpacking replacement com.mycompany.hellojb ...
Setting up com.mycompany.hellojb (1.0-74) ...
postinst called with args= configure 1.0-73
iPhone5:~ root# dpkg -r com.mycompany.hellojb
(Reading database ... 3530 files and directories currently installed.)
Removing com.mycompany.hellojb ...
prerm called with args= remove
postrm called with args= remove
So, if you only want to rm
a file during an uninstall, put this in the postrm
script:
#!/bin/bash
echo "postrm" $1
if [ $1 = "remove" ]; then
echo "deleting user data on uninstall"
/bin/rm /var/mobile/Library/Application Support/TweakName/file.save
fi
exit 0
Note: you didn't say whether these are being installed by Cydia, or by dpkg
directly at the command line. I can't test with Cydia right now, but the general concept should be the same. As you've probably noticed, when installing packages through Cydia, it shows you the standard output from the installer scripts as they run.