From 1a9c6bece4e9da6cc09c9ded62dc3dc1e941f9d7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9C=9D=E4=BB=A3=E5=B0=BE?= Date: Thu, 19 Mar 2026 15:39:51 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0=20hy2.sh?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- hy2.sh | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/hy2.sh b/hy2.sh index d62d247..1bb2bb8 100644 --- a/hy2.sh +++ b/hy2.sh @@ -24,6 +24,10 @@ require_cmd() { } } +random_subdomain_prefix() { + openssl rand -hex 8 | cut -c1-8 +} + prompt_nonempty() { local prompt="$1" local value="" @@ -444,7 +448,12 @@ main() { email="$(prompt_nonempty '请输入 ACME 邮箱: ')" zone="$(prompt_nonempty '请输入 Cloudflare Zone(例如 example.com): ')" - subdomain="$(prompt_nonempty '请输入要创建的子域名前缀(例如 hy2): ')" + + default_subdomain="$(random_subdomain_prefix)" + read -r -p "请输入要创建的子域名前缀(例如 hy2,直接回车使用默认值 ${default_subdomain}): " subdomain + subdomain="${subdomain:-$default_subdomain}" + subdomain="$(printf '%s' "$subdomain" | tr 'A-Z' 'a-z' | tr -cd 'a-z0-9-')" + CF_API_TOKEN="$(prompt_nonempty '请输入 Cloudflare API Token: ')" export CF_API_TOKEN