mirror of
https://github.com/bin456789/reinstall.git
synced 2025-01-19 04:49:13 +08:00
dd: 不使用 mime 判断dd镜像格式
This commit is contained in:
parent
ecc3134479
commit
a66cbdfb41
22
reinstall.sh
22
reinstall.sh
@ -24,6 +24,8 @@ is_in_china() {
|
|||||||
test_url() {
|
test_url() {
|
||||||
url=$1
|
url=$1
|
||||||
expect_type=$2
|
expect_type=$2
|
||||||
|
var_to_eval=$3
|
||||||
|
|
||||||
tmp_file=/tmp/reinstall-img-test
|
tmp_file=/tmp/reinstall-img-test
|
||||||
install_pkg file
|
install_pkg file
|
||||||
|
|
||||||
@ -32,15 +34,16 @@ test_url() {
|
|||||||
error_and_exit "$url not accessible"
|
error_and_exit "$url not accessible"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
mime=$(file -ib $tmp_file | cut -d';' -f1 | cut -d'/' -f2)
|
# gzip的mime有很多种写法
|
||||||
case $mime in
|
# centos7中显示为 x-gzip,在其他系统中显示为 gzip,可能还有其他
|
||||||
gzip) img_type=gz ;;
|
# 所以不用mime判断
|
||||||
x-xz) img_type=xz ;;
|
# https://www.digipres.org/formats/sources/tika/formats/#application/gzip
|
||||||
x-iso9660-image) img_type=iso ;;
|
|
||||||
esac
|
|
||||||
|
|
||||||
if ! echo $expect_type | grep -wo "$img_type"; then
|
real_type=$(file -b $tmp_file | cut -d' ' -f1 | tr '[:upper:]' '[:lower:]')
|
||||||
error_and_exit "$url $mime not supported"
|
[ -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
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -127,12 +130,13 @@ setos() {
|
|||||||
eval "${step}_image_name='$image_name'"
|
eval "${step}_image_name='$image_name'"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# shellcheck disable=SC2154
|
||||||
setos_dd() {
|
setos_dd() {
|
||||||
if [ -z "$img" ]; then
|
if [ -z "$img" ]; then
|
||||||
echo "dd need --img"
|
echo "dd need --img"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
test_url $img 'xz|gz'
|
test_url $img 'xz|gzip' img_type
|
||||||
eval "${step}_img='$img'"
|
eval "${step}_img='$img'"
|
||||||
eval "${step}_img_type='$img_type'"
|
eval "${step}_img_type='$img_type'"
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user