1

我有一个应用程序包(如果相关,则使用 Unity 3d 构建),我可以使用 productbuild 创建一个 .pkg 安装程序并在 App Store 上分发而不会出现问题。但是,该应用程序会下载并缓存大量媒体,并且有一些可选配置文件需要在机器上的所有用户之间共享。根据Apple 的文档,配置文件可能应该放在 /Library/Application Support 目录中,而媒体应该放在 /Library/Caches 中。我已经制作了该应用程序的修改版本,它使用这些目录而不是沙盒应用程序可以访问的目录,但它没有 /Library 目录的权限,除非我以 root 身份运行该应用程序,这不是现实的选择。

我已经在谷歌搜索了几个小时,但我似乎找不到任何关于创建这样一个安装程序的信息。我确实读过这个答案,它有一个安装程序的屏幕截图,可以选择为所有用户安装,但要么我错过了一些启用该选项的选项,要么该屏幕截图刚刚过时,因为我似乎无法创建 .pkg这给了我这个选择。

所以我想我的问题归结为:我如何打包我的应用程序以便它可以为所有用户安装,并有权读取和写入 /Library/Application Support/{app name},或者是否有另一种首选方式在同一台机器上的多个用户之间共享配置文件和/或媒体?

4

1 回答 1

2

对于其他有类似问题的人,正确的答案是您不能使用 productbuild 执行此操作,但您可以使用 pkgbuild。

我的应用商店的 productbuild 构建步骤如下所示:

productbuild --component "{mystoreapp.app/}" /Applications --sign "{signing identity}" "{mystorepkg.pkg}"

pkgbuild 对应的打包命令如下所示:

pkgbuild --component "{mymodifiedapp.app/}" --sign "{signing identity}" --ownership preserve --scripts "{path/to/my/scripts}" --identifier {com.yourcompany.yourapp} --version "{versionNumber}" --install-location /Applications "{mymodifiedpkg.pkg}"

请注意,此处的签名是可选的,因为它将在商店外分发。其中 {path/to/my/scripts} 有一个名为的文件postinstall,如下所示:

#this function creates a directory if it doesn't exist
create_directory() {
    if [[ ! -d "$1" ]]
    then
            if [[ ! -L "$1" ]]
            then
                    echo "directory $1 doesn't exist. Creating now"
                    mkdir "$1"

                    echo "directory $1 created"
            else
                    echo "directory $1 exists"
            fi
    fi
}

#this function gives all users read and write (and execute) access to the directory
fix_dir_permissions() {
    chmod 777 "$1"
}

baseDirName="/Library/Application Support/{your app name bere}"

subDirs[0]="$baseDirName/{sub dir here}"

#create base directory
create_directory "$baseDirName"

#create all subdirectories and give permissions
for subDir in "${subDirs[@]}"
do
    create_directory "$subDir"
    fix_dir_permissions "$subDir"
done

exit 0

此脚本将在安装结束后运行,并将创建您的应用程序支持目录以及您需要的任何子目录并更改它们的权限,以便所有用户都可以访问它们。

于 2015-11-09T18:54:47.540 回答