From a66cbdfb41adcfc6d75367e4371482ff245c657e Mon Sep 17 00:00:00 2001 From: bin456789 Date: Mon, 5 Jun 2023 19:50:21 +0800 Subject: [PATCH] =?UTF-8?q?dd:=20=E4=B8=8D=E4=BD=BF=E7=94=A8=20mime=20?= =?UTF-8?q?=E5=88=A4=E6=96=ADdd=E9=95=9C=E5=83=8F=E6=A0=BC=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- reinstall.sh | 22 +++++++++++++--------- trans.sh | 2 +- 2 files changed, 14 insertions(+), 10 deletions(-) diff --git a/reinstall.sh b/reinstall.sh index 8305fb9..c60e22c 100644 --- a/reinstall.sh +++ b/reinstall.sh @@ -24,6 +24,8 @@ is_in_china() { test_url() { url=$1 expect_type=$2 + var_to_eval=$3 + tmp_file=/tmp/reinstall-img-test install_pkg file @@ -32,15 +34,16 @@ test_url() { error_and_exit "$url not accessible" fi - mime=$(file -ib $tmp_file | cut -d';' -f1 | cut -d'/' -f2) - case $mime in - gzip) img_type=gz ;; - x-xz) img_type=xz ;; - x-iso9660-image) img_type=iso ;; - esac + # gzip的mime有很多种写法 + # centos7中显示为 x-gzip,在其他系统中显示为 gzip,可能还有其他 + # 所以不用mime判断 + # https://www.digipres.org/formats/sources/tika/formats/#application/gzip - if ! echo $expect_type | grep -wo "$img_type"; then - error_and_exit "$url $mime not supported" + real_type=$(file -b $tmp_file | cut -d' ' -f1 | tr '[:upper:]' '[:lower:]') + [ -n "$var_to_eval" ] && eval $var_to_eval=$real_type + + if ! echo $expect_type | grep -wo "$real_type"; then + error_and_exit "$url expect: $expect_type. real: $real_type, " fi } @@ -127,12 +130,13 @@ setos() { eval "${step}_image_name='$image_name'" } + # shellcheck disable=SC2154 setos_dd() { if [ -z "$img" ]; then echo "dd need --img" exit 1 fi - test_url $img 'xz|gz' + test_url $img 'xz|gzip' img_type eval "${step}_img='$img'" eval "${step}_img_type='$img_type'" } diff --git a/trans.sh b/trans.sh index 0378e07..d23f148 100644 --- a/trans.sh +++ b/trans.sh @@ -92,7 +92,7 @@ if [ "$distro" = "alpine" ]; then elif [ "$distro" = "dd" ]; then case "$img_type" in - gz) prog=gzip ;; + gzip) prog=gzip ;; xz) prog=xz ;; esac