init
This commit is contained in:
@@ -0,0 +1,41 @@
|
||||
#!/bin/bash
|
||||
# core/validator.sh - unified option validation.
|
||||
#
|
||||
# The primary validation still happens inline inside parse_arguments and
|
||||
# show_menu (migrated verbatim, to preserve the exact error messages and the
|
||||
# "already installed" guards). validate_options() is a final, idempotent
|
||||
# safety net: it re-checks only options that are still set, using the same
|
||||
# regexes and messages, so it can never change a valid install path.
|
||||
|
||||
# Validate a single value against an ERE.
|
||||
# $1 = value, $2 = regex, $3 = error message
|
||||
is_valid() {
|
||||
local val="$1" regex="$2" msg="$3"
|
||||
if [[ "${val}" =~ ${regex} ]]; then
|
||||
return 0
|
||||
fi
|
||||
echo "${CWARNING}${msg}${CEND}"
|
||||
return 1
|
||||
}
|
||||
|
||||
# Re-validate options that are still set after parse/menu. Empty options
|
||||
# (e.g. unset because already installed) are skipped.
|
||||
validate_options() {
|
||||
_check_opt() {
|
||||
# $1 = value, $2 = regex, $3 = message
|
||||
[ -z "$1" ] && return 0
|
||||
is_valid "$1" "$2" "$3" || error_exit "$3"
|
||||
}
|
||||
|
||||
_check_opt "${nginx_option}" '^[1-2]$' "nginx_option input error! Please only input number 1~2"
|
||||
_check_opt "${php_option}" '^[1-3]$' "php_option input error! Please only input number 1~3"
|
||||
_check_opt "${mphp_ver}" '^(74|80|81)$' "mphp_ver input error! Please only input number 74/80/81"
|
||||
# On Ubuntu 24+ only PHP 8.x is supported; PHP 7.4 (and the mphp 7.4 build)
|
||||
# fails to compile against the newer system libicu.
|
||||
if [[ "${Family}" == "ubuntu" ]] && [ "${Ubuntu_ver:-0}" -ge 24 ]; then
|
||||
[ "${php_option}" == '1' ] && error_exit "PHP 7.4 is not supported on Ubuntu ${Ubuntu_ver}+, please choose PHP 8.x (option 2 or 3)"
|
||||
[ "${mphp_ver}" == '74' ] && error_exit "mphp 7.4 is not supported on Ubuntu ${Ubuntu_ver}+, please choose 80 or 81"
|
||||
fi
|
||||
_check_opt "${db_option}" '^[1-9]$' "db_option input error! Please only input number 1~9"
|
||||
_check_opt "${dbinstallmethod}" '^[1-2]$' "dbinstallmethod input error! Please only input number 1~2"
|
||||
}
|
||||
Reference in New Issue
Block a user