2013-04-26 66 views
2

我正在爲越獄iOS編寫調整,這些文件打包在.deb文件中。調整將其數據保存在/var/mobile/Library/Application Support/TweakName/file.save。我想rm保存文件,當用戶卸載調整,以便我不留下文件躺在。但我的理解是postrm腳本在包更新以及刪除時運行,並且我想保留版本之間的保存狀態,因爲我不希望任何更新更改保存格式(並且我可以處理,如果它出現)。Debian軟件包:在卸載但不升級的rm文件

那麼,有沒有什麼辦法來區分從更新卸載,並只在卸載的情況下運行命令?

回答

3

你說得對,更新應用程序確實會運行「刪除」腳本(以及下一版本的安裝腳本)。

但是,軟件包管理系統也將pass command line parameters to the scripts,您可以用這些來確定你是哪一種情景:升級,或卸載

如果你只是想進行反向工程什麼參數傳遞到腳本,把這個腳本(如postrm):

echo "postrm called with args= " $1 $2 

當我安裝的更新,以及刪除軟件包,我那麼看到這一點:

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 

所以,如果你只是想rm文件的卸載過程中,把這個在postrm腳本:

#!/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 

注意你不說這些是否正在被蘋果蠹安裝,或通過直接dpkg在命令行。我現在不能用Cydia進行測試,但總的概念應該是一樣的。正如您可能已經注意到的那樣,當通過Cydia安裝軟件包時,它會在安裝程序腳本運行時向您顯示標準輸出。

+0

與往常一樣非常有幫助。 Cydia安裝是我的主要用例,所以我會明天測試它並確保它能正常工作。謝謝! – drewmm 2013-04-27 06:11:32

+0

是的,這與Cydia完美合作。謝謝! – drewmm 2013-04-29 05:32:20