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

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/5312837/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-21 07:50:44  来源:igfitidea点击:

Uninstaller for package on Mac OS X

macospackagemakeruninstaller

提问by villintehaspam

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.shand place it into /Library/Application Support/com.<mycompany>.<myapplication>/and refer to this from the application documentation. The purpose is basically to stop the daemon if running, unload and delete the corresponding plist as well as remove any application files. Does this sound reasonable or are there better methods to accomplish this?

我的想法是包含一个名为的文件uninstall.sh并将其放入/Library/Application Support/com.<mycompany>.<myapplication>/并从应用程序文档中引用。目的基本上是在运行时停止守护进程,卸载和删除相应的 plist 以及删除任何应用程序文件。这听起来合理还是有更好的方法来实现这一点?

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. Any recommendations or pointers to best-practice information?

此外,我想知道使用删除包的痕迹是否是一种好习惯pkgutil --forget- 如果我不这样做,下次安装包时它会显示为已升级而不是已安装。任何建议或指向最佳实践信息的指针?

Is there no standard way of doing this on OS X?

在 OS X 上没有标准的方法吗?

采纳答案by Rob Napier

There is no standard way of doing this on OS X. Yes, shocking, I know. Apple consistently warns everyone away from package installers (among other things by providing insufficient documentation for them). They then exclusively use package installers for their own standalone apps.... go figure.

在 OS X 上没有这样做的标准方法。是的,令人震惊,我知道。Apple 一直警告所有人远离软件包安装程序(除其他外,为他们提供的文档不足)。然后,他们专门为自己的独立应用程序使用软件包安装程序......去看看。

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,但如果可以,请避免这样做。

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 movedfor a year or so now, while they "update" it.

顺便说一句,如果你去寻找软件交付指南,它已经被移动了一年左右,而他们“更新”了它。

回答by user1259710

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 脚本要好一点,因为它确保永远不会删除任何其他已安装软件包使用的任何文件

回答by Steg

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. The uninstall script can be included with the .pkg in the .dmg.

我有一个类似的应用程序并遇到了同样的问题。我采用的方法是我见过其他应用程序使用的方法。与其简单地分发 .pkg 安装程序,不如将其包装在 .dmg 文件中。卸载脚本可以包含在 .dmg 中的 .pkg 中。

The uninstall script is then renamed to "uninstall.tool". The .tool extension allows users to run the script by double clicking, rather than having to run it from the command line.

然后卸载脚本被重命名为“uninstall.tool”。.tool 扩展允许用户通过双击运行脚本,而不必从命令行运行它。

回答by petert

The way I solved this was to use Automator, create an applicationdocument and then add dialog and script actions. Finally save your Automator application document and you end up with a simple GUI application to run the uninstall.

我解决这个问题的方法是使用Automator,创建一个应用程序文档,然后添加对话框和脚本操作。最后保存您的 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

回答by buildmaestro

Slightly unconventional, but aren't these all. I have Homebrew and cask installed. I was able to uninstall a .pkg with the following:

有点非常规,但不只是这些。我安装了 Homebrew 和木桶。我能够使用以下内容卸载 .pkg:

 brew cask uninstall --force <pkg_name>

ex. brew cask uninstall --force dockertools

前任。酿造桶卸载 --force dockertools