Mac 安装程序包 - 如何以 root 或管理员身份运行脚本? (飞行后)
我创建了 Mac 软件包来安装我的一些东西。我有 postflight 脚本,应该将一些数据复制到 /Library/Application Support/Apple/Mail/Stationery/Apple/Contents/Resources/Stationery/Contents/Resources/ - 出于此处提到的原因: 如何在linux? (BOM文件问题)它需要是postflight脚本。
然而它不起作用(它只是下载一个 zip 文件,解压它并 cp 到提到的位置)。所以我通过添加 2> 检查了错误到 cp ,发生了什么:
cp: /Library/Application Support/Apple/Mail/Stationery/Apple/Contents/Resources/Stationery/Contents/Resources/: Permission returned
我已经仔细检查了我的 Info.plist,看起来设置正确已保留:
<key>IFPkgFlagAuthorizationAction</key>
<string>RootAuthorization</string>
但脚本仍然没有权限。我尝试过“whoami”,它返回当前登录的用户。更奇怪的是,安装程序实际上要求管理员身份验证。你们有什么想法我应该怎么做才能让这个脚本以 root/admin/谁拥有更大的权限运行?
I have created the Mac Package in order to install some of my stuff. I have the postflight script that is supposed to copy over some data to /Library/Application Support/Apple/Mail/Stationery/Apple/Contents/Resources/Stationery/Contents/Resources/ - and for reasons mentioned in here: How can I build a Mac package on linux? (BOM file problem) it needs to be postflight script.
However it did not work (it was just downloading a zip file, unpacking it and cp to mentioned location). So I've checked the errors by adding 2> to cp and here's what happened:
cp: /Library/Application Support/Apple/Mail/Stationery/Apple/Contents/Resources/Stationery/Contents/Resources/: Permission denied
I've double check my Info.plist and looks like proper setting is preserved:
<key>IFPkgFlagAuthorizationAction</key>
<string>RootAuthorization</string>
But the script still don't have permissions. I've tried the "whoami" and it returned currently logged in user. What's more curious, the installer ia actually asking for admin authentication. You guys have any ideas what should I do to have this script running as root/admin/whoever with greater permissions?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
安装程序发出管理员身份验证警报的事实意味着安装程序已经通过身份验证(可能是将文件安装到仅限管理员/root 的位置)。
如果我没记错的话,在我自己的 Postflight 脚本中,我在脚本中添加了对 sudo 的调用来执行管理员/根权限的操作。尝试一下这种方法,看看是否有效。我不知道这是否是“最佳实践”方法(或者也许是,因为安装程序可以签名)。
The fact that the installer is bringing up the admin authentication alert means that the installer is already authenticated (presumably to install files into admin/root-only places).
If I remember correctly, in my own Postflight scripts, I added calls to
sudo
within the script to do admin/root privileged things. Try that approach and see if it works. I don't know if this is the "best practice" approach though (or maybe it is, since installers can be signed).我认为在 Lion 中这是不可能的。Lion 的安装程序从当前用户启动脚本。
I think it's impossible in Lion.Installer of Lion launches scripts from current user.