Compare commits

...

2 Commits

Author SHA1 Message Date
bin456789
ae69f6a841
core: 优化 windows 下的文件下载 2025-04-17 21:10:25 +08:00
bin456789
4061c5c6b6
dd: State.ini 不存在时从注册表判断系统状态 2025-04-17 21:10:24 +08:00
2 changed files with 53 additions and 29 deletions

View File

@ -126,12 +126,9 @@ call :check_cygwin_installed || (
--packages %pkgs%
rem 检查 Cygwin 是否成功安装
if errorlevel 1 (
goto :install_cygwin_failed
) else (
if errorlevel 1 goto :install_cygwin_failed
call :check_cygwin_installed || goto :install_cygwin_failed
)
)
rem 在c盘根目录下执行 cygpath -ua . 会得到 /cygdrive/c因此末尾要有 /
for /f %%a in ('%SystemDrive%\cygwin\bin\cygpath -ua ./') do set thisdir=%%a
@ -159,23 +156,28 @@ rem 或者添加 export PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/
%SystemDrive%\cygwin\bin\bash %thisdir%reinstall.sh %*
exit /b
:download
rem bits 要求有 Content-Length 才能下载
rem cloudflare 的 cdn-cgi/trace 没有 Content-Length
rem 据说如果网络设为“按流量计费” bits 也无法下载
rem https://learn.microsoft.com/en-us/windows/win32/bits/http-requirements-for-bits-downloads
rem bitsadmin /transfer "%~3" /priority foreground %~1 %~2
:download
rem certutil 会被 windows Defender 报毒
rem windows server 2019 要用第二条 certutil 命令
echo Download: %~1 %~2
del /q "%~2" 2>nul
if exist "%~2" (echo Cannot delete %~2 & exit /b 1)
if not exist "%~2" certutil -urlcache -f -split "%~1" "%~2" >nul
if not exist "%~2" certutil -urlcache -split "%~1" "%~2" >nul
if not exist "%~2" exit /b 1
exit /b
certutil -urlcache -f -split "%~1" "%~2" >nul
if not errorlevel 1 if exist "%~2" exit /b 0
certutil -urlcache -split "%~1" "%~2" >nul
if not errorlevel 1 if exist "%~2" exit /b 0
rem 下载失败时删除文件,防止下载了一部分导致下次运行时跳过了下载
del /q "%~2" 2>nul
exit /b 1
:download_with_curl
rem 加 --insecure 防止以下错误

View File

@ -2775,6 +2775,28 @@ EOF
create_cloud_init_network_config "$ci_file" "$recognize_static6" "$recognize_ipv6_types"
}
get_image_state() {
local os_dir=$1
local image_state=
# 如果 dd 镜像精简了 State.ini则从注册表获取
if state_ini=$(find_file_ignore_case $os_dir/Windows/Setup/State/State.ini); then
image_state=$(grep -i '^ImageState=' $state_ini | cut -d= -f2 | tr -d '\r')
fi
if [ -z "$image_state" ]; then
apk add hivex
hive=$(find_file_ignore_case $os_dir/Windows/System32/config/SOFTWARE)
image_state=$(hivexget $hive '\Microsoft\Windows\CurrentVersion\Setup\State' ImageState)
apk del hivex
fi
if [ -n "$image_state" ]; then
echo "$image_state"
else
error_and_exit "Cannot get ImageState."
fi
}
modify_windows() {
os_dir=$1
info "Modify Windows"
@ -2784,15 +2806,8 @@ modify_windows() {
# https://learn.microsoft.com/windows-hardware/manufacture/desktop/add-a-custom-script-to-windows-setup
# 判断用 SetupComplete 还是组策略
# 默认视为 IMAGE_STATE_COMPLETE除非有 State.ini因为 dd 镜像可能精简了 State.ini
# 但最好还是从注册表获取
image_state=IMAGE_STATE_COMPLETE
if state_ini=$(find_file_ignore_case $os_dir/Windows/Setup/State/State.ini); then
cat -n $state_ini
if tmp=$(grep -i '^ImageState=' $state_ini | cut -d= -f2 | tr -d '\r' | grep .); then
image_state=$tmp
fi
fi
image_state=$(get_image_state "$os_dir")
echo "ImageState: $image_state"
if [ "$image_state" = IMAGE_STATE_COMPLETE ]; then
use_gpo=true
@ -5231,15 +5246,18 @@ is_list_has() {
echo "$list" | grep -qFx "$item"
}
# hivexget 是 shell 脚本,开头是 #!/bin/bash
# 但 alpine 没安装 bash直接运行 hivexget 会报错
hivexget() {
ash "$(which hivexget)" "$@"
}
get_installation_type_from_windows_drive() {
os_dir=$1
local os_dir=$1
apk add hivex
software_hive=$(find_file_ignore_case $os_dir/Windows/System32/config/SOFTWARE)
hivexsh "$software_hive" <<EOF
cd \Microsoft\Windows NT\CurrentVersion
lsval InstallationType
EOF
hive=$(find_file_ignore_case $os_dir/Windows/System32/config/SOFTWARE)
hivexget $hive '\Microsoft\Windows NT\CurrentVersion' InstallationType
apk del hivex
}
@ -5631,6 +5649,7 @@ install_windows() {
file=$(
case "$product_ver" in
'7' | '2008 r2') $support_sha256 &&
# 25.0 比 24.5 只更新了 ProSet 软件,驱动相同
echo echo 18713/eng/prowin${arch_intel}legacy.exe || # 25.0 有部分文件是 sha256 签名
echo 29323/eng/prowin${arch_intel}legacy.exe ;; # 24.3 sha1 签名
'8') echo 21642/eng/prowin${arch_intel}.exe ;;
@ -5869,6 +5888,9 @@ EOF
# 2. 2020/8/10 将部分文件降到 17400相当于 189~215 iso
# 3. 2022/4/14 将部分文件降级,相当于 217~最新版 iso
# 可改成直接从 github commit 下载 win7 173(sha1) 176(sha256) 全家桶?
# 国内可使用 jsdelivr 加速 github
# 2008 安装的气球驱动不能用,需要到硬件管理器重新安装设备才能用,无需更新驱动
# 2k12