mirror of
https://github.com/bin456789/reinstall.git
synced 2025-01-19 04:49:13 +08:00
core: 完善文件类型检查
This commit is contained in:
parent
785c813ea8
commit
9fa03c14bd
72
reinstall.sh
72
reinstall.sh
@ -234,7 +234,7 @@ test_url_grace() {
|
|||||||
test_url_real() {
|
test_url_real() {
|
||||||
grace=$1
|
grace=$1
|
||||||
url=$2
|
url=$2
|
||||||
expect_type_combo=$3
|
expect_types=$3
|
||||||
var_to_eval=$4
|
var_to_eval=$4
|
||||||
info test url
|
info test url
|
||||||
|
|
||||||
@ -269,56 +269,74 @@ test_url_real() {
|
|||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
|
|
||||||
if [ -n "$expect_type_combo" ]; then
|
# 如果要检查文件类型
|
||||||
|
if [ -n "$expect_types" ]; then
|
||||||
|
install_pkg file
|
||||||
|
real_type=$(file_enhanced $tmp_file)
|
||||||
|
echo "$real_type"
|
||||||
|
|
||||||
|
# 期待值没有.表示要只需判断外侧
|
||||||
|
if ! grep -Fq . <<<"$expect_types"; then
|
||||||
|
real_type=$(echo "$real_type" | cut -d. -f2-)
|
||||||
|
fi
|
||||||
|
|
||||||
|
# 检查
|
||||||
|
if ! grep -Foq "|$real_type|" <<<"|$expect_types|"; then
|
||||||
|
failed "$url
|
||||||
|
expected: $expect_types
|
||||||
|
actually: $real_type"
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
|
# 如果要设置变量
|
||||||
|
if [ -n "$var_to_eval" ]; then
|
||||||
|
IFS=. read -r "${var_to_eval?}" "${var_to_eval}_warp" <<<"$real_type"
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
fix_file_type() {
|
fix_file_type() {
|
||||||
# gzip的mime有很多种写法
|
# gzip的mime有很多种写法
|
||||||
# centos7中显示为 x-gzip,在其他系统中显示为 gzip,可能还有其他
|
# centos7中显示为 x-gzip,在其他系统中显示为 gzip,可能还有其他
|
||||||
# 所以不用mime判断
|
# 所以不用mime判断
|
||||||
# https://www.digipres.org/formats/sources/tika/formats/#application/gzip
|
# https://www.digipres.org/formats/sources/tika/formats/#application/gzip
|
||||||
|
|
||||||
|
# --extension 不靠谱
|
||||||
|
# file -b /reinstall-tmp/img-test --mime-type
|
||||||
|
# application/x-qemu-disk
|
||||||
|
# file -b /reinstall-tmp/img-test --extension
|
||||||
|
# ???
|
||||||
|
|
||||||
# 有些 file 版本输出的是 # ISO 9660 CD-ROM filesystem data ,要去掉开头的井号
|
# 有些 file 版本输出的是 # ISO 9660 CD-ROM filesystem data ,要去掉开头的井号
|
||||||
|
|
||||||
# 下面两种都是 raw
|
# 下面两种都是 raw
|
||||||
# DOS/MBR boot sector
|
# DOS/MBR boot sector
|
||||||
# x86 boot sector; partition 1: ...
|
# x86 boot sector; partition 1: ...
|
||||||
sed 's/^# //' | cut -d' ' -f1 | to_lower |
|
|
||||||
|
sed 's/^# //' | awk '{print $1}' | to_lower |
|
||||||
sed -e 's,dos/mbr,raw,' -e 's,x86,raw,'
|
sed -e 's,dos/mbr,raw,' -e 's,x86,raw,'
|
||||||
}
|
}
|
||||||
|
|
||||||
file_enhanced() {
|
file_enhanced() {
|
||||||
file_type=$(file -b $tmp_file | fix_file_type)
|
local file=$1
|
||||||
if [ "$file_type" = "xz" ] || [ "$file_type" = "gzip" ]; then
|
local outside inside
|
||||||
|
|
||||||
|
outside=$(file -b $file | fix_file_type)
|
||||||
|
|
||||||
|
if [ "$outside" = "xz" ] || [ "$outside" = "gzip" ]; then
|
||||||
# 要安装 xz 或者 gzip,不然会报错
|
# 要安装 xz 或者 gzip,不然会报错
|
||||||
# ERROR:[xz: Wait failed, No child process]
|
# ERROR:[xz: Wait failed, No child process]
|
||||||
install_pkg "$file_type"
|
install_pkg "$outside"
|
||||||
|
|
||||||
# 加 if 是为了避免以下情况(外面是xz,但是识别不到里面的东西,即使装了xz),
|
# 加 if 是为了避免以下情况(外面是xz,但是识别不到里面的东西,即使装了xz),
|
||||||
# 即使 file 报错返回值也是 0
|
# 即使 file 报错返回值也是 0
|
||||||
# [root@localhost ~]# file -bZ /reinstall-tmp/img-test
|
# [root@localhost ~]# file -bZ /reinstall-tmp/img-test
|
||||||
# ERROR:[xz: Unexpected end of input]
|
# ERROR:[xz: Unexpected end of input]
|
||||||
if file_type_in="$(file -bZ $tmp_file | fix_file_type)" &&
|
if inside="$(file -bZ $file | fix_file_type)" && ! grep -iq "^Error" <<<"$inside"; then
|
||||||
! grep -iq "^Error" <<<"$file_type_in"; then
|
echo "$inside.$outside"
|
||||||
file_type="$file_type_in.$file_type"
|
return
|
||||||
fi
|
|
||||||
fi
|
|
||||||
echo "$file_type"
|
|
||||||
}
|
|
||||||
|
|
||||||
install_pkg file
|
|
||||||
real_type_combo=$(file_enhanced $tmp_file)
|
|
||||||
echo "$real_type_combo"
|
|
||||||
|
|
||||||
if ! grep -Foq "|$real_type_combo|" <<<"|$expect_type_combo|"; then
|
|
||||||
failed "$url expected: $expect_type_combo. actual: $real_type_combo."
|
|
||||||
fi
|
|
||||||
|
|
||||||
IFS=. read -r real_type real_type_warp <<<"$real_type_combo"
|
|
||||||
|
|
||||||
if [ -n "$var_to_eval" ]; then
|
|
||||||
eval "$var_to_eval=$real_type"
|
|
||||||
eval "$var_to_eval""_warp=$real_type_warp"
|
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
echo "$outside"
|
||||||
}
|
}
|
||||||
|
|
||||||
add_community_repo_for_alpine() {
|
add_community_repo_for_alpine() {
|
||||||
|
6
trans.sh
6
trans.sh
@ -3700,7 +3700,9 @@ install_windows() {
|
|||||||
esac
|
esac
|
||||||
# 排除 $PLUGINSDIR $TEMP
|
# 排除 $PLUGINSDIR $TEMP
|
||||||
exclude='$*'
|
exclude='$*'
|
||||||
7z x $drv/Citrix_xensetup.exe -o$drv/aws/ -ao$override -x!$exclude
|
7z x $drv/Citrix_xensetup.exe -o$drv/xen/ -ao$override -x!$exclude
|
||||||
|
|
||||||
|
cp_drivers $drv/xen
|
||||||
}
|
}
|
||||||
|
|
||||||
# aws xen
|
# aws xen
|
||||||
@ -3743,6 +3745,8 @@ install_windows() {
|
|||||||
download https://xenbits.xenproject.org/pvdrivers/win/$part.tar $drv/$part.tar
|
download https://xenbits.xenproject.org/pvdrivers/win/$part.tar $drv/$part.tar
|
||||||
tar -xf $drv/$part.tar -C $drv/xen/
|
tar -xf $drv/$part.tar -C $drv/xen/
|
||||||
done
|
done
|
||||||
|
|
||||||
|
cp_drivers $drv/xen
|
||||||
}
|
}
|
||||||
|
|
||||||
# kvm
|
# kvm
|
||||||
|
Loading…
x
Reference in New Issue
Block a user