热修复 Scoop 的 GIMP 3.0 安装脚本错误

Windows 包管理器 Scoop 上的 GIMP 3.0 已经发布一周多了,期间已经推送了三个版本。然而官方的安装脚本存在错误,导致用户无法正确安装,至今仍未解决。目前 GIMP 3.0 的安装配置主要存在两个问题:

  1. 软件安装包解压缩失败
  2. 安装脚本中的文件路径不正确

问题一只要将 Scoop 默认的 innounp 卸载并替换成 innounp-unicode 就行了:

powershellscoop uninstall innounp 
scoop install versions/innounp-unicode

问题二的错误信息如下:

Installing 'gimp' (3.0.2) [64bit] from 'extras' bucket
gimp-3.0.2-setup.exe (374.5 MB) [========================================================================] 100%
Checking hash of gimp-3.0.2-setup.exe ... ok.
Extracting gimp-3.0.2-setup.exe ... done.
Running installer script...Rename-Item:
Line |
   4 |     Rename-Item 'lib\gimp\2.0\plug-ins\twain\twain,2.exe' 'twain.exe'
     |     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
     | Cannot find path 'D:\Apps\scoop\apps\gimp\3.0.2\lib\gimp\2.0\plug-ins\twain\twain,2.exe' because it does not exist.
Remove-Item:
Line |
   5 |     Remove-Item 'lib\gimp\2.0\plug-ins\twain\twain,1.exe'
     |     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
     | Cannot find path 'D:\Apps\scoop\apps\gimp\3.0.2\lib\gimp\2.0\plug-ins\twain\twain,1.exe' because it does not exist.
Get-Content:
Line |
  14 |  $pyenv = Get-Content 'lib\gimp\2.0\environ\pygimp.env' -Raw
     |           ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
     | Cannot find path 'D:\Apps\scoop\apps\gimp\3.0.2\lib\gimp\2.0\environ\pygimp.env' because it does not exist.
Set-Content:
Line |
  15 |  … T_LAYER=HIGHDPIAWARE' | Set-Content 'lib\gimp\2.0\environ\pygimp.env'
     |                            ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
     | Could not find a part of the path 'D:\Apps\scoop\apps\gimp\3.0.2\lib\gimp\2.0\environ\pygimp.env'.
Get-Content:
Line |
  16 |  $pyint = Get-Content 'lib\gimp\2.0\interpreters\pygimp.interp' -Raw
     |           ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
     | Cannot find path 'D:\Apps\scoop\apps\gimp\3.0.2\lib\gimp\2.0\interpreters\pygimp.interp' because it does not exist.
Copy-Item:
Line |
  21 |  Copy-Item "$bucketsdir\extras\scripts\gimp\default.env" "$dir\lib\gim …
     |  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
     | Could not find a part of the path 'D:\Apps\scoop\apps\gimp\3.0.2\lib\gimp\2.0\environ\'.
done.
Linking D:\Apps\scoop\apps\gimp\current => D:\Apps\scoop\apps\gimp\3.0.2
Creating shim for 'gimp-console-2.10'.
Get-Command: D:\Apps\scoop\apps\scoop\current\lib\install.ps1:757
Line |
 757 |              $bin = (Get-Command $target).Source
     |                      ~~~~~~~~~~~~~~~~~~~
     | The term 'bin\gimp-console-2.10.exe' is not recognized as a name of a cmdlet, function, script file, or
     | executable program. Check the spelling of the name, or if a path was included, verify that the path is
     | correct and try again.
Can't shim 'bin\gimp-console-2.10.exe': File doesn't exist.

GIMP 都升级到 3.0 了,安装脚本里还在使用 2.0 的路径。找到本地的 gimp.json 文件,此处路径为 D:\Apps\scoop\buckets\extras\bucket\gimp.json,将其内容修改为:

json{
    "version": "3.0.2",
    "description": "GNU Image Manipulation Program",
    "homepage": "https://www.gimp.org",
    "license": "GPL-3.0-only",
    "url": "https://download.gimp.org/mirror/pub/gimp/v3.0/windows/gimp-3.0.2-setup.exe",
    "hash": "7a5eca6cc9cf6cf68b7e674eecf879afc13e657ef59fb7742093a05e9998ffa5",
    "innosetup": true,
    "installer": {
        "script": [
            "Push-Location \"$dir\"",
            "Get-ChildItem -Filter '*.debug' -Recurse | Remove-Item -Recurse",
            "if ($architecture -eq '64bit') {",
            "   Get-ChildItem -Filter '*,1*' -Recurse | Rename-Item -NewName { $_.name -Replace ',\\d','' }",
            "   Get-ChildItem -Filter '*,*' -Recurse | Remove-Item",
            "} else {",
            "   Get-ChildItem -Filter '*,1*' -Recurse | Remove-Item",
            "   Get-ChildItem -Filter '*,*' -Recurse | Rename-Item -NewName { $_.name -Replace ',\\d','' }",
            "}",
            "$pyenv = Get-Content 'lib\\gimp\\3.0\\environ\\pygimp.env' -Raw",
            "$pyenv + '__COMPAT_LAYER=HIGHDPIAWARE' | Set-Content 'lib\\gimp\\3.0\\environ\\pygimp.env'",
            "$pyint = Get-Content 'lib\\gimp\\3.0\\interpreters\\pygimp.interp' -Raw",
            "$pyint = $pyint -Replace '(python|python2)=(.*)', \"`$1=$dir\\bin\\pythonw.exe\"",
            "$pyint = $pyint -Replace 'py::python2', 'py::python'",
            "$pyint | Set-Content 'lib\\gimp\\3.0\\interpreters\\pygimp.interp'",
            "Pop-Location",
            "Copy-Item \"$bucketsdir\\extras\\scripts\\gimp\\default.env\" \"$dir\\lib\\gimp\\3.0\\environ\\\" | Out-Null"
        ]
    },
    "bin": [
        "bin\\gimp-console-3.0.exe",
        [
            "bin\\gimp-console-3.0.exe",
            "gimp-console"
        ],
        [
            "bin\\gimp-console-3.0.exe",
            "gimp"
        ],
        "bin\\gimptool-3.0.exe",
        [
            "bin\\gimptool-3.0.exe",
            "gimptool"
        ]
    ],
    "shortcuts": [
        [
            "bin\\gimp-3.0.exe",
            "GIMP"
        ]
    ],
    "checkver": {
        "url": "https://www.gimp.org/downloads/",
        "regex": "gimp-(?<version>[\\d.]+)-setup(?<build>-\\d)?\\.exe",
        "replace": "${version}${build}"
    },
    "autoupdate": {
        "url": "https://download.gimp.org/mirror/pub/gimp/v$majorVersion.$minorVersion/windows/gimp-$matchHead-setup$matchTail.exe",
        "hash": {
            "url": "$baseurl/SHA256SUMS"
        }
    }
}

保存后使用命令 scoop install gimp 再次安装 GIMP 成功。最后使用 git checkout -- bucket/gimp.json 恢复 gimp.json 文件。