سؤال

I'm writing tweaks for jailbroken iOS, which are packaged in .deb files. The tweak is saving its data at /var/mobile/Library/Application Support/TweakName/file.save. I'd like to rm that save file when a user uninstalls the tweak, so that I don't leave files lying around. But my understanding is that the postrm script runs when a package is updated as well as when it's deleted, and I'd like to preserve the saved state between versions, as I don't expect any update to change the save format (and I can deal with that if it does arise).

So, is there any way to distinguish an uninstall from an update, and run a command only in the case of an uninstall?

هل كانت مفيدة؟

المحلول

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.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top