简体   繁体   English

pkgbuild postinstall 脚本在其他人的 Mac 上导致“安装失败”

[英]pkgbuild postinstall script causes “Installation failed” on others' Macs

I have an issue in my custom installer that occurs when I append a postinstall script to the pkg.当我将安装后脚本附加到 pkg 时,我的自定义安装程序出现问题。 On my computer the installation works just fine, but on other users' systems the .app is installed but the postinstall script fails without execution.在我的电脑上,安装工作正常,但在其他用户的系统上,.app 已安装,但 postinstall 脚本在没有执行的情况下失败。

If I remove the --scripts argument on pkgbuild, the installer produces no issues.如果我删除 pkgbuild 上的--scripts参数,安装程序不会产生任何问题。 If I add it (and even if the postinstall script is empty) a "failed installation" message is shown.如果我添加它(即使postinstall脚本为空),也会显示“安装失败”消息。 No logs are produced.不生成日志。

The pkg is built using a script similar to this: pkg 是使用与此类似的脚本构建的:

pkgbuild --identifier $PKG_IDENTIFIER \
         --version $APP_VERSION \
         --root $APP_PATH \
         --scripts Scripts/ \
         --install-location /Applications/$APP_NAME.app $TMP_PKG_PATH

productbuild --sign "Developer ID Installer: $COMPANY_NAME" \
             --distribution Distribution.xml \
             --package-path $INSTALLER_BUILD_PATH $INSTALLER_PKG_PATH

On my system the app is installed into /Applications and the postinstall script runs and does it's business.在我的系统上,应用程序安装到 /Applications 中,安装后脚本运行并完成它的业务。 On other systems the postinstall doesn't even seem to be executed at all.在其他系统上,postinstall 似乎根本没有执行。

It has been tested on OSX 10.8 and 10.7 and both get the same issue.它已经在 OSX 10.8 和 10.7 上进行了测试,并且都遇到了相同的问题。 The postinstall script is tested independently on all systems (using ./postinstall in the Terminal) and works. postinstall 脚本在所有系统上都经过独立测试(在终端中使用./postinstall )并且可以正常工作。

The script looks like this:该脚本如下所示:

#!/usr/bin/env sh
set -e

# Install launch agent
LAUNCH_AGENT_SRC="/Applications/MyApp.app/Contents/Resources/launchd.plist"
LAUNCH_AGENT_DEST="$HOME/Library/LaunchAgents/com.company.myapp.agent.plist"

# Uninstall old launch agent
if [ -f "$LAUNCH_AGENT_DEST" ]; then
  launchctl unload "$LAUNCH_AGENT_DEST"
  rm -f "$LAUNCH_AGENT_DEST"
fi

cp "$LAUNCH_AGENT_SRC" "$LAUNCH_AGENT_DEST"
launchctl load "$LAUNCH_AGENT_DEST"

# Open application
open -a "MyApp"

exit 0

What could be causing this issue?什么可能导致这个问题?

It seems the cause of the issue was the if statement.似乎问题的原因是 if 语句。 And when it wasn't present the contents of the if could cause the error to fire unless the launch agent was installed already.当它不存在时,if 的内容可能会导致错误触发,除非已经安装了启动代理。

I solved it by switching the code for:我通过切换代码解决了这个问题:

#!/usr/bin/env sh
set -e

# Launch agent location
LAUNCH_AGENT_SRC="/Applications/MyApp.app/Contents/Resources/launchd.plist"
LAUNCH_AGENT_DEST="$HOME/Library/LaunchAgents/com.company.myapp.agent.plist"

# Uninstall old launch agent
launchctl unload "$LAUNCH_AGENT_DEST" || true
rm -f "$LAUNCH_AGENT_DEST" || true

# Install launch agent
cp "$LAUNCH_AGENT_SRC" "$LAUNCH_AGENT_DEST" || true
launchctl load "$LAUNCH_AGENT_DEST" || true

# Open application
open -a "MyApp"

exit 0

The error I made before when testing an empty script was not having exit 0 at the end.我之前在测试空脚本时犯的错误最后没有exit 0 So now when I got that working I could activate different rows of the code and see what was causing an error.所以现在当我开始工作时,我可以激活代码的不同行,看看是什么导致了错误。

您可能已经找到了答案,如果不查看脚本就很难说,但是您能确保在安装后脚本的末尾有“exit 0”吗?

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

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