From f4e497883f22269632db73b0716c3bc41943ea1c Mon Sep 17 00:00:00 2001 From: bin456789 Date: Mon, 21 Apr 2025 21:32:01 +0800 Subject: [PATCH] =?UTF-8?q?dd:=20=E4=BF=AE=E5=A4=8D=E9=83=A8=E5=88=86?= =?UTF-8?q?=E9=95=9C=E5=83=8F=E7=B3=BB=E7=BB=9F=E6=96=87=E4=BB=B6=E5=A4=A7?= =?UTF-8?q?=E5=B0=8F=E5=86=99=E4=B8=8D=E5=90=8C=E5=AF=BC=E8=87=B4=E6=8A=A5?= =?UTF-8?q?=E9=94=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- trans.sh | 6 ++-- windows-driver-utils.sh | 68 +++++++++++++++++++++++++++++------------ 2 files changed, 52 insertions(+), 22 deletions(-) diff --git a/trans.sh b/trans.sh index b1c16b6..c440d52 100644 --- a/trans.sh +++ b/trans.sh @@ -2843,9 +2843,9 @@ modify_windows() { if $use_gpo; then # 使用组策略 - gpt_ini=$os_dir/Windows/System32/GroupPolicy/gpt.ini - scripts_ini=$os_dir/Windows/System32/GroupPolicy/Machine/Scripts/scripts.ini + scripts_ini=$(get_path_in_correct_case $os_dir/Windows/System32/GroupPolicy/Machine/Scripts/scripts.ini) mkdir -p "$(dirname $scripts_ini)" + gpt_ini=$(get_path_in_correct_case $os_dir/Windows/System32/GroupPolicy/gpt.ini) # 备份 ini for file in $gpt_ini $scripts_ini; do @@ -2892,7 +2892,7 @@ EOF download $confhome/windows-del-gpo.bat $os_dir/windows-del-gpo.bat else # 使用 SetupComplete - setup_complete=$os_dir/Windows/Setup/Scripts/SetupComplete.cmd + setup_complete=$(get_path_in_correct_case $os_dir/Windows/Setup/Scripts/SetupComplete.cmd) mkdir -p "$(dirname $setup_complete)" # 添加到 C:\Setup\Scripts\SetupComplete.cmd 最前面 diff --git a/windows-driver-utils.sh b/windows-driver-utils.sh index a9fc69c..30ba377 100644 --- a/windows-driver-utils.sh +++ b/windows-driver-utils.sh @@ -115,6 +115,9 @@ list_files_from_inf() { # [Intel.NTamd64.6.0] # ; Empty section. + + # 如果后期改成不从 Manufacturer 获取支持的架构,而是从[]获取支持的架构,注意这种情况 + # [Intel.NTamd64.10.0.1..22000] ############################################## # 例子1 @@ -206,8 +209,7 @@ list_files_from_inf() { dir=$(echo "$line" | awk -F, '{print $4}' | simply_inf_word) # 每行一条记录 if [ -n "$SourceDisksNames" ]; then - SourceDisksNames="$SourceDisksNames -" + SourceDisksNames=$SourceDisksNames$'\n' fi SourceDisksNames="$SourceDisksNames$num:$dir" fi @@ -237,7 +239,11 @@ list_files_from_inf() { done < <(echo "$inf_txts") } -find_file_ignore_case() { +# windows 安装驱动时,只会安装相同架构的驱动文件到系统,即使 inf 里有列出其它架构的驱动 +# 因此 DISM 导出驱动时,也就没有包含其它架构的驱动文件 + +# 用于尽可能匹配路径大小写 +get_path_in_correct_case() { # 同时支持参数和管道 local path path=$({ if [ -n "$1" ]; then echo "$1"; else cat; fi; }) @@ -247,42 +253,66 @@ find_file_ignore_case() { # shellcheck disable=SC2046 set -- $(echo "$path" | grep -o '[^/]*') ( - # windows 安装驱动时,只会安装相同架构的驱动文件到系统,即使 inf 里有列出其它架构的驱动 - # 因此导出驱动时,也就不会包含其它架构的驱动文件 - # 因此这里只警告,不中断脚本 - local output= if is_absolute_path "$path"; then cd / output=/ fi + stop_find=false + while [ $# -gt 0 ]; do local part=$1 + local tmp # shellcheck disable=SC2010 - if part=$(ls -1 | grep -Fix "$part"); then - # 大于 1 表示当前 part 是目录 - if [ $# -gt 1 ]; then - if cd "$part"; then - output="$output$part/" - else - warn "Can't cd $path" - return 1 + if ! $stop_find; then + if tmp=$(ls -1 | grep -Fix "$part"); then + part=$tmp + # 大于 1 表示当前 part 是目录 + if [ $# -gt 1 ]; then + if ! cd "$part" 2>/dev/null; then + warn "Can't cd $path" + stop_find=true + fi fi else - # 最后 part - output="$output$part" + stop_find=true fi + fi + + if [ $# -gt 1 ]; then + output="$output$part/" else - warn "Can't find $path" >&2 - return 1 + # 最后 part + output="$output$part" fi shift done + echo "$output" ) } +is_file_or_link() { + # -e / -f 坏软连接,返回 false + # -L 坏软连接,返回 true + [ -f "$1" ] || [ -L "$1" ] +} + +find_file_ignore_case() { + # 同时支持参数和管道 + local path + path=$({ if [ -n "$1" ]; then echo "$1"; else cat; fi; }) + + path=$(get_path_in_correct_case "$path") + if is_file_or_link "$path"; then + echo "$path" + else + warn "Can't find $path" >&2 + return 1 + fi +} + parse_inf_and_cp_driever() { local inf=$1 local dst=$2