windows: 适配 massgrave 新镜像链接

This commit is contained in:
bin456789
2026-01-07 20:30:33 +08:00
parent 6ebe902624
commit 14c314d2bc

View File

@ -1086,7 +1086,10 @@ get_windows_iso_link() {
if [ -n "$label_msdl" ]; then if [ -n "$label_msdl" ]; then
iso=$(curl -L "$page_url" | grep -ioP 'https://[^ ]+?#[0-9]+' | head -1 | grep .) iso=$(curl -L "$page_url" | grep -ioP 'https://[^ ]+?#[0-9]+' | head -1 | grep .)
else else
curl -L "$page_url" | grep -ioP 'https://[^ ]+?.(iso|img)' >$tmp/win.list curl -L "$page_url" |
tr -d '\n' | sed -e 's,<a ,\n<a ,g' -e 's,</a>,</a>\n,g' | # 使每个 <a></a> 占一行
grep -Ei '\.(iso|img)</a>$' | # 找出是 iso 或 img 的行
sed -E 's,<a href="([^"]+)".+>(.+)</a>,\2 \1,' >$tmp/win.list # 提取文件名和链接
# 如果不是 ltsc ,应该先去除 ltsc 链接,否则最终链接有 ltsc 的 # 如果不是 ltsc ,应该先去除 ltsc 链接,否则最终链接有 ltsc 的
# 例如查找 windows 10 iot enterprise会得到 # 例如查找 windows 10 iot enterprise会得到
@ -1104,10 +1107,14 @@ get_windows_iso_link() {
} }
get_shortest_line() { get_shortest_line() {
# awk '{print length($0), $0}' | sort -n | head -1 | awk '{print $2}'
awk '(NR == 1 || length($0) < length(shortest)) { shortest = $0 } END { print shortest }' awk '(NR == 1 || length($0) < length(shortest)) { shortest = $0 } END { print shortest }'
} }
get_shortest_line_by_field() {
local field=$1
awk "(NR == 1 || length(\$$field) < length(field)) { line = \$0; field = \$$field } END { print line }"
}
get_windows_iso_link_inner() { get_windows_iso_link_inner() {
regexs=() regexs=()
@ -1139,7 +1146,7 @@ get_windows_iso_link_inner() {
regex=${regex// /_} regex=${regex// /_}
echo "looking for: $regex" >&2 echo "looking for: $regex" >&2
if iso=$(grep -Ei "/$regex" "$tmp/win.list" | get_shortest_line | grep .); then if iso=$(grep -Ei "^$regex " "$tmp/win.list" | get_shortest_line_by_field 1 | awk '{print $2}' | grep .); then
return return
fi fi
done done
@ -1512,7 +1519,9 @@ Continue?
} }
setos_windows() { setos_windows() {
auto_find_iso=false
if [ -z "$iso" ]; then if [ -z "$iso" ]; then
auto_find_iso=true
# 查找时将 windows longhorn serverdatacenter 改成 windows server 2008 serverdatacenter # 查找时将 windows longhorn serverdatacenter 改成 windows server 2008 serverdatacenter
image_name=${image_name/windows longhorn server/windows server 2008 server} image_name=${image_name/windows longhorn server/windows server 2008 server}
echo "iso url is not set. Attempting to find it automatically." echo "iso url is not set. Attempting to find it automatically."
@ -1526,10 +1535,13 @@ Continue?
if [[ "$iso" = magnet:* ]]; then if [[ "$iso" = magnet:* ]]; then
: # 不测试磁力链接 : # 不测试磁力链接
else
iso_is_tested=false
if $auto_find_iso; then
if test_url_grace "$iso" iso 2>/dev/null; then
iso_is_tested=true
else else
# 需要用户输入 massgrave.dev 直链 # 需要用户输入 massgrave.dev 直链
if grep -Eiq '\.massgrave\.dev/.*\.(iso|img)$' <<<"$iso" ||
grep -Eiq '\.gravesoft\.dev/#[0-9]+$' <<<"$iso"; then
info "Set Direct link" info "Set Direct link"
# MobaXterm 不支持 # MobaXterm 不支持
# printf '\e]8;;http://example.com\e\\This is a link\e]8;;\e\\\n' # printf '\e]8;;http://example.com\e\\This is a link\e]8;;\e\\\n'
@ -1545,9 +1557,11 @@ Continue?
error_and_exit "ISO Link is empty." error_and_exit "ISO Link is empty."
fi fi
fi fi
fi
# 测试是否是 iso if ! $iso_is_tested; then
test_url "$iso" iso test_url "$iso" iso
fi
# 判断 iso 架构是否兼容 # 判断 iso 架构是否兼容
# https://gitlab.com/libosinfo/osinfo-db/-/tree/main/data/os/microsoft.com?ref_type=heads # https://gitlab.com/libosinfo/osinfo-db/-/tree/main/data/os/microsoft.com?ref_type=heads