core: 提前验证 dd / windows 参数

This commit is contained in:
bin456789 2023-10-22 16:43:34 +08:00
parent 2c0b45fadf
commit fc3d82ab16
No known key found for this signature in database
GPG Key ID: EE301B386DE6C11B

View File

@ -420,23 +420,12 @@ setos() {
} }
setos_windows() { setos_windows() {
if [ -z "$iso" ] || [ -z "$image_name" ]; then
error_and_exit "Install Windows need --iso --image-name"
fi
# 防止常见错误
# --image-name 肯定大于等于3个单词
if [ "$(echo "$image_name" | wc -w)" -lt 3 ]; then
error_and_exit "--image-name wrong."
fi
eval "${step}_iso='$iso'" eval "${step}_iso='$iso'"
eval "${step}_image_name='$image_name'" eval "${step}_image_name='$image_name'"
} }
# shellcheck disable=SC2154 # shellcheck disable=SC2154
setos_dd() { setos_dd() {
if [ -z "$img" ]; then
error_and_exit "dd need --img"
fi
eval "${step}_img='$img'" eval "${step}_img='$img'"
eval "${step}_img_type='$img_type'" eval "${step}_img_type='$img_type'"
} }
@ -536,7 +525,11 @@ is_distro_like_redhat() {
} }
# 检查是否为正确的系统名 # 检查是否为正确的系统名
verify_os_string() { verify_os_name() {
if [ -z "$*" ]; then
usage_and_exit
fi
for os in \ for os in \
'centos 7|8|9' \ 'centos 7|8|9' \
'alma 8|9' \ 'alma 8|9' \
@ -575,6 +568,23 @@ verify_os_string() {
usage_and_exit usage_and_exit
} }
verify_os_args() {
case "$distro" in
dd) [ -n "$img" ] || error_and_exit "dd need --img" ;;
windows)
if [ -z "$iso" ] || [ -z "$image_name" ]; then
error_and_exit "Install Windows need --iso and --image-name"
fi
# 防止常见错误
# --image-name 肯定大于等于3个单词
if [ "$(echo "$image_name" | wc -w)" -lt 3 ] ||
[[ "$(to_lower <<<"$image_name")" != windows* ]]; then
error_and_exit "--image-name wrong."
fi
;;
esac
}
get_cmd_path() { get_cmd_path() {
# arch 云镜像不带 which # arch 云镜像不带 which
# command -v 包括脚本里面的方法 # command -v 包括脚本里面的方法
@ -896,6 +906,12 @@ done
# 不支持容器虚拟化 # 不支持容器虚拟化
assert_not_in_container assert_not_in_container
# 检查目标系统名
verify_os_name "$@"
# 检查必须的参数
verify_os_args
# win系统盘 # win系统盘
if is_in_windows; then if is_in_windows; then
c=$(echo $SYSTEMDRIVE | cut -c1) c=$(echo $SYSTEMDRIVE | cut -c1)