V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
laputaprince
V2EX  ›  macOS

讨论下 osx 下脚本化管理软件的思路

  •  
  •   laputaprince · 2016-05-05 08:22:17 +08:00 · 2410 次点击
    这是一个创建于 2912 天前的主题,其中的信息可能已经有所发展或是发生改变。
    从 linux 转过来,发现 osx 下软件的安装源实在有点多,粗略分成以下几种。

    1. 从 brew install , 大多是命令行
    2. brew cask install ,一般是比较 popular 的 app
    3. 只能从 Appstore 安装的, 比如 Onenote
    4. 只能下载安装的,比如 adobe 系列

    对于 2. brew cask install, 一直以来的疑问是
    1. 安装在 /Applications ,跟默认目录 /opt/homebrew-cask 有什么 pros & cons?
    2. 安装在 /opt/homebrew-cask 会和 app 自带的升级程序有冲突么?

    3 的话貌似可以用 mas ,不知体验如何。 4 好像比较无解。

    抛砖引玉,谢谢。
    17 条回复    2016-05-24 02:51:32 +08:00
    xiamx
        1
    xiamx  
       2016-05-05 08:47:51 +08:00
    Try GitHub Boxen

    1. /opt/homebrew-cask: managed by brew-cask. /Applications: unmanaged
    2. Most cases not, depends on the app
    xream
        2
    xream  
       2016-05-05 09:13:16 +08:00
    我还是觉得 cask 很蛋疼 然后就改了 HOMEBREW_CASK_OPTS '--appdir=/Applications --caskroom=/Applications'
    ynyounuo
        3
    ynyounuo  
       2016-05-05 09:44:59 +08:00 via iPhone
    3. 并不是
    4. 可用 Brew Cask 安装
    xucheng
        4
    xucheng  
       2016-05-05 19:14:06 +08:00
    abao00001
        5
    abao00001  
       2016-05-06 07:02:14 +08:00
    其实没什么区别,现在看到我使用的 app 里面只有 1password 和 chrome 有影响,因为我的 1password 是 mas 买的,由于沙盒机制 brew cask 安装的 chrome 不能调用 1password 。但是可以 brew cask 安装 1password ,授权会自动转移。对于以前安装在 application 里的 app ,可以直接拖入 trash ,然后用 brew cask 安装,设置不会受影响,这说明 brew cask 其实只是改变了安装方式, app 运行和建立相关文档同在 application 里一样,甚至卸载既可以使用 brew cask uninstall ,也可以用辅助的 appcleaner 一类 app 卸载。最后说更新,很多人抱怨不能更新,但是后来在网上看到有人写了个码,解决的更新的问题:

    casks=( $(brew cask list) )

    if [[ "$1" == "upgrade" ]]; then
    for cask in ${casks[@]}; do
    current="$(brew cask info $cask | sed -n '1p' | sed -n 's/^.*: \(.*\)$/\1/p')"
    installed=( $(ls /opt/homebrew-cask/Caskroom/$cask))
    if (! [[ " ${installed[@]} " == *" $current "* ]]); then
    echo "Upgrading $cask to v$current."
    (set -x; brew cask install $cask --force;)
    else
    echo "$cask v$current is up-to-date, skipping."
    fi
    done
    else
    echo "Inspecting ${#casks[@]} casks. Use 'brew-cask.sh upgrade' to perform any updates."
    for (( i = i ; i < ${#casks[@]} ; i++ )); do
    current="$(brew cask info ${casks[$i]} | sed -n '1p' | sed -n 's/^.*: \(.*\)$/\1/p')"
    installed=( $(ls /opt/homebrew-cask/Caskroom/${casks[$i]}))
    if (! [[ " ${installed[@]} " == *" $current "* ]]); then
    casks[$i]="${casks[$i]}$(tput sgr0)$(tput setaf 2) ✔$(tput sgr0)"
    fi
    done
    echo " ${casks[@]/%/$'\n'}" | column
    fi

    我现在还不清楚 brew cask 如何识别对系统不兼容的 app ,这个命令会不会更新至不兼容版本。我准备出现有不兼容的版本时再移回 application ,反正 app 相关的文档都是一致的。

    最后要说明的是我只有 mas 找不到的 app 才用 brew cask ,因为我懒及对未经过审核 app 的不信任。
    abao00001
        6
    abao00001  
       2016-05-06 07:06:53 +08:00
    brew cask 安装的 app 通过 app 自动升级又安装回 application 里面了。旧版本可以手动拖到 trash 。所以说 brew cask 只是简化了安装过程,其他什么也没有做。甚至只是运行 brew cask uninstall 同把 app 直接拖进 trash 一样,相关配置文档并没有删除。所以我建议还是使用辅助 app 删除。简单说就是以前怎么用这个还是怎么用,只是安装和更新可以偷一下懒。
    hackpro
        7
    hackpro  
       2016-05-06 16:23:44 +08:00
    @abao00001

    对 我也一直有这个疑惑
    用 brew cask 安装的应用 再用 update && upgrade 去升级的时候重来没有提示过升级
    只有每次打开应用手动点击更新检查的时候才会弹出升级提示
    abao00001
        8
    abao00001  
       2016-05-06 19:59:09 +08:00 via iPad
    @hackpro brew cask 的作者本意只是简化安装, app 内有自动升级,升级后 brew cask 安装的旧版本直接删掉就好了。
    hackpro
        9
    hackpro  
       2016-05-06 20:16:37 +08:00
    @abao00001
    原本选择 brew cask 安装是想可以批量更新的 看来是不行了
    不知道有什么办法可以实现不?
    abao00001
        10
    abao00001  
       2016-05-06 22:14:58 +08:00
    @hackpro 上面不是贴出来了吗。那个码简单说是:检查有没有可更新版本,没有可更新版本的 app 跳过,有可更新的安装更新,然后清除旧版本清除缓存。我觉得这个是我目前在网上看到过的写的比较好的,所以我一直用的这个。我发现国内 brew cask 使用率不高是因为网络问题,下载慢的不行,连这些 app 的网站都是被屏蔽的。
    hackpro
        11
    hackpro  
       2016-05-06 22:48:55 +08:00
    @abao00001 感谢,刚刚没注意到

    运行之后总是出现 command not found 提示,不止可否帮忙看下

    ```
    nspecting 47 casks. Use 'brew-cask.sh upgrade' to perform any updates.
    ./update_brew_cask: line 19: [[ 6.1 ==: command not found
    ./update_brew_cask: line 19: [[ 10.05 ==: command not found
    ./update_brew_cask: line 19: [[ 1.1 ==: command not found
    ./update_brew_cask: line 19: [[ 5.0.2 ==: command not found
    ./update_brew_cask: line 19: [[ 2.4.0 ==: command not found
    ./update_brew_cask: line 19: [[ 2.8.3_435 ==: command not found
    ./update_brew_cask: line 19: [[ 2.4 ==: command not found
    ./update_brew_cask: line 19: [[ 2.0.7 ==: command not found
    ./update_brew_cask: line 19: [[ 1.62 ==: command not found
    ./update_brew_cask: line 19: [[ latest ==: command not found
    ./update_brew_cask: line 19: [[ 3.11.4 ==: command not found
    ./update_brew_cask: line 19: [[ 1.2.3 ==: command not found
    ./update_brew_cask: line 19: [[ 2016.1 ==: command not found
    ./update_brew_cask: line 19: [[ 2.1.1 ==: command not found
    ./update_brew_cask: line 19: [[ 3.2.3 ==: command not found
    ./update_brew_cask: line 19: [[ 2.8.9 ==: command not found
    ./update_brew_cask: line 19: [[ 1.5.2.4 ==: command not found
    ./update_brew_cask: line 19: [[ latest ==: command not found
    ./update_brew_cask: line 19: [[ 1.6.0 ==: command not found
    ./update_brew_cask: line 19: [[ latest ==: command not found
    ./update_brew_cask: line 19: [[ 36.6 ==: command not found
    ./update_brew_cask: line 19: [[ 4.2.13332 ==: command not found
    ./update_brew_cask: line 19: [[ 2.3 ==: command not found
    ./update_brew_cask: line 19: [[ latest ==: command not found
    ./update_brew_cask: line 19: [[ 5.11 ==: command not found
    ./update_brew_cask: line 19: [[ 2.1.4 ==: command not found
    ./update_brew_cask: line 19: [[ 1.0.4 ==: command not found
    ./update_brew_cask: line 19: [[ 3.6.3 ==: command not found
    ./update_brew_cask: line 19: [[ latest ==: command not found
    ./update_brew_cask: line 19: [[ 2.4.623 ==: command not found
    ./update_brew_cask: line 19: [[ 2.5 ==: command not found
    ./update_brew_cask: line 19: [[ 3.4.3,458 ==: command not found
    ./update_brew_cask: line 19: [[ latest ==: command not found
    ./update_brew_cask: line 19: [[ 2016.1 ==: command not found
    ./update_brew_cask: line 19: [[ latest ==: command not found
    ./update_brew_cask: line 19: [[ 2.7 ==: command not found
    ./update_brew_cask: line 19: [[ latest ==: command not found
    ./update_brew_cask: line 19: [[ 1.7.26 ==: command not found
    ./update_brew_cask: line 19: [[ 514.0-1456193896 ==: command not found
    ./update_brew_cask: line 19: [[ 2.0-beta.9 ==: command not found
    ./update_brew_cask: line 19: [[ 2.3.4-305-ab500cf4 ==: command not found
    ./update_brew_cask: line 19: [[ latest ==: command not found
    ./update_brew_cask: line 19: [[ 5.0.16-105871 ==: command not found
    ./update_brew_cask: line 19: [[ 3.5.1 ==: command not found
    ./update_brew_cask: line 19: [[ latest ==: command not found
    ./update_brew_cask: line 19: [[ 2015.12.14 ==: command not found
    ./update_brew_cask: line 19: [[ 2.7.8 ==: command not found
    abao00001
        12
    abao00001  
       2016-05-07 00:29:33 +08:00   ❤️ 1
    @hackpro 哦对了。~/bin 缺少 brew-cask.sh upgrade...装太久我忘记了, sorry 。。。
    $ curl -L https://raw.githubusercontent.com/eduncan911/dotfiles/master/bin/brew-cask.sh --create-dirs -o ~/bin/brew-cask.sh
    $ chmod 755 ~/bin/brew-cask.sh
    你再试试。
    abao00001
        13
    abao00001  
       2016-05-07 00:38:42 +08:00
    @hackpro 是在~/bin 里添加 brew-cask.sh 。 可以以这两种方式使用:
    $ brew-cask.sh
    $ brew-cask.sh upgrade

    你先添加,再运行上面的 code ,调动 bin 里的 brew-cask.sh 应该就没有问题了
    hackpro
        14
    hackpro  
       2016-05-07 11:31:53 +08:00
    @abao00001

    感谢,已经完美解决,但是有个问题:这个脚本其实就是上面您贴的那段代码啊
    为何完整粘贴、未做任何修改放在我创建的脚本中会出现上面 log 提示的问题(已添加脚本执行权限)
    hackpro
        15
    hackpro  
       2016-05-10 10:41:04 +08:00
    @abao00001

    这个脚本目前发现两点问题
    1 、应用内已经手动更新过 脚本检测时还是会重新更新
    2 、出现 sha256 校验失败,似乎不会重新下载?
    abao00001
        16
    abao00001  
       2016-05-17 23:33:41 +08:00
    @hackpro 我已经移回 application 了。我发现 brew cask 更新版本落后于应用内更新。而且这个 script 是把可更新版本下载,包括系统不兼容版本。我还是感觉 brew cask 只适合快速安装。
    netabare
        17
    netabare  
       2016-05-24 02:51:32 +08:00 via iPhone   ❤️ 1
    跑个题, brew cask 几乎都没怎么用……想安装几个常见的 GUI 软件都搜不到…
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   5289 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 28ms · UTC 08:08 · PVG 16:08 · LAX 01:08 · JFK 04:08
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.