Skip to content

Commit 1d5da87

Browse files
committed
自动模式 (-y) 下的默认策略
当开启自动确认后,脚本会执行以下逻辑: * IP/Hostname:自动填入检测到的公网 IP。 * 目录覆盖:如果目录存在,自动备份并覆盖。 * 密码生成: * 新环境:自动生成强随机密码。 * 旧环境(检测到已有数据):自动选择“保留旧密码”(防止数据库连不上)。 * SSL:自动修正证书路径。 ✦ 所有修改已就绪。
1 parent 3462628 commit 1d5da87

File tree

2 files changed

+54
-7
lines changed

2 files changed

+54
-7
lines changed

download-and-install.sh

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,8 +141,22 @@ if [ -f "$DEPLOY_SCRIPT" ]; then
141141
echo ""
142142
# Switch to directory before execution to ensure relative paths work
143143
cd "$INSTALL_DIR"
144+
145+
# If PROJECT env var is set, append it to arguments
146+
if [ -n "$PROJECT" ]; then
147+
echo -e "${BLUE}Project selection detected via env: PROJECT=$PROJECT${NC}"
148+
set -- "$@" "--project" "$PROJECT"
149+
fi
150+
151+
# If AUTO_YES env var is set, append it to arguments
152+
if [ -n "$AUTO_YES" ]; then
153+
echo -e "${BLUE}Auto-confirm detected via env: AUTO_YES=$AUTO_YES${NC}"
154+
set -- "$@" "--yes"
155+
fi
156+
157+
echo -e "${BLUE}Executing: ./setup-services.sh $@${NC}"
144158
# Ensure stdin is attached to terminal for interactive input
145-
exec ./setup-services.sh < /dev/tty
159+
exec ./setup-services.sh "$@" < /dev/tty
146160
else
147161
echo -e "${RED}Critical Error: setup-services.sh not found in downloaded repository!${NC}"
148162
exit 1

setup-services.sh

Lines changed: 39 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,11 @@ while [[ $# -gt 0 ]]; do
5050
shift # past argument
5151
shift # past value
5252
;;
53+
-y|--yes)
54+
AUTO_YES="true"
55+
echo -e "${YELLOW}Non-interactive mode enabled (Auto-Yes).${NC}"
56+
shift # past argument
57+
;;
5358
*)
5459
echo -e "${RED}Unknown option: $1${NC}"
5560
echo -e "Usage: ./setup-services.sh [-p|--project <name>]"
@@ -94,7 +99,12 @@ echo -e "${BLUE}Installing to $TARGET_DIR...${NC}"
9499

95100
if [ -d "$TARGET_DIR" ]; then
96101
echo -e "${YELLOW}Directory $TARGET_DIR already exists.${NC}"
97-
read -p "Backup and overwrite? (y/N) " confirm
102+
if [ "$AUTO_YES" == "true" ]; then
103+
confirm="y"
104+
echo -e "${BLUE}Auto-confirming backup and overwrite.${NC}"
105+
else
106+
read -p "Backup and overwrite? (y/N) " confirm
107+
fi
98108
if [[ "$confirm" != "y" && "$confirm" != "Y" ]]; then
99109
echo "Aborting."
100110
exit 0
@@ -184,7 +194,11 @@ else
184194
# Always suggest the detected IP (or empty if detection failed)
185195
IP_DEFAULT="$DETECTED_IP"
186196

187-
read -p "Enter Server Public IP [${IP_DEFAULT}]: " INPUT_IP
197+
if [ "$AUTO_YES" == "true" ]; then
198+
INPUT_IP=$IP_DEFAULT
199+
else
200+
read -p "Enter Server Public IP [${IP_DEFAULT}]: " INPUT_IP
201+
fi
188202
INPUT_IP=${INPUT_IP:-$IP_DEFAULT}
189203

190204
COMMENT_IP="User-defined"
@@ -198,7 +212,11 @@ else
198212
# Logic: Default to the IP address entered above
199213
HOST_DEFAULT=${CURRENT_HOST:-$INPUT_IP}
200214

201-
read -p "Enter Server Hostname (e.g., google.com) [${HOST_DEFAULT}]: " INPUT_HOST
215+
if [ "$AUTO_YES" == "true" ]; then
216+
INPUT_HOST=$HOST_DEFAULT
217+
else
218+
read -p "Enter Server Hostname (e.g., google.com) [${HOST_DEFAULT}]: " INPUT_HOST
219+
fi
202220
INPUT_HOST=${INPUT_HOST:-$HOST_DEFAULT}
203221

204222
COMMENT_HOST="User-defined"
@@ -229,7 +247,12 @@ else
229247
echo -e " 1) Keep existing passwords (Recommended if preserving data)"
230248
echo -e " 2) Rename old data dir & Generate new passwords (WARNING: Hides old data)"
231249
echo -e " 3) Abort deployment"
232-
read -p "Select option [1]: " DATA_OPT
250+
if [ "$AUTO_YES" == "true" ]; then
251+
DATA_OPT=1
252+
echo -e "${BLUE}Auto-selecting Option 1 (Keep existing passwords).${NC}"
253+
else
254+
read -p "Select option [1]: " DATA_OPT
255+
fi
233256
DATA_OPT=${DATA_OPT:-1}
234257

235258
case $DATA_OPT in
@@ -257,7 +280,12 @@ else
257280
esac
258281
else
259282
# Data dir empty or doesn't exist, safe to prompt for generation
260-
read -p "Generate new random passwords for key services? (Y/n) " GEN_PASS
283+
if [ "$AUTO_YES" == "true" ]; then
284+
GEN_PASS="y"
285+
echo -e "${BLUE}Auto-confirming password generation.${NC}"
286+
else
287+
read -p "Generate new random passwords for key services? (Y/n) " GEN_PASS
288+
fi
261289
if [[ "$GEN_PASS" != "n" && "$GEN_PASS" != "N" ]]; then
262290
SHOULD_GENERATE_PASS="y"
263291
fi
@@ -281,7 +309,12 @@ else
281309
# Heuristic: if ssl folder exists, and current config is placeholder or empty, prompt to update
282310
if [[ "$SSL_VAL" == *"placeholder"* ]] || [ -z "$SSL_VAL" ]; then
283311
echo -e "${YELLOW}Local SSL certificates detected in ./ssl directory.${NC}"
284-
read -p "Update SSL_CERTIFICATE path to local file? (Y/n) " UPD_SSL
312+
if [ "$AUTO_YES" == "true" ]; then
313+
UPD_SSL="y"
314+
echo -e "${BLUE}Auto-confirming SSL path update.${NC}"
315+
else
316+
read -p "Update SSL_CERTIFICATE path to local file? (Y/n) " UPD_SSL
317+
fi
285318
if [[ "$UPD_SSL" != "n" && "$UPD_SSL" != "N" ]]; then
286319
# Find the crt file
287320
CRT_FILE=$(find "$TARGET_DIR/ssl" -name "*.crt" | head -n 1)

0 commit comments

Comments
 (0)