使用 scoop 安装管理 windows 软件(4):安装包解压密码

ref: https://github.com/ScoopInstaller/Scoop/issues/4390

0. 问题: scoop 本身不支持安装包有解压密码的自动解压。

scoop 本身不支持安装包有解压密码的自动解压。因此在安装 MAS 时会卡在解压处,无法继续安装。

1. 7z 命令手册

7z 命令是支持的: 7z x FILENAME.7z -pPWD -oOUTDIR

2. 查 Scoop 源码的解压函数

找到 Scoop 源码里的 “~\scoop\apps\scoop\current\lib\decompress.ps1” 文件。
文件封装了 Expand-7zipArchive 函数命令, 但参数没有能将密码传入的方法。

3. 试 Scoop 的 pre_install

Scoop Wiki 里提到了 pre_install 等说法。

在 MAS.json 中加入:

1
"pre_install": "7z x $dir\\$fname -p1234 $('-o' + $dir)"

尝试了很多次还是不起作用,Scoop的策略是遇到压缩包先执行解压、再做后续的事情。所以这一句不会被执行,安装程序依旧卡在解压处,无法继续安装。

github 也有类似问题:
ref: https://github.com/ScoopInstaller/Scoop/issues/4390

JourneyOver commented on Sep 27, 2022

Does this no longer work? I've tried multiple different things of trying to set it to install / pre_install and neither seem to actually work, looking at task manager it seems that it's not actually calling 7-zip at all with the password and instead just defaulting to trying to extract the file without the password at all.
does extract_dir or extract_to support password any? as looking at https://scoop-docs.vercel.app/docs/concepts/App-Manifests.html#a-simple-example doesn't seem to show an example with > password protect files at all.

niheaven commented on Sep 27, 2022

Use Expand-7zipArchive and pass arguments, sorry the password has not been supported in manifest.

JourneyOver commented on Sep 28, 2022

So I actually figured out the situation, whenever the url ends in either .zip/.rar or any other rared typed of extension, it'll always throw the default extraction method, no matter the pre_install or installer stuff.. solution is just to append random bit at end that isn’t .zip/.rar or other rar type of extensions and then it’ll extract the file correctly with the installer or pre_install bits.`

niheaven commented on Sep 28, 2022

So I actually figured out the situation, whenever the url ends in either .zip/.rar or any other rared typed of extension, it'll always throw the default extraction method, no matter the pre_install or installer stuff.. solution is just to append random bit at end that isn't .zip/.rar or other rar type of extensions and then it'll extract the file correctly with the installer or pre_install bits.

4. 解决办法

下载时将文件后缀改为不是压缩包的格式,将 url 后面加上 #dl.7z_ , 下载完成后缀名就变成了 .7z_

Scoop 的安装程序就不会自动执行默认的解压程序 Expand-7zipArchive ; 这样 pre_install 命令就可以正常工作。

修改后的安装配置文件:

mas_x.json

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
{
"version": "1.7",
"description": "Microsoft-Activation-Scripts https://massgrave.dev",
"homepage": "https://github.com/massgravel/Microsoft-Activation-Scripts",
"url": "https://github.com/massgravel/Microsoft-Activation-Scripts/releases/download/1.7/MAS_1.7_Password_1234.7z#dl.7z_",
"hash": "852946f630a25b46f9fcbf34b777f57aacfe10036ba0d7e9e919385c510c212e",
"bin": "All-In-One-Version\\MAS_AIO.cmd",
"shortcuts": [
[
"All-In-One-Version\\MAS_AIO.cmd",
"MAS_AIO"
]
],
"pre_install":[
"$zip=(Get-ChildItem $dir\\MAS_*).Name",
"7z x $dir\\$zip -p1234 $('-o' + $dir) | Out-Null",
"Move-Item $dir\\MAS_$version\\* $dir"
],
"post_install": [
"Remove-Item $dir\\*dl.7z_ -Force",
"Remove-Item $dir\\MAS_$version -Force -Recurse"
],
"checkver": {
"github": "https://github.com/massgravel/Microsoft-Activation-Scripts"
},
"autoupdate": {
"url": "https://github.com/massgravel/Microsoft-Activation-Scripts/releases/download/$version/MAS_$version_Password_1234.7z"
}
}