update hy2.sh

This commit is contained in:
2026-03-19 16:06:36 +08:00
parent 7cd9d5c415
commit 7786a3e8ac

20
hy2.sh
View File

@@ -32,26 +32,12 @@ prompt_nonempty() {
local prompt="$1" local prompt="$1"
local value="" local value=""
while true; do while true; do
read -r -p "$prompt" value read -r -p "$prompt" value < /dev/tty
if [[ -n "${value// }" ]]; then if [[ -n "${value// }" ]]; then
printf '%s' "$value" printf '%s' "$value"
return 0 return 0
fi fi
yellow "输入不能为空,请重新输入。" yellow "输入不能为空,请重新输入。" >&2
done
}
prompt_secret_nonempty() {
local prompt="$1"
local value=""
while true; do
read -r -s -p "$prompt" value
echo
if [[ -n "${value// }" ]]; then
printf '%s' "$value"
return 0
fi
yellow "输入不能为空,请重新输入。"
done done
} }
@@ -505,7 +491,7 @@ main() {
subdomain="${subdomain:-$default_subdomain}" subdomain="${subdomain:-$default_subdomain}"
subdomain="$(printf '%s' "$subdomain" | tr 'A-Z' 'a-z' | tr -cd 'a-z0-9-')" subdomain="$(printf '%s' "$subdomain" | tr 'A-Z' 'a-z' | tr -cd 'a-z0-9-')"
CF_API_TOKEN="$(prompt_secret_nonempty '请输入 Cloudflare API Token: ')" CF_API_TOKEN="$(prompt_nonempty '请输入 Cloudflare API Token: ')"
export CF_API_TOKEN export CF_API_TOKEN
password="$(generate_password)" password="$(generate_password)"