diff --git a/reinstall.sh b/reinstall.sh index cb43578..a315859 100644 --- a/reinstall.sh +++ b/reinstall.sh @@ -1294,6 +1294,28 @@ Continue? test_url "$iso" 'iso raw' [ -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'" diff --git a/trans.sh b/trans.sh index ed910db..00cb761 100644 --- a/trans.sh +++ b/trans.sh @@ -4053,6 +4053,21 @@ get_filesize_mb() { } install_windows() { + get_wim_prop() { + wim=$1 + property=$2 + + wiminfo "$wim" | grep -i "^$property:" | cut -d: -f2- | xargs + } + + get_image_prop() { + wim=$1 + index=$2 + property=$3 + + wiminfo "$wim" "$index" | grep -i "^$property:" | cut -d: -f2- | xargs + } + info "Process windows iso" apk add wimlib @@ -4061,6 +4076,17 @@ install_windows() { mkdir -p /iso mount -o ro /os/windows.iso /iso + # 防止用了不兼容架构的 iso + boot_index=$(get_wim_prop /iso/sources/boot.wim 'Boot Index') + arch_wim=$(get_image_prop /iso/sources/boot.wim "$boot_index" 'Architecture' | to_lower) + if ! { + { [ "$(uname -m)" = "x86_64" ] && [ "$arch_wim" = x86_64 ]; } || + { [ "$(uname -m)" = "x86_64" ] && [ "$arch_wim" = x86 ]; } || + { [ "$(uname -m)" = "aarch64" ] && [ "$arch_wim" = arm64 ]; } + }; then + error_and_exit "The machine is $(uname -m), but the iso is $arch_wim." + fi + if [ -e /iso/sources/install.esd ]; then iso_install_wim=/iso/sources/install.esd install_wim=/os/installer/sources/install.esd @@ -4105,14 +4131,8 @@ install_windows() { done fi - get_boot_wim_prop() { - property=$1 - wiminfo "/os/boot.wim" | grep -i "^$property:" | cut -d: -f2- | xargs - } - get_selected_image_prop() { - property=$1 - wiminfo "$iso_install_wim" "$image_name" | grep -i "^$property:" | cut -d: -f2- | xargs + get_image_prop "$iso_install_wim" "$image_name" "$1" } # PRODUCTTYPE: @@ -4219,7 +4239,6 @@ install_windows() { # arch_dd 华为云驱动 32 64 # 将 wim 的 arch 转为驱动和应答文件的 arch - arch_wim=$(get_selected_image_prop Architecture | to_lower) case "$arch_wim" in x86) arch=x86 @@ -4238,15 +4257,6 @@ install_windows() { ;; esac - # 防止用了不兼容架构的 iso - if ! { - { [ "$(uname -m)" = "x86_64" ] && [ "$arch_wim" = x86_64 ]; } || - { [ "$(uname -m)" = "x86_64" ] && [ "$arch_wim" = x86 ]; } || - { [ "$(uname -m)" = "aarch64" ] && [ "$arch_wim" = arm64 ]; } - }; then - error_and_exit "The machine is $(uname -m), but the iso is $arch_wim." - fi - add_drivers() { info "Add drivers" @@ -4624,11 +4634,17 @@ install_windows() { fi done fi - done - [ "$arch_wim" = x86 ] && gvnic_suffix=-32 || gvnic_suffix= - cp_drivers $drv/gce/gvnic -ipath "*/win$nt_ver$gvnic_suffix/*" - cp_drivers $drv/gce/gga -ipath "*/win$nt_ver/*" + case "$name" in + gvnic) + [ "$arch_wim" = x86 ] && suffix=-32 || suffix= + cp_drivers $drv/gce/gvnic -ipath "*/win$nt_ver$suffix/*" + ;; + gga) + cp_drivers $drv/gce/gga -ipath "*/win$nt_ver/*" + ;; + esac + done } # azure @@ -4700,7 +4716,6 @@ install_windows() { # 挂载 boot.wim info "mount boot.wim" mkdir -p /wim - boot_index=$(get_boot_wim_prop 'Boot Index') wimmountrw /os/boot.wim "$boot_index" /wim/ cp_drivers() {