mirror of
https://github.com/bin456789/reinstall.git
synced 2025-03-19 05:39:31 +08:00
提前测试iso/dd镜像是否有效
This commit is contained in:
parent
1b8fe2637f
commit
17fc7af9a8
35
reinstall.sh
35
reinstall.sh
@ -7,6 +7,11 @@ usage_and_exit() {
|
|||||||
exit 1
|
exit 1
|
||||||
}
|
}
|
||||||
|
|
||||||
|
error_and_exit() {
|
||||||
|
echo "Error: $1"
|
||||||
|
exit 1
|
||||||
|
}
|
||||||
|
|
||||||
is_in_china() {
|
is_in_china() {
|
||||||
if [ -z $_is_in_china ]; then
|
if [ -z $_is_in_china ]; then
|
||||||
# https://geoip.ubuntu.com/lookup
|
# https://geoip.ubuntu.com/lookup
|
||||||
@ -16,6 +21,29 @@ is_in_china() {
|
|||||||
return $_is_in_china
|
return $_is_in_china
|
||||||
}
|
}
|
||||||
|
|
||||||
|
test_url() {
|
||||||
|
url=$1
|
||||||
|
expect_type=$2
|
||||||
|
tmp_file=/tmp/reinstall-img-test
|
||||||
|
install_pkg file
|
||||||
|
|
||||||
|
http_code=$(curl -Ls -r 0-1048576 -w "%{http_code}" -o $tmp_file $url)
|
||||||
|
if [ "$http_code" != 200 ] && [ "$http_code" != 206 ]; then
|
||||||
|
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
|
||||||
|
|
||||||
|
if ! echo $expect_type | grep -wo "$img_type"; then
|
||||||
|
error_and_exit "$url $mime not supported"
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
setos() {
|
setos() {
|
||||||
local step=$1
|
local step=$1
|
||||||
local distro=$2
|
local distro=$2
|
||||||
@ -83,7 +111,9 @@ setos() {
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
filename=$(curl $mirror | grep -oP "ubuntu-$releasever.*?-live-server-$basearch_alt.iso" | head -1)
|
filename=$(curl $mirror | grep -oP "ubuntu-$releasever.*?-live-server-$basearch_alt.iso" | head -1)
|
||||||
eval ${step}_iso=$mirror$filename
|
iso=$mirror$filename
|
||||||
|
test_url $iso iso
|
||||||
|
eval ${step}_iso=$iso
|
||||||
eval ${step}_ks=$confhome/user-data
|
eval ${step}_ks=$confhome/user-data
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -92,6 +122,7 @@ setos() {
|
|||||||
echo "Install Windows need --iso --image-name"
|
echo "Install Windows need --iso --image-name"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
test_url $iso iso
|
||||||
eval "${step}_iso='$iso'"
|
eval "${step}_iso='$iso'"
|
||||||
eval "${step}_image_name='$image_name'"
|
eval "${step}_image_name='$image_name'"
|
||||||
}
|
}
|
||||||
@ -101,7 +132,9 @@ setos() {
|
|||||||
echo "dd need --ddimg"
|
echo "dd need --ddimg"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
test_url $ddimg 'xz|gz'
|
||||||
eval "${step}_ddimg='$ddimg'"
|
eval "${step}_ddimg='$ddimg'"
|
||||||
|
eval "${step}_ddimg_type='$img_type'"
|
||||||
}
|
}
|
||||||
|
|
||||||
setos_redhat() {
|
setos_redhat() {
|
||||||
|
3
trans.sh
3
trans.sh
@ -91,8 +91,7 @@ if [ "$distro" = "alpine" ]; then
|
|||||||
exec reboot
|
exec reboot
|
||||||
|
|
||||||
elif [ "$distro" = "dd" ]; then
|
elif [ "$distro" = "dd" ]; then
|
||||||
filetype=$(echo $ddimg | awk -F. '{print $NF}')
|
case "$ddimg_type" in
|
||||||
case "$filetype" in
|
|
||||||
gz) prog=gzip ;;
|
gz) prog=gzip ;;
|
||||||
xz) prog=xz ;;
|
xz) prog=xz ;;
|
||||||
esac
|
esac
|
||||||
|
Loading…
x
Reference in New Issue
Block a user