简体   繁体   English

在Mac上提供有关安装后脚本的帮助

[英]assistance with postinstall script on Mac

New at this. 这是新的。 I need to use a postinstall script to move a file and a folder to the user's Application Support folder on a Mac. 我需要使用安装后脚本将文件和文件夹移动到Mac上用户的Application Support文件夹中。 For the file I only want to move it if the file doesn't already exist. 对于文件,我只想在文件不存在的情况下移动它。 I do not want to overwrite it if if does exist. 如果存在,我不想覆盖它。 Here is my script. 这是我的剧本。 It runs but nothing gets copied. 它运行,但没有任何复制。 I'm using the Packages app, btw, and this script is loaded into the postinstall script tab. 我正在使用Packages应用程序,顺便说一句,此脚本已加载到安装后脚本选项卡中。

#!/bin/sh
if ! "/Library/Application Support/MyApp/MyApp user dict"; then 
mv "$1/Contents/Resources/MyApp user dict" "/Library/Application Support/MyApp/.";
fi

mv "$1/Contents/Resources/Spellcheck Dictionary" "/Library/Application Support/MyApp/.";
exit 0

User-specific tasks generally do not belong in installer scripts -- remember that there may be multiple users on a machine, and that some of them may not be accessible when your installer is running. 特定于用户的任务通常不属于安装程序脚本-请记住,一台计算机上可能有多个用户,并且在安装程序运行时可能无法访问其中的某些用户。 (For example, users may have encrypted home directories, or may not exist until after your installer is run.) If your application needs to copy files to the user's home directory, it should probably do this when it is first launched. (例如,用户可能具有加密的主目录,或者可能直到运行安装程序后才存在。)如果您的应用程序需要将文件复制到用户的主目录,则它应该在首次启动时执行此操作。

Nevertheless, I see several specific issues with this script: 不过,我看到此脚本有几个特定的​​问题:

  1. Your script refers to $1 in several places. 您的脚本在多个地方引用$1 Are you sure that your script has an argument passed to it on the command line? 您确定您的脚本在命令行上传递了一个参数吗?

  2. The correct syntax to test if a file does not exist is: 测试文件是否不存在的正确语法是:

     if [ ! -f "/path/to/file" ] ; then … 

    Your script is missing the square brackets and -f condition. 您的脚本缺少方括号和-f条件。 (For details, see man test .) (有关详细信息,请参见man test 。)

  3. Assuming that $1 is supposed to be the path to the current user's home directory, you have the arguments to mv backwards. 假定$1应该是当前用户主目录的路径,则您具有向后mv的参数。 The destination comes last, not first. 目的地排在最后,而不是第一。 (The syntax is essentially mv from to .) (语法本质上是mv from to 。)

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

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