Scoop 踩坑记录

安装时无法指定软件版本

网上部分教程表示 scoop 安装软件时可以指定版本号:

POWERSHELLscoop install [email protected]

但实际上这个功能现在已无法正常使用,目前的官方文档里也没有注明这样的用法。此外,有些软件官方网站并不会保留历史版本的下载链接,这也是 scoop 不能支持安装软件指定版本的原因之一。

如果要安装软件的历史版本,只能通过自建软件仓库的方式来实现。

不支持通过 manifest 文件安装

通过命令 scoop help install 查看安装参数可以得知,scoop 应该是支持从 URL 或本地 manifest 文件来安装软件的。

Usage: scoop install <app> [options]

e.g. The usual way to install an app (uses your local 'buckets'):
     scoop install git

To install an app from a manifest at a URL:
     scoop install https://raw.githubusercontent.com/ScoopInstaller/Main/master/bucket/runat.json

To install an app from a manifest on your computer
     scoop install \path\to\app.json

Options:
  -g, --global              Install the app globally
  -i, --independent         Don't install dependencies automatically
  -k, --no-cache            Don't use the download cache
  -u, --no-update-scoop     Don't update Scoop before installing if it's outdated
  -s, --skip                Skip hash validation (use with caution!)
  -a, --arch <32bit|64bit>  Use the specified architecture, if the app supports it

但是实测并不成功,会得到一个 Couldn't find manifest for 'APP_NAME'. 错误。看起来,安装的软件名称必须在现有的仓库中存在才行。这样的话,通过 URL 或 json 文件来安装软件的功能就一点意义都没有了。

安装时发生 Hash check failed 错误

有时,在安装软件时会遇到 Hash check failed 错误。比如目前用 scoop install nirsoft\filetypesman 命令安装 FileTypesMan 时报错:

Installing 'filetypesman' (1.95) [64bit]
Checking hash of filetypesman-x64.zip ... ERROR Hash check failed!
App:         nirsoft/filetypesman
URL:         https://www.nirsoft.net/utils/filetypesman-x64.zip
First bytes: 50 4B 03 04 14 00 02 00
Expected:    d032ee7ea72b6678a65c3500f19eb3edb58574f33a2be9ff0ac6d9ef9ea29ada
Actual:      5feec2a7c0ca1d46ff8bd27a0eadd068f3d8c6dc3fee6f7354973319aeecefb3

Please try again or create a new issue by using the following link and paste your console output:
https://github.com/kodybrown/scoop-nirsoft/issues/new?title=filetypesman%401.95%3a+hash+check+failed

发生该错误的原因是,官方软件的下载地址没有版本区分,发布的历史版本和当前版本都是用同一个 URL。FileTypesMan 已经发布了 1.96 版本,而仓库中的 manifest 文件未及时更新,仍是 1.95 版本,导致下载后的安装包没有通过 Hash 验证。解决方法就是安装时使用 -s 参数跳过 Hash 验证:

POWERSHELLscoop install -s nirsoft\filetypesman

manifest 的 persist 默认为文件夹

在 manifest 文件中,可以用 persist 定义持久性数据,但是默认为文件夹。如果要指向文件,需要用 pre_install 脚本特别处理。

JSON{
    "version": "2.51.0",
    "homepage": "https://www.xnview.com/en/xnview/",
    "license": "Freeware|Proprietary",
    "url": "https://download.xnview.com/XnView-win-full.zip",
    "hash": "DF376971063951076211D00AF74E98513C6E25377C57FCA4957EE817AB809B30",
    "extract_dir": "XnView",
    "bin": "xnview.exe",
    "shortcuts": [
        [
            "xnview.exe",
            "XnView"
        ]
    ],
    "pre_install": [
        "# --- If xnview.ini exists as a folder, then remove it ---",
        "if (Test-Path \"$persist_dir\\xnview.ini\" -PathType Container) {",
        "    Remove-Item \"$persist_dir\\xnview.ini\" -Force -Recurse",
        "}",
        "if (!(Test-Path \"$persist_dir\\xnview.ini\")) {",
        "   New-Item \"$dir\\xnview.ini\" -ItemType File | Out-Null",
        "}",
        "# --- If category.db exists as a folder, then remove it ---",
        "if (Test-Path \"$persist_dir\\category.db\" -PathType Container) {",
        "    Remove-Item \"$persist_dir\\category.db\" -Force -Recurse",
        "}",
        "if (!(Test-Path \"$persist_dir\\category.db\")) {",
        "   New-Item \"$dir\\category.db\" -ItemType File | Out-Null",
        "}"
    ],
    "uninstaller": {
        "script": [
            "# Manually copy because Xnview overwrites hardlink with a regular file, which breaks persist",
            "if ((Test-Path \"$dir\\xnview.ini\") -and !(Get-Item \"$dir\\xnview.ini\").LinkType -and (Test-Path $persist_dir)) { Copy-Item \"$dir\\xnview.ini\" $persist_dir -Force }",
            "if ((Test-Path \"$dir\\category.db\") -and !(Get-Item \"$dir\\category.db\").LinkType -and (Test-Path $persist_dir)) { Copy-Item \"$dir\\category.db\" $persist_dir -Force }"
        ]
    },
    "persist": [
        "xnview.ini",
        "category.db"
    ],
    "checkver": "Download <strong>XnView ([\\d.]+)</strong> for Windows",
    "autoupdate": {
        "url": "https://download.xnview.com/XnView-win-full.zip",
        "hash": {
            "url": "https://www.xnview.com/en/xnview/",
            "find": "XnView-win-full.zip: ($sha256)"
        }
    }
}