windows: 支持磁力链接下载 iso

fixes #268
This commit is contained in:
bin456789
2025-02-21 00:30:33 +08:00
parent 8e8bf610dc
commit 6263f994af
2 changed files with 173 additions and 65 deletions

View File

@ -1358,50 +1358,55 @@ Continue?
# 注意 windows server 2008 r2 serverdatacenter 不用改
image_name=${image_name/windows server 2008 server/windows longhorn server}
iso_filetype='iso raw'
iso_tested=false
if [[ "$iso" = magnet:* ]]; then
: # 不测试磁力链接
else
iso_filetype='iso raw'
iso_tested=false
# 获取 massgrave.dev 直链
if grep -Eiq '\.massgrave\.dev/.*\.(iso|img)' <<<"$iso"; then
# 如果已经是 iso 直链则跳过下面的 iso 测试
if test_url_grace "$iso" "$iso_filetype"; then
iso_tested=true
# 获取 massgrave.dev 直链
if grep -Eiq '\.massgrave\.dev/.*\.(iso|img)' <<<"$iso"; then
# 如果已经是 iso 直链则跳过下面的 iso 测试
if test_url_grace "$iso" "$iso_filetype"; then
iso_tested=true
else
msg="Could not find direct link for $iso"
if ! iso=$(grep -oE 'https?.*\.iso[^"]*' $tmp/img-test | sed 's/&amp;/\&/g' | grep .); then
error_and_exit "$msg"
fi
fi
fi
# 测试是否是 iso
if ! $iso_tested; then
test_url "$iso" "$iso_filetype"
fi
# 判断 iso 架构是否兼容
# https://gitlab.com/libosinfo/osinfo-db/-/tree/main/data/os/microsoft.com?ref_type=heads
# uupdump linux 下合成的标签是 ARM64windows下合成的标签是 A64
if file -b "$tmp/img-test" | grep -Eq '_(A64|ARM64)'; then
iso_arch=arm64
else
msg="Could not find direct link for $iso"
if ! iso=$(grep -oE 'https?.*\.iso[^"]*' $tmp/img-test | sed 's/&amp;/\&/g' | grep .); then
error_and_exit "$msg"
iso_arch=x86_or_x64
fi
if ! {
{ [ "$basearch" = x86_64 ] && [ "$iso_arch" = x86_or_x64 ]; } ||
{ [ "$basearch" = aarch64 ] && [ "$iso_arch" = arm64 ]; }
}; then
warn "
The current machine is $basearch, but it seems the ISO is for $iso_arch. Continue?
当前机器是 $basearch,但 ISO 似乎是 $iso_arch。继续安装?"
read -r -p '[y/N]: '
if ! [[ "$REPLY" = [Yy] ]]; then
exit
fi
fi
fi
# 测试是否是 iso
if ! $iso_tested; then
test_url "$iso" "$iso_filetype"
fi
[ -n "$boot_wim" ] && test_url "$boot_wim" 'wim'
# 判断 iso 架构是否兼容
# https://gitlab.com/libosinfo/osinfo-db/-/tree/main/data/os/microsoft.com?ref_type=heads
if file -b "$tmp/img-test" | grep -q '_A64'; then
iso_arch=arm64
else
iso_arch=x86_or_x64
fi
if ! {
{ [ "$basearch" = x86_64 ] && [ "$iso_arch" = x86_or_x64 ]; } ||
{ [ "$basearch" = aarch64 ] && [ "$iso_arch" = arm64 ]; }
}; then
warn "
The current machine is $basearch, but it seems the ISO is for $iso_arch. Continue?
当前机器是 $basearch,但 ISO 似乎是 $iso_arch。继续安装?"
read -r -p '[y/N]: '
if ! [[ "$REPLY" = [Yy] ]]; then
exit
fi
fi
eval "${step}_iso='$iso'"
eval "${step}_boot_wim='$boot_wim'"
eval "${step}_image_name='$image_name'"