macos 使用 PackageMaker 在安装时运行脚本

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/640701/
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 06:04:00  来源:igfitidea点击:

Using PackageMaker to run a script on install

macosinstallerpackagemaker

提问by Abdullah Jibaly

I have an app I need to create an installer for, and all the installer needs to do (besides copying the app) is run a script (or executable) that is not part of the app itself. Any help on how I can do this? I see in the Requirementstab there is a Results of Scriptaction, and there is also the Preinstall Actionsin the Actionstab which has an Open Fileaction. Will either of these do the job or should I be looking elsewhere?

我有一个需要为其创建安装程序的应用程序,并且安装程序需要做的所有事情(除了复制应用程序)都是运行一个不属于应用程序本身的脚本(或可执行文件)。关于我如何做到这一点的任何帮助?我在“需求”选项卡中看到“脚本结果”操作,“操作”选项卡中还有“预安装操作”,其中包含“打开文件”操作。这些中的任何一个都可以完成工作还是我应该寻找其他地方?

回答by epatel

Hereis a good How-to

是一个很好的操作方法

There are 7 types of scripts than can be launched during the Installation Process:

InstallationCheck:This script is launched at the beginning of the installation process (even before the Authentication step). It can be used to check that the Package can be installed on this computer.

VolumeCheck:This script is launched in the "Select Destination" step. It is used to determine on which volume the Package can be installed.

preflight:This script is launched just after the user clicked on the "Install" button.

preinstall / preupgrade:This script is launched after the preflight script if there's one (in the case of a single package installation); otherwise just after the user clicked on the "Install" button.

As you see, there's 2 types of scripts here. The preinstall one is launched when the Package has never been installed (from an Installer.app point of view), the preupgrade one is launched when the Package has already been installed. To determine whether a Package has already been installed or not, Installer.app is having a look at the content of the following directory: /Library/Receipts. If there's a file named PackageName.pkg within it, then the Package has already been installed, otherwise it's the first install.

postinstall / postupgrade:This script is launched after the files in the package have been installed. See (preinstall / preupgrade) to see which one is launched.

postflight:This script is launched after the postinstall / postupgrade script or when the package has been installed.

有 7 种类型的脚本可以在安装过程中启动:

InstallationCheck:此脚本在安装过程开始时启动(甚至在身份验证步骤之前)。它可用于检查该包是否可以安装在这台计算机上。

VolumeCheck:此脚本在“选择目的地”步骤中启动。它用于确定包可以安装在哪个卷上。

预检:此脚本在用户单击“安装”按钮后立即启动。

preinstall / preupgrade:如果有预检脚本(如果是单个软件包安装),则在预检脚本之后启动该脚本;否则就在用户单击“安装”按钮之后。

如您所见,这里有两种类型的脚本。当软件包从未安装过(从 Installer.app 的角度来看)时,会启动预安装,当软件包已安装时会启动预升级。为了确定包是否已经安装,Installer.app 正在查看以下目录的内容:/Library/Receipts。如果里面有一个名为 PackageName.pkg 的文件,那么这个 Package 已经被安装,否则就是第一次安装。

postinstall / postupgrade:此脚本在安装包中的文件后启动。请参阅 (preinstall / preupgrade) 以查看启动了哪个。

postflight:此脚本在 postinstall / postupgrade 脚本之后或安装包后启动。

回答by joon

I just managed to include a Shell script to my package that I made with PackageMaker. I needed to add my app to the login items after installation, so I made a script called postflight.shand put it into a folder. (it seems it works with any location)

我只是设法在我使用 PackageMaker 制作的包中包含了一个 Shell 脚本。我需要在安装后将我的应用程序添加到登录项中,所以我制作了一个名为的脚本postflight.sh并将其放入一个文件夹中。(似乎它适用于任何位置)

And then in my package, I have Applications. In Contents, Package:Applications, in the Scripts tab, I choose the postflight.shin Postflight section. That's it.

然后在我的包中,我有应用程序。在 Contents、Package:Applications 和 Scripts 选项卡中,我选择了postflight.shPostflight 部分。而已。

my postflight.shstarts with

我的postflight.sh开始

#!/bin/bash

and then it has some script to put the app into the login items. When I didn't have that, I could make the package, but the installation failed. Hope this is helpful.

然后它有一些脚本可以将应用程序放入登录项中。当我没有那个时,我可以制作软件包,但安装失败。希望这是有帮助的。

回答by Bob Denny

This PackageMaker How-Toarticle is out of date, but it has some very useful info on scripts about half-way down. Look for the table showing the command line variables as seen from shell and perl, plus some useful exit status values.

这篇PackageMaker How-To文章已经过时,但它有一些关于脚本的非常有用的信息。查找显示从 shell 和 perl 看到的命令行变量的表,以及一些有用的退出状态值。