windows: 支持自动查找 iso 链接

This commit is contained in:
bin456789 2024-04-05 22:45:59 +08:00
parent c2aaa967c1
commit 10a8699d12
No known key found for this signature in database
GPG Key ID: EE301B386DE6C11B
3 changed files with 397 additions and 34 deletions

View File

@ -122,17 +122,25 @@ bash reinstall.sh netboot.xyz
```bash
bash reinstall.sh windows \
--iso 'https://drive.massgrave.dev/en-us_windows_10_enterprise_ltsc_2021_x64_dvd_d289cf96.iso' \
--image-name 'Windows 10 Enterprise LTSC 2021' \
--iso 'https://drive.massgrave.dev/en-us_windows_10_enterprise_ltsc_2021_x64_dvd_d289cf96.iso'
```
- Now supports automatically searching for Windows (including LTSC) and Windows Server ISO links.
- Need to set the language using `--lang`, default `en-us`.
- Search Source: <https://massgrave.dev/genuine-installation-media.html>
```bash
bash reinstall.sh windows \
--image-name 'Windows 10 Enterprise LTSC 2021'
--lang zh-cn
```
![Installing Windows](https://github.com/bin456789/reinstall/assets/7548515/07c1aea2-1ce3-4967-904f-aaf9d6eec3f7)
Parameters:
Parameters Description:
`--iso` Original image link
`--image-name` Specify the image to install, case-insensitive, for example:
`--image-name` Specify the image to install, case-insensitive, Commonly used images include:
```text
Windows 7 Ultimate
@ -153,11 +161,11 @@ Use `Dism++` File menu > Open Image File, select the iso to be installed to get
- Hyper-V Server
- Azure Stack HCI
2. The script will install the following drivers as needed:
- KVM ([Virtio](https://fedorapeople.org/groups/virt/virtio-win/direct-downloads/))
- XEN ([XEN PV](https://xenproject.org/windows-pv-drivers/), [AWS PV](https://docs.aws.amazon.com/zh_cn/AWSEC2/latest/WindowsGuide/xen-drivers-overview.html))
- AWS ([ENA Network Adapter](https://docs.aws.amazon.com/zh_cn/AWSEC2/latest/WindowsGuide/enhanced-networking-ena.html), [NVMe Storage Controller](https://docs.aws.amazon.com/zh_cn/AWSEC2/latest/WindowsGuide/aws-nvme-drivers.html))
- GCP ([gVNIC Network Adapter](https://cloud.google.com/compute/docs/networking/using-gvnic), [GGA Graphics](https://cloud.google.com/compute/docs/instances/enable-instance-virtual-display))
- Azure ([MANA Network Adapter](https://learn.microsoft.com/zh-cn/azure/virtual-network/accelerated-networking-mana-windows))
- KVM ([Virtio](https://fedorapeople.org/groups/virt/virtio-win/direct-downloads/))
- XEN ([XEN PV](https://xenproject.org/windows-pv-drivers/), [AWS PV](https://docs.aws.amazon.com/zh_cn/AWSEC2/latest/WindowsGuide/xen-drivers-overview.html))
- AWS ([ENA Network Adapter](https://docs.aws.amazon.com/zh_cn/AWSEC2/latest/WindowsGuide/enhanced-networking-ena.html), [NVMe Storage Controller](https://docs.aws.amazon.com/zh_cn/AWSEC2/latest/WindowsGuide/aws-nvme-drivers.html))
- GCP ([gVNIC Network Adapter](https://cloud.google.com/compute/docs/networking/using-gvnic), [GGA Graphics](https://cloud.google.com/compute/docs/instances/enable-instance-virtual-display))
- Azure ([MANA Network Adapter](https://learn.microsoft.com/zh-cn/azure/virtual-network/accelerated-networking-mana-windows))
3. Vista (Server 2008) and 32-bit systems may lack drivers.
4. For EFI machines without CSM enabled, Windows 7 (Server 2008 R2) cannot be installed.
5. If the machine has a static IP, the IP will be automatically set after installation.
@ -173,6 +181,8 @@ Use `Dism++` File menu > Open Image File, select the iso to be installed to get
<https://massgrave.dev/genuine-installation-media.html> (Recommended, iso sourced from official channels, updated monthly, includes the latest patches)
<https://www.microsoft.com/software-download/windows8>
<https://www.microsoft.com/software-download/windows10> (Need to open it with a mobile User-Agent)
<https://www.microsoft.com/software-download/windows11>
@ -184,8 +194,8 @@ Use `Dism++` File menu > Open Image File, select the iso to be installed to get
| Debian | 384M | 512M |
| Ubuntu | 1G | 512M |
| CentOS / Alma / Rocky / Fedora | 1G | 512M |
| Alpine | 256M | - |
| openSUSE | - | 512M |
| Alpine | 256M | - |
| Arch | 512M | - |
| Gentoo | 512M | - |
| Windows 8.1 (Server 2012 R2) or below | 512M | - |

View File

@ -122,17 +122,25 @@ bash reinstall.sh netboot.xyz
```bash
bash reinstall.sh windows \
--iso 'https://drive.massgrave.dev/en-us_windows_10_enterprise_ltsc_2021_x64_dvd_d289cf96.iso' \
--image-name 'Windows 10 Enterprise LTSC 2021' \
--iso 'https://drive.massgrave.dev/en-us_windows_10_enterprise_ltsc_2021_x64_dvd_d289cf96.iso'
```
- 现在脚本支持自动查找 Windows (含 LTSC) 和 Windows Server iso 链接
- 需设置语言 `--lang`,默认 `en-us`
- 查找源:<https://massgrave.dev/genuine-installation-media.html>
```bash
bash reinstall.sh windows \
--image-name 'Windows 10 Enterprise LTSC 2021'
--lang zh-cn
```
![Installing Windows](https://github.com/bin456789/reinstall/assets/7548515/07c1aea2-1ce3-4967-904f-aaf9d6eec3f7)
参数:
参数说明:
`--iso` 原版镜像链接
`--image-name` 指定要安装的映像,不区分大小写,例如:
`--image-name` 指定要安装的映像,不区分大小写,常用映像有:
```text
Windows 7 Ultimate
@ -146,18 +154,18 @@ Windows Server 2022 SERVERDATACENTER
![image-name](https://github.com/bin456789/reinstall/assets/7548515/5aae0a9b-61e2-4f66-bb98-d470a6beaac2)
1. 支持的系统:
- Windows Vista 到 11
- Windows Server 2008 到 2022包括以下衍生版
- Windows Server Essentials
- Windows Server Annual Channel
- Hyper-V Server
- Azure Stack HCI
- Windows Vista 到 11
- Windows Server 2008 到 2022包括以下衍生版
- Windows Server Essentials
- Windows Server Annual Channel
- Hyper-V Server
- Azure Stack HCI
2. 脚本会按需安装以下驱动:
- KVM ([Virtio](https://fedorapeople.org/groups/virt/virtio-win/direct-downloads/))
- XEN ([XEN PV](https://xenproject.org/windows-pv-drivers/)、[AWS PV](https://docs.aws.amazon.com/zh_cn/AWSEC2/latest/WindowsGuide/xen-drivers-overview.html))
- AWS ([ENA 网卡](https://docs.aws.amazon.com/zh_cn/AWSEC2/latest/WindowsGuide/enhanced-networking-ena.html)、[NVME 存储控制器](https://docs.aws.amazon.com/zh_cn/AWSEC2/latest/WindowsGuide/aws-nvme-drivers.html))
- GCP ([gVNIC 网卡](https://cloud.google.com/compute/docs/networking/using-gvnic)、[GGA 显卡](https://cloud.google.com/compute/docs/instances/enable-instance-virtual-display))
- Azure ([MANA 网卡](https://learn.microsoft.com/zh-cn/azure/virtual-network/accelerated-networking-mana-windows))
- KVM ([Virtio](https://fedorapeople.org/groups/virt/virtio-win/direct-downloads/))
- XEN ([XEN PV](https://xenproject.org/windows-pv-drivers/)、[AWS PV](https://docs.aws.amazon.com/zh_cn/AWSEC2/latest/WindowsGuide/xen-drivers-overview.html))
- AWS ([ENA 网卡](https://docs.aws.amazon.com/zh_cn/AWSEC2/latest/WindowsGuide/enhanced-networking-ena.html)、[NVME 存储控制器](https://docs.aws.amazon.com/zh_cn/AWSEC2/latest/WindowsGuide/aws-nvme-drivers.html))
- GCP ([gVNIC 网卡](https://cloud.google.com/compute/docs/networking/using-gvnic)、[GGA 显卡](https://cloud.google.com/compute/docs/instances/enable-instance-virtual-display))
- Azure ([MANA 网卡](https://learn.microsoft.com/zh-cn/azure/virtual-network/accelerated-networking-mana-windows))
3. Vista (Server 2008) 和 32 位系统可能会缺少驱动
4. 未开启 CSM 的 EFI 机器,无法安装 Windows 7 (Server 2008 R2)
5. 静态 IP 的机器,安装后会自动配置好 IP
@ -173,6 +181,8 @@ Windows Server 2022 SERVERDATACENTER
<https://massgrave.dev/genuine-installation-media.html> (推荐iso 来自官方,每月更新,包含最新补丁)
<https://www.microsoft.com/software-download/windows8>
<https://www.microsoft.com/software-download/windows10> (需用手机 User-Agent 打开)
<https://www.microsoft.com/software-download/windows11>
@ -184,8 +194,8 @@ Windows Server 2022 SERVERDATACENTER
| Debian | 384M | 512M |
| Ubuntu | 1G | 512M |
| CentOS / Alma / Rocky / Fedora | 1G | 512M |
| Alpine | 256M | - |
| openSUSE | - | 512M |
| Alpine | 256M | - |
| Arch | 512M | - |
| Gentoo | 512M | - |
| Windows 8.1 (Server 2012 R2) 或以下 | 512M | - |

View File

@ -329,6 +329,337 @@ is_virt() {
$_is_virt
}
# sr-latn-rs 到 sr-latn
en_us() {
echo "$lang" | awk -F- '{print $1"-"$2}'
# zh-hk 可回落到 zh-tw
if [ "$lang" = zh-hk ]; then
echo zh-tw
fi
}
# fr-ca 到 fr
us() {
# 葡萄牙准确对应 pp
if [ "$lang" = pt-pt ]; then
echo pp
return
fi
# 巴西准确对应 pt
if [ "$lang" = pt-br ]; then
echo pt
return
fi
echo "$lang" | awk -F- '{print $2}'
# hk 额外回落到 tw
if [ "$lang" = zh-hk ]; then
echo tw
fi
}
# fr-ca 到 fr-fr
en_en() {
echo "$lang" | awk -F- '{print $1"-"$1}'
# en-gb 额外回落到 en-us
if [ "$lang" = en-gb ]; then
echo en-us
fi
}
# zh-cn 到 zh
en() {
# 巴西/葡萄牙回落到葡萄牙语
if [ "$lang" = pt-br ] || [ "$lang" = pt-br ]; then
echo "pp"
return
fi
echo "$lang" | awk -F- '{print $1}'
}
english() {
case "$lang" in
ar-sa) echo Arabic ;;
bg-bg) echo Bulgarian ;;
cs-cz) echo Czech ;;
da-dk) echo Danish ;;
de-de) echo German ;;
el-gr) echo Greek ;;
en-gb) echo Eng_Intl ;;
en-us) echo English ;;
es-es) echo Spanish ;;
es-mx) echo Spanish_Latam ;;
et-ee) echo Estonian ;;
fi-fi) echo Finnish ;;
fr-ca) echo FrenchCanadian ;;
fr-fr) echo French ;;
he-il) echo Hebrew ;;
hr-hr) echo Croatian ;;
hu-hu) echo Hungarian ;;
it-it) echo Italian ;;
ja-jp) echo Japanese ;;
ko-kr) echo Korean ;;
lt-lt) echo Lithuanian ;;
lv-lv) echo Latvian ;;
nb-no) echo Norwegian ;;
nl-nl) echo Dutch ;;
pl-pl) echo Polish ;;
pt-pt) echo Portuguese ;;
pt-br) echo Brazilian ;;
ro-ro) echo Romanian ;;
ru-ru) echo Russian ;;
sk-sk) echo Slovak ;;
sl-si) echo Slovenian ;;
sr-latn | sr-latn-rs) echo Serbian_Latin ;;
sv-se) echo Swedish ;;
th-th) echo Thai ;;
tr-tr) echo Turkish ;;
uk-ua) echo Ukrainian ;;
zh-cn) echo ChnSimp ;;
zh-hk | zh-tw) echo ChnTrad ;;
esac
}
parse_windows_image_name() {
set -- $image_name
if ! [ "$1" = windows ]; then
return 1
fi
shift
if [ "$1" = server ]; then
server=server
shift
fi
version=$1
shift
if [ "$1" = r2 ]; then
version+=" r2"
shift
fi
edition=
for i in "$@"; do
case "$i" in
# windows 10 enterprise n ltsc 2021
k | n | kn) ;;
*)
if [ -n "$edition" ]; then
edition+=" "
fi
edition+="$1"
;;
esac
shift
done
}
is_have_arm_version() {
case "$version" in
10)
case "$edition" in
pro | 'pro for workstations' | education | 'pro education' | enterprise) return ;;
'iot enterprise') return ;;
'iot enterprise ltsc 2021' | 'enterprise ltsc 2021') return ;;
esac
;;
11)
case "$edition" in
pro | 'pro for workstations' | education | 'pro education' | enterprise) return ;;
'iot enterprise') return ;;
esac
;;
esac
return 1
}
find_windows_iso() {
parse_windows_image_name || error_and_exit "--image-name wrong: $image_name"
if ! [ "$version" = 8.1 ] && [ -z "$edition" ]; then
error_and_exit "Edition is not set."
fi
if [ "$basearch" = 'aarch64' ] && ! is_have_arm_version; then
error_and_exit "No ARM iso for this Windows Version."
fi
if [ -z "$lang" ]; then
lang=en-us
fi
langs="$lang $(en_us) $(us) $(en_en) $(en)"
langs=$(echo "$langs" | xargs -n 1 | awk '!seen[$0]++')
full_lang=$(english)
case "$basearch" in
x86_64) arch_win=x64 ;;
aarch64) arch_win=arm64 ;;
esac
get_windows_iso_links
get_windows_iso_link
}
get_windows_iso_links() {
label_msdn=$(
if [ -n "$server" ]; then
case "$version" in
2008 | '2008 r2')
case "$edition" in
serverweb | serverwebcore) echo _ ;;
serverstandard | serverstandardcore) echo _ ;;
serverenterprise | serverenterprisecore) echo _ ;;
serverdatacenter | serverdatacentercore) echo _ ;;
esac
;;
'2012 r2' | 2016 | 2019 | 2022)
case "$edition" in
serverstandard | serverstandardcore) echo _ ;;
serverdatacenter | serverdatacentercore) echo _ ;;
esac
;;
esac
else
case "$version" in
vista)
case "$edition" in
enterprise) echo _ ;;
homebasic | homepremium | business | ultimate) echo _ ;;
esac
;;
7)
case "$edition" in
professional) echo professional ;;
business | enterprise) echo enterprise ;;
homebasic | homepremium | ultimate) echo ultimate ;;
esac
;;
8.1)
case "$edition" in
'') echo _ ;;
pro) echo pro ;;
enterprise) echo enterprise ;;
esac
;;
10)
case "$edition" in
home | 'home single language') echo consumer ;;
pro | 'pro for workstations' | education | 'pro education' | enterprise) echo business ;;
'iot enterprise') echo 'iot enterprise' ;;
'enterprise 2015 ltsb' | 'enterprise 2016 ltsb') echo "$edition" ;;
'enterprise ltsc 2019' | 'iot enterprise ltsc 2019' | 'iot enterprise ltsc 2021') echo "$edition" ;;
'enterprise ltsc 2021')
# arm64 的 enterprise ltsc 2021 要下载 iot enterprise ltsc 2021 iso
case "$arch_win" in
arm64) echo 'iot enterprise ltsc 2021' ;;
x86 | x64) echo 'enterprise ltsc 2021' ;;
esac
;;
esac
;;
11)
case "$edition" in
home | 'home single language') echo consumer ;;
pro | 'pro for workstations' | education | 'pro education' | enterprise) echo business ;;
'iot enterprise') echo 'iot enterprise' ;;
esac
;;
esac
fi
)
label_vlsc=$(
case "$version" in
10 | 11)
case "$edition" in
pro | 'pro for workstations' | education | 'pro education' | enterprise) echo pro ;;
esac
;;
esac
)
page=$(
if [ "$arch_win" = arm64 ]; then
echo arm
elif grep -Ewq 'ltsb|ltsc' <<<"$edition"; then
echo ltsc
elif [ "$server" = 'server' ]; then
echo server
else
case "$version" in
vista | 7 | 8.1 | 10 | 11)
echo "$version"
;;
esac
fi
)
page_url=https://massgrave.dev/windows_${page}_links.html
info "Find windows iso"
echo "Version: $version"
echo "Edition: $edition"
echo "Label msdn: $label_msdn"
echo "Label vlsc: $label_vlsc"
echo "List: $page_url"
echo
if [ -n "$page" ] && { [ -n "$label_msdn" ] || [ -n "$label_vlsc" ]; }; then
if [ "$label_msdn" = _ ]; then
label_msdn=
fi
if [ "$label_vlsc" = _ ]; then
label_vlsc=
fi
else
error_and_exit "Not support find this iso. Check --image-name or set --iso manually."
fi
curl -L "$page_url" | grep -ioP 'https://.*?.iso' | awk -F/ '{print $NF}' >$tmp/win.list
}
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 }'
}
get_windows_iso_link() {
regexs=()
# msdn
for lang in $langs; do
regex=
for i in ${lang} windows ${server} ${version} ${label_msdn}; do
if [ -n "$i" ]; then
regex+="${i}_"
fi
done
regex+=".*${arch_win}.*.iso"
regexs+=("$regex")
done
# vlsc
regex="sw_dvd9_win_${label_vlsc}_${version}.*${arch_win}_${full_lang}.*.iso"
regexs+=("$regex")
# 查找
for regex in "${regexs[@]}"; do
regex=${regex// /_}
echo "finding: $regex" >&2
if file=$(grep -Eix "$regex" "$tmp/win.list" | get_shortest_line | grep .); then
iso="https://drive.massgrave.dev/$file"
return
fi
done
error_and_exit "Could not find windows iso."
}
setos() {
local step=$1
local distro=$2
@ -548,6 +879,11 @@ setos() {
}
setos_windows() {
if [ -z "$iso" ]; then
echo "iso url is not set. Try to find it."
find_windows_iso
fi
test_url $iso 'iso|dos/mbr'
eval "${step}_iso='$iso'"
eval "${step}_image_name='$image_name'"
@ -705,8 +1041,8 @@ verify_os_args() {
case "$distro" in
dd) [ -n "$img" ] || error_and_exit "dd need --img" ;;
windows)
if [ -z "$iso" ] || [ -z "$image_name" ]; then
error_and_exit "Install Windows need --iso and --image-name"
if [ -z "$image_name" ]; then
error_and_exit "Install Windows need --image-name."
fi
;;
esac
@ -881,7 +1217,7 @@ check_ram() {
alpine | debian | dd) echo 256 ;;
arch | gentoo | windows) echo 512 ;;
centos | alma | rocky | fedora | ubuntu) echo 1024 ;;
opensuse) echo max ;; # 没有安装模式
opensuse) echo -1 ;; # 没有安装模式
esac
)
@ -1977,7 +2313,7 @@ else
fi
# 整理参数
if ! opts=$(getopt -n $0 -o "" --long debug,hold:,sleep:,iso:,image-name:,img:,ci,cloud-image -- "$@"); then
if ! opts=$(getopt -n $0 -o "" --long ci,debug,hold:,sleep:,iso:,image-name:,img:,lang: -- "$@"); then
usage_and_exit
fi
@ -1989,12 +2325,15 @@ while true; do
set -x
shift
;;
--ci | --cloud-image)
--ci)
cloud_image=1
shift
;;
--hold | --sleep)
hold=$2
if ! { [ "$hold" = 1 ] || [ "$hold" = 2 ]; }; then
error_and_exit "Invalid --hold value: $hold."
fi
shift 2
;;
--img)
@ -2006,7 +2345,11 @@ while true; do
shift 2
;;
--image-name)
image_name=$2
image_name=$(echo "$2" | to_lower)
shift 2
;;
--lang)
lang=$(echo "$2" | to_lower)
shift 2
;;
--)