简体   繁体   English

Mac OS X上的软件包卸载程序

[英]Uninstaller for package on Mac OS X

As a service to my users I would like to provide an uninstall script to completely remove all traces of my application on Mac OS X. The application is installed using a package rather than just being dragged into the Applications folder because it is a daemon-type app that also requires to run a script at installation to be launched. 作为我的用户的服务,我想提供一个卸载脚本来完全删除我的应用程序在Mac OS X上的所有痕迹。应用程序使用包安装而不是仅仅被拖入Applications文件夹,因为它是一个守护进程类型应用程序还需要在安装时运行脚本才能启动。

My thinking is to include a file called uninstall.sh and place it into /Library/Application Support/com.<mycompany>.<myapplication>/ and refer to this from the application documentation. 我的想法是包含一个名为uninstall.sh的文件,并将其放入/Library/Application Support/com.<mycompany>.<myapplication>/并从应用程序文档中引用它。 The purpose is basically to stop the daemon if running, unload and delete the corresponding plist as well as remove any application files. 目的基本上是在运行,卸载和删除相应的plist以及删除任何应用程序文件时停止守护程序。 Does this sound reasonable or are there better methods to accomplish this? 这听起来合理还是有更好的方法来实现这一目标?

Also I am wondering if it is good practice to also remove traces of the package using pkgutil --forget - if I don't do this, the next time the package is installed it shows up as being upgraded instead of installed. 另外我想知道是否使用pkgutil --forget删除软件包的痕迹是好的做法 - 如果我不这样做,下次安装软件包时它会显示为升级而不是安装。 Any recommendations or pointers to best-practice information? 有关最佳实践信息的任何建议或指示?

Is there no standard way of doing this on OS X? 在OS X上没有标准的方法吗?

There is no standard way of doing this on OS X. Yes, shocking, I know. 在OS X上没有标准的方法可以做到这一点。是的,令人震惊,我知道。 Apple consistently warns everyone away from package installers (among other things by providing insufficient documentation for them). Apple始终警告所有人远离软件包安装程序(除其他外,为他们提供的文档不足)。 They then exclusively use package installers for their own standalone apps.... go figure. 然后,他们专门为自己的独立应用程序使用软件包安装程序....

Yes, you should include pkgutil --forget . 是的,你应该包括pkgutil --forget

If your customers are comfortable with this kind of script, then your approach sounds fine. 如果您的客户对这种脚本感到满意,那么您的方法听起来不错。 If they want a "double-click-on-it" then you should probably put the uninstaller in /Applications , but avoid that if you can. 如果他们想要“双击它”,那么您应该将卸载/Applications放在/Applications ,但如果可以,请避免使用。

If you have a GUI, Status Item, or Preference Panel, then it's nice to put a "Uninstall" button or menu item there rather than requiring them to go mess around with Terminal. 如果您有一个GUI,状态项或首选项面板,那么最好在其中放置一个“卸载”按钮或菜单项,而不是要求它们与终端混乱。

BTW, if you go looking for the Software Delivery Guide, it's been moved for a year or so now, while they "update" it. 顺便说一句,如果你去寻找软件交付指南,它已被移动了一年左右,而他们“更新”它。

the inability to remove packages has bugged me for years, so i've written a tool to uninstall packages: 无法删除软件包多年来一直困扰着我,所以我编写了一个卸载软件包的工具:

http://www.corecode.at/uninstallpkg/index.html http://www.corecode.at/uninstallpkg/index.html

its a bit better than the shell scripts to do it floating around because it makes sure never to remove any files that are used by any other installed packages 它比shell脚本好一点,因为它确保永远不会删除任何其他安装的包使用的任何文件

The way I solved this was to use Automator , create an application document and then add dialog and script actions. 我解决这个问题的方法是使用Automator ,创建一个应用程序文档,然后添加对话框和脚本操作。 Finally save your Automator application document and you end up with a simple GUI application to run the uninstall. 最后保存Automator应用程序文档,最后得到一个简单的GUI应用程序来运行卸载。

Often the uninstall action requires administrator privileges - I solved this in Automator by running a shell script action that generates another shell script that can then by run in an applescript action as follows: 卸载操作通常需要管理员权限 - 我在Automator中通过运行shell脚本操作来解决此问题,该操作生成另一个shell脚本,然后可以通过AppleScript操作运行,如下所示:

on run {input, parameters}
    do shell script "/tmp/uninstaller.sh" with administrator privileges
    return input
end run

I have a similar application and came across the same issue. 我有一个类似的应用程序,并遇到了同样的问题。 The approach I took was one that I have seen other applications use. 我采用的方法是我见过其他应用程序使用的方法。 Rather than simply distributing the .pkg installer, wrap it up in a .dmg file. 而不是简单地分发.pkg安装程序,将其包装在.dmg文件中。 The uninstall script can be included with the .pkg in the .dmg. 卸载脚本可以包含在.dmg中的.pkg中。

The uninstall script is then renamed to "uninstall.tool". 然后将卸载脚本重命名为“uninstall.tool”。 The .tool extension allows users to run the script by double clicking, rather than having to run it from the command line. .tool扩展名允许用户通过双击来运行脚本,而不必从命令行运行它。

Slightly unconventional, but aren't these all. 稍微不同寻常,但不是这些。 I have Homebrew and cask installed. 我安装了Homebrew和cask。 I was able to uninstall a .pkg with the following: 我能够使用以下内容卸载.pkg:

 brew cask uninstall --force <pkg_name>

ex. 恩。 brew cask uninstall --force dockertools brew cask uninstall --force dockertools

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM