Compare commits

...

5 Commits

Author SHA1 Message Date
bin456789
4f5eaa70b6
windows: 更新 iso 链接 2025-05-16 20:49:02 +08:00
bin456789
e3ed8703ab
redhat: 不需要输入版本号 2025-05-16 19:06:09 +08:00
bin456789
14ef2c8269
windows: vista 禁用气球驱动 2025-05-16 19:06:08 +08:00
bin456789
6a57249015
windows: vista 从镜像获取默认密钥 2025-05-16 19:06:08 +08:00
bin456789
19198a6146
windows: 提示用户输入 iso 直链 2025-05-16 19:06:07 +08:00
4 changed files with 95 additions and 75 deletions

View File

@ -15,7 +15,7 @@ One-Click Script to Reinstall System [中文](README.md)
## Highlights
- One-click Linux installation: Supports 19 common distributions.
- One-click Windows installation: Uses the official ISO for installation instead of custom images. The script can automatically ~~retrieves the ISO link~~ and installs common drivers like `Virtio`.
- One-click Windows installation: Uses the official ISO for installation instead of custom images. The script can automatically retrieves the ISO link and installs common drivers like `Virtio`.
- Supports installation in any direction, i.e., `Linux to Linux`, `Linux to Windows`, `Windows to Windows`, `Windows to Linux`
- No need to input IP parameters; automatically recognizes dynamic and static IPs, supports `/32`, `/128`, `gateway outside subnet`, `IPv6 only`, `dual NIC`
- Specially optimized for low-spec servers, requires less memory than the official netboot
@ -128,7 +128,6 @@ certutil -urlcache -f -split https://cnb.cool/bin456789/reinstall/-/git/raw/main
bash reinstall.sh anolis 7|8|23
opencloudos 8|9|23
rocky 8|9
redhat 8|9 --img="http://xxx.com/xxx.qcow2"
oracle 8|9
almalinux 8|9
centos 9|10
@ -144,6 +143,7 @@ bash reinstall.sh anolis 7|8|23
gentoo
aosc
fnos
redhat --img="http://access.cdn.redhat.com/xxx.qcow2"
```
#### Optional Parameters
@ -211,7 +211,7 @@ bash reinstall.sh ubuntu --installer
bash reinstall.sh dd --img "https://example.com/xxx.xz"
```
#### Optional parameters
#### Optional Parameters
- `--allow-ping` Configure Windows Firewall to Allow Ping Responses (DD Windows only)
- `--rdp-port PORT` Change RDP port (DD Windows only)
@ -234,7 +234,7 @@ bash reinstall.sh dd --img "https://example.com/xxx.xz"
bash reinstall.sh alpine --hold=1
```
#### Optional parameters
#### Optional Parameters
- `--password PASSWORD` Set password
- `--ssh-port PORT` Change SSH port
@ -278,10 +278,7 @@ bash reinstall.sh netboot.xyz
- Hyper-V Server \*
- Azure Stack HCI \*
#### ~~Method 1: Let the Script Automatically Search for ISO~~
> [!CAUTION]
> The ISO repository currently prohibits direct link downloads, so this method is no longer effective.
#### Method 1: Let the Script Automatically Search for ISO
- The script will search for ISOs from <https://massgrave.dev/genuine-installation-media>, a site that collects official ISOs.
- Systems marked with \* do not support automatic ISO searching.
@ -384,7 +381,7 @@ bash reinstall.sh windows \
</details>
#### Optional parameters
#### Optional Parameters
- `--password PASSWORD` Set Password
- `--allow-ping` Configure Windows Firewall to Allow Ping Responses

View File

@ -15,7 +15,7 @@
## 亮点
- 一键安装 Linux支持 19 种常见发行版
- 一键安装 Windows使用官方 ISO 安装而非自制镜像,~~脚本会自动获取 ISO 链接~~、自动安装 Virtio 等常见驱动
- 一键安装 Windows使用官方 ISO 安装而非自制镜像,脚本会自动获取 ISO 链接、自动安装 Virtio 等常见驱动
- 支持任意方向重装,即 `Linux to Linux``Linux to Windows``Windows to Windows``Windows to Linux`
- 无需填写 IP 参数,自动识别动静态,支持 `/32``/128``网关不在子网范围内``纯 IPv6``双网卡`
- 专门适配低配小鸡,比官方 netboot 需要更少的内存
@ -128,7 +128,6 @@ certutil -urlcache -f -split https://cnb.cool/bin456789/reinstall/-/git/raw/main
bash reinstall.sh anolis 7|8|23
opencloudos 8|9|23
rocky 8|9
redhat 8|9 --img="http://xxx.com/xxx.qcow2"
oracle 8|9
almalinux 8|9
centos 9|10
@ -144,6 +143,7 @@ bash reinstall.sh anolis 7|8|23
gentoo
aosc
fnos
redhat --img="http://access.cdn.redhat.com/xxx.qcow2"
```
#### 可选参数
@ -278,10 +278,7 @@ bash reinstall.sh netboot.xyz
- Hyper-V Server \*
- Azure Stack HCI \*
#### ~~方法 1: 让脚本自动查找 ISO~~
> [!CAUTION]
> 目前该 ISO 仓库禁止了直链下载,因此该方法已失效
#### 方法 1: 让脚本自动查找 ISO
- 脚本会从 <https://massgrave.dev/genuine-installation-media> 查找 ISO该网站专门提供官方 ISO 下载
- 上面带 \* 的系统不支持自动查找 ISO

View File

@ -48,7 +48,6 @@ usage_and_exit() {
Usage: $reinstall_____ anolis 7|8|23
opencloudos 8|9|23
rocky 8|9
redhat 8|9 --img="http://xxx.com/xxx.qcow2"
oracle 8|9
almalinux 8|9
centos 9|10
@ -64,6 +63,7 @@ Usage: $reinstall_____ anolis 7|8|23
gentoo
aosc
fnos
redhat --img="http://access.cdn.redhat.com/xxx.qcow2"
dd --img="http://xxx.com/yyy.zzz" (raw image stores in raw/vhd/tar/gz/xz/zst)
windows --image-name="windows xxx yyy" --lang=xx-yy
windows --image-name="windows xxx yyy" --iso="http://xxx.com/xxx.iso"
@ -93,14 +93,20 @@ info() {
shift
msg=$*
else
msg=$(to_upper <<<"$@")
msg="***** $(to_upper <<<"$*") *****"
fi
echo_color_text '\e[32m' "***** $msg *****" >&2
echo_color_text '\e[32m' "$msg" >&2
}
warn() {
echo_color_text '\e[33m' "Warning: $*" >&2
local msg
if [ "$1" = false ]; then
shift
msg=$*
else
msg="Warning: $*"
fi
echo_color_text '\e[33m' "$msg" >&2
}
error() {
@ -838,11 +844,10 @@ find_windows_iso() {
aarch64) arch_win=arm64 ;;
esac
get_windows_iso_links
get_windows_iso_link
}
get_windows_iso_links() {
get_windows_iso_link() {
get_label_msdn() {
if [ -n "$server" ]; then
case "$version" in
@ -872,7 +877,6 @@ get_windows_iso_links() {
esac
;;
homebasic | homepremium | business | ultimate) echo _ ;;
enterprise) echo enterprise ;;
esac
;;
7)
@ -882,18 +886,10 @@ get_windows_iso_links() {
x86) echo ultimate ;;
esac
;;
professional) echo professional ;;
homebasic | homepremium | ultimate) echo ultimate ;;
enterprise) echo enterprise ;;
esac
;;
8.1)
case "$edition" in
'') ;; # massgrave 不提供 windows 8.1 家庭版链接
pro) echo pro ;;
enterprise) echo enterprise ;;
homebasic | homepremium | professional | ultimate) echo ultimate ;;
esac
;;
# 8.1 需到 msdl.gravesoft.dev 下载
10)
case "$edition" in
home | 'home single language') echo consumer ;;
@ -945,6 +941,25 @@ get_windows_iso_links() {
esac
}
get_label_msdl() {
case "$version" in
8.1)
case "$edition" in
'' | pro) echo _ ;;
esac
;;
11)
case "$edition" in
home | 'home single language' | pro | education | 'pro education' | 'pro for workstations')
case "$arch_win" in
arm64) echo _ ;;
esac
;;
esac
;;
esac
}
get_page() {
if [ "$arch_win" = arm64 ]; then
echo arm
@ -967,6 +982,7 @@ get_windows_iso_links() {
# 部分 bash 不支持 $() 里面嵌套case所以定义成函数
label_msdn=$(get_label_msdn)
label_msdl=$(get_label_msdl)
label_vlsc=$(get_label_vlsc)
page=$(get_page)
@ -976,25 +992,32 @@ get_windows_iso_links() {
echo "Version: $version"
echo "Edition: $edition"
echo "Label msdn: $label_msdn"
echo "Label msdl: $label_msdl"
echo "Label vlsc: $label_vlsc"
echo "List: $page_url"
echo
if [ -z "$page" ] || { [ -z "$label_msdn" ] && [ -z "$label_vlsc" ]; }; then
if [ -z "$page" ] || { [ -z "$label_msdn" ] && [ -z "$label_msdl" ] && [ -z "$label_vlsc" ]; }; then
error_and_exit "Not support find this iso. Check if --image-name is wrong. If not, set --iso manually."
fi
curl -L "$page_url" | grep -ioP 'https://.*?.(iso|img)' >$tmp/win.list
# 如果不是 ltsc ,应该先去除 ltsc 链接,否则最终链接有 ltsc 的
# 例如查找 windows 10 iot enterprise会得到
# en-us_windows_10_iot_enterprise_ltsc_2021_arm64_dvd_e8d4fc46.iso
# en-us_windows_10_iot_enterprise_version_22h2_arm64_dvd_39566b6b.iso
# sed -Ei 和 sed -iE 是不同的
if is_ltsc; then
sed -Ei '/ltsc|ltsb/!d' $tmp/win.list
if [ -n "$label_msdl" ]; then
iso=$(curl -L "$page_url" | grep -ioP 'https://.*?#[0-9]+' | head -1 | grep .)
else
sed -Ei '/ltsc|ltsb/d' $tmp/win.list
curl -L "$page_url" | grep -ioP 'https://.*?.(iso|img)' >$tmp/win.list
# 如果不是 ltsc ,应该先去除 ltsc 链接,否则最终链接有 ltsc 的
# 例如查找 windows 10 iot enterprise会得到
# en-us_windows_10_iot_enterprise_ltsc_2021_arm64_dvd_e8d4fc46.iso
# en-us_windows_10_iot_enterprise_version_22h2_arm64_dvd_39566b6b.iso
# sed -Ei 和 sed -iE 是不同的
if is_ltsc; then
sed -Ei '/ltsc|ltsb/!d' $tmp/win.list
else
sed -Ei '/ltsc|ltsb/d' $tmp/win.list
fi
get_windows_iso_link_inner
fi
}
@ -1003,7 +1026,7 @@ get_shortest_line() {
awk '(NR == 1 || length($0) < length(shortest)) { shortest = $0 } END { print shortest }'
}
get_windows_iso_link() {
get_windows_iso_link_inner() {
regexs=()
# msdn
@ -1423,25 +1446,27 @@ Continue?
if [[ "$iso" = magnet:* ]]; then
: # 不测试磁力链接
else
iso_tested=false
# 需要用户输入 massgrave.dev 直链
if grep -Eiq '\.massgrave\.dev/.*\.(iso|img)$' <<<"$iso" ||
grep -Eiq '\.gravesoft\.dev/#[0-9]+$' <<<"$iso"; then
info "Set Direct link"
# MobaXterm 不支持
# printf '\e]8;;http://example.com\e\\This is a link\e]8;;\e\\\n'
# 获取 massgrave.dev 直链
if grep -Eiq '\.massgrave\.dev/.*\.(iso|img)' <<<"$iso"; then
# 如果已经是 iso 直链则跳过下面的 iso 测试
if test_url_grace "$iso" iso; 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
# MobaXterm 不显示为超链接
# info false "请在浏览器中打开 $iso 获取直链并粘贴到这里。"
# info false "Please open $iso in browser to get the direct link and paste it here."
echo "请在浏览器中打开 $iso 获取直链并粘贴到这里。"
echo "Please open $iso in browser to get the direct link and paste it here."
IFS= read -r -p "Direct Link: " iso
if [ -z "$iso" ]; then
error_and_exit "ISO Link is empty."
fi
fi
# 测试是否是 iso
if ! $iso_tested; then
test_url "$iso" iso
fi
test_url "$iso" iso
# 判断 iso 架构是否兼容
# https://gitlab.com/libosinfo/osinfo-db/-/tree/main/data/os/microsoft.com?ref_type=heads
@ -1670,13 +1695,11 @@ Continue with DD?
}
setos_redhat() {
# el 10 需要 x86-64-v3
if [ "$basearch" = x86_64 ] && [ "$releasever" -ge 10 ]; then
assert_cpu_supports_x86_64_v3
fi
if is_use_cloud_image; then
# ci
# el 10 需要 x86-64-v3
if [ "$basearch" = x86_64 ] && [[ "$img" = *rhel-10* ]]; then
assert_cpu_supports_x86_64_v3
fi
eval "${step}_img='$img'"
else
:
@ -1791,7 +1814,6 @@ verify_os_name() {
'opencloudos 8|9|23' \
'almalinux 8|9' \
'rocky 8|9' \
'redhat 8|9' \
'oracle 8|9' \
'fedora 41|42' \
'nixos 24.11' \
@ -1800,6 +1822,7 @@ verify_os_name() {
'alpine 3.18|3.19|3.20|3.21' \
'openeuler 20.03|22.03|24.03|25.03' \
'ubuntu 16.04|18.04|20.04|22.04|24.04|25.04' \
'redhat' \
'kali' \
'arch' \
'gentoo' \

View File

@ -6069,8 +6069,6 @@ EOF
# 可改成直接从 github commit 下载 win7 173(sha1) 176(sha256) 全家桶?
# 国内可使用 jsdelivr 加速 github
# 2008 安装的气球驱动不能用,需要到硬件管理器重新安装设备才能用,无需更新驱动
# 2k12
# https://github.com/virtio-win/virtio-win-pkg-scripts/issues/61
# 217 ~ 271 2k12 证书有问题,红帽的 virtio-win-1.9.45 没问题
@ -6118,8 +6116,13 @@ EOF
mkdir -p $drv/virtio
mount -o ro $drv/virtio.iso $drv/virtio
# -not -ipath "*/balloon/*"
cp_drivers $drv/virtio -ipath "*/$virtio_sys/$arch/*" "$@"
# vista 如果安装气动驱动,会报错 windows could not configure one or more system components
# 2008 安装的气球驱动不能用,需要到硬件管理器重新安装设备才能用,无需更新驱动
if [ "$product_ver" = vista ]; then
cp_drivers $drv/virtio -ipath "*/$virtio_sys/$arch/*" "$@" -not -ipath "*/balloon/*"
else
cp_drivers $drv/virtio -ipath "*/$virtio_sys/$arch/*" "$@"
fi
else
# coreutils 的 cp mv rm 才有 -v 参数
apk add 7zip file coreutils
@ -6449,14 +6452,14 @@ EOF
# key
if [ "$product_ver" = vista ]; then
# vista 需密钥,密钥可与 edition 不一致
# TODO: 改成从网页获取?
# vista 无人值守安装需要密钥,密钥可与 edition 不一致
# https://learn.microsoft.com/en-us/windows-server/get-started/kms-client-activation-keys
key=VKK3X-68KWM-X2YGT-QR4M6-4BWMV
# 从镜像获取默认密钥
setup_cfg=$(get_path_in_correct_case /os/installer/sources/inf/setup.cfg)
key=$(del_cr <"$setup_cfg" | grep -Eix 'Value=([A-Z0-9]{5}-){4}[A-Z0-9]{5}' | cut -d= -f2 | grep .)
sed -i "s/%key%/$key/" /tmp/autounattend.xml
else
# shellcheck disable=SC2010
if ls -d /os/installer/sources/* | grep -iq ei.cfg; then
if [ -f "$(get_path_in_correct_case /os/installer/sources/ei.cfg)" ]; then
# 镜像有 ei.cfg删除 key 字段
sed -i "/%key%/d" /tmp/autounattend.xml
else