Skip to content

Commit df43e6d

Browse files
authored
feat(一键部署): 优化流程,增加可选项 (#52)
* feat: verify docker service status after install/detection * 密码修改提醒 * 项目目录强制使用/home/docker-compose * 支持 ./setup-services.sh --project bus-https方法部署项目 * 修改env模版 * 自动模式 (-y) 下的默认策略 当开启自动确认后,脚本会执行以下逻辑: * IP/Hostname:自动填入检测到的公网 IP。 * 目录覆盖:如果目录存在,自动备份并覆盖。 * 密码生成: * 新环境:自动生成强随机密码。 * 旧环境(检测到已有数据):自动选择“保留旧密码”(防止数据库连不上)。 * SSL:自动修正证书路径。 ✦ 所有修改已就绪。 * 对调顺序 * 增加ffmpeg和ifv转码下载选项
1 parent 928dc87 commit df43e6d

File tree

4 files changed

+204
-23
lines changed

4 files changed

+204
-23
lines changed

download-and-install.sh

Lines changed: 42 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -97,14 +97,39 @@ else
9797
fi
9898

9999
# 4. Docker Check & Install
100+
check_docker_status() {
101+
if systemctl is-active --quiet docker; then
102+
return 0
103+
else
104+
echo -e "${BLUE}Starting Docker service...${NC}"
105+
systemctl start docker
106+
if systemctl is-active --quiet docker; then
107+
return 0
108+
fi
109+
fi
110+
return 1
111+
}
112+
100113
if ! command -v docker &> /dev/null; then
101114
echo -e "${BLUE}Docker not found. Installing via official script...${NC}"
102115
curl -fsSL https://get.docker.com | bash
103116
systemctl enable docker
104-
systemctl start docker
105-
echo -e "${GREEN}Docker installed.${NC}"
117+
118+
if check_docker_status; then
119+
echo -e "${GREEN}Docker installed and started successfully.${NC}"
120+
else
121+
echo -e "${RED}Error: Docker installed but failed to start.${NC}"
122+
echo -e "${YELLOW}Please check logs: journalctl -xeu docker.service${NC}"
123+
echo -e "${YELLOW}You may need to install Docker manually.${NC}"
124+
exit 1
125+
fi
106126
else
107127
echo -e "${GREEN}Docker detected.${NC}"
128+
if ! check_docker_status; then
129+
echo -e "${RED}Error: Docker is installed but not running and failed to start.${NC}"
130+
echo -e "${YELLOW}Please check logs: journalctl -xeu docker.service${NC}"
131+
exit 1
132+
fi
108133
fi
109134

110135
# 5. Handover to setup-services.sh
@@ -116,8 +141,22 @@ if [ -f "$DEPLOY_SCRIPT" ]; then
116141
echo ""
117142
# Switch to directory before execution to ensure relative paths work
118143
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}"
119158
# Ensure stdin is attached to terminal for interactive input
120-
exec ./setup-services.sh < /dev/tty
159+
exec ./setup-services.sh "$@" < /dev/tty
121160
else
122161
echo -e "${RED}Critical Error: setup-services.sh not found in downloaded repository!${NC}"
123162
exit 1

examples/track-http/.env

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,15 @@
1+
# Server information, You must fill in the information accurately.
12
SERVER_IP_PUBLIC='58.82.168.197'
23
SERVER_HOSTNAME='th-track.transcodegroup.cn'
34

5+
# Custom Port Info, recommended use default. 9000~9100, 443, 80
6+
WEB_PORT_HTTP=80
7+
8+
# Initial password. Recommended use random password; do not change it after started the service.
49
MYSQL_PASSWORD='12345678'
510
REDIS_PASSWORD='12345678'
611
MONGODB_PASSWORD='12345678'
712
RABBITMQ_PASSWORD='12345678'
813
MINIO_PASSWORD='12345678'
914
MAIL_PASSWORD='12345678'
15+

examples/track-https/.env

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,20 @@
1+
# Server information, You must fill in the information accurately.
12
SERVER_HOSTNAME='vpn.transbustransportes.com.br'
23
SERVER_IP_PUBLIC='200.155.137.26'
4+
35
# The certificate can be set to placeholder first to ensure compose starts, and then change it to the actual certificate path after applying for the certificate
46
SSL_CERTIFICATE=/home/docker/nginx/ssl/placeholder
57
# SSL_CERTIFICATE=/home/docker-compose/ssl/certificate
68

9+
# Custom Port Info, recommended use default. 9000~9100, 443, 80
10+
WEB_PORT_HTTP=80
11+
WEB_PORT_HTTPS=443
12+
13+
# Initial password. Recommended use random password; do not change it after started the service.
714
MYSQL_PASSWORD='12345678'
815
REDIS_PASSWORD='12345678'
916
MONGODB_PASSWORD='12345678'
1017
RABBITMQ_PASSWORD='12345678'
1118
MINIO_PASSWORD='12345678'
1219
MAIL_PASSWORD='12345678'
20+

setup-services.sh

Lines changed: 148 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ echo -e "${BLUE} Docker Compose One-Click Deployment ${NC}"
2626
echo -e "${BLUE}=================================================${NC}"
2727

2828
# 1. Select Deployment Example
29-
echo -e "${GREEN}Select a deployment scenario:${NC}"
3029
# List directories in examples/ excluding 'docker'
3130
if [ -d "examples" ]; then
3231
OPTIONS=($(ls -d examples/*/ | grep -v "examples/docker/" | xargs -n 1 basename))
@@ -40,29 +39,72 @@ if [ ${#OPTIONS[@]} -eq 0 ]; then
4039
exit 1
4140
fi
4241

43-
PS3="Enter choice number: "
44-
select OPT in "${OPTIONS[@]}"; do
45-
if [ -n "$OPT" ]; then
46-
SELECTED_EXAMPLE="$OPT"
47-
break
48-
else
49-
echo "Invalid selection."
50-
fi
42+
# Parse arguments manually since we are inside the script flow
43+
ARG_PROJECT=""
44+
45+
while [[ $# -gt 0 ]]; do
46+
key="$1"
47+
case $key in
48+
-p|--project)
49+
ARG_PROJECT="$2"
50+
shift # past argument
51+
shift # past value
52+
;;
53+
-y|--yes)
54+
AUTO_YES="true"
55+
echo -e "${YELLOW}Non-interactive mode enabled (Auto-Yes).${NC}"
56+
shift # past argument
57+
;;
58+
*)
59+
echo -e "${RED}Unknown option: $1${NC}"
60+
echo -e "Usage: ./setup-services.sh [-p|--project <name>]"
61+
exit 1
62+
;;
63+
esac
5164
done
5265

66+
# Logic to select example
67+
if [ -n "$ARG_PROJECT" ]; then
68+
for opt in "${OPTIONS[@]}"; do
69+
if [ "$opt" == "$ARG_PROJECT" ]; then
70+
SELECTED_EXAMPLE="$opt"
71+
echo -e "${GREEN}Project selected via argument: $SELECTED_EXAMPLE${NC}"
72+
break
73+
fi
74+
done
75+
if [ -z "$SELECTED_EXAMPLE" ]; then
76+
echo -e "${RED}Invalid project: $ARG_PROJECT${NC}"
77+
echo -e "Available options: ${OPTIONS[*]}"
78+
exit 1
79+
fi
80+
else
81+
echo -e "${GREEN}Select a deployment project:${NC}"
82+
PS3="Enter choice number: "
83+
select OPT in "${OPTIONS[@]}"; do
84+
if [ -n "$OPT" ]; then
85+
SELECTED_EXAMPLE="$OPT"
86+
break
87+
else
88+
echo "Invalid selection."
89+
fi
90+
done
91+
fi
92+
5393
echo -e "${GREEN}Selected: $SELECTED_EXAMPLE${NC}"
5494

5595
# 2. Prepare Target Directory
56-
echo -e "${GREEN}Hint: Press Enter to accept the [default] value.${NC}"
57-
read -p "Enter installation directory [${DEFAULT_TARGET_BASE}]: " TARGET_BASE
58-
TARGET_BASE=${TARGET_BASE:-$DEFAULT_TARGET_BASE}
59-
TARGET_DIR="$TARGET_BASE"
96+
TARGET_DIR="$DEFAULT_TARGET_BASE"
6097

6198
echo -e "${BLUE}Installing to $TARGET_DIR...${NC}"
6299

63100
if [ -d "$TARGET_DIR" ]; then
64101
echo -e "${YELLOW}Directory $TARGET_DIR already exists.${NC}"
65-
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
66108
if [[ "$confirm" != "y" && "$confirm" != "Y" ]]; then
67109
echo "Aborting."
68110
exit 0
@@ -152,7 +194,11 @@ else
152194
# Always suggest the detected IP (or empty if detection failed)
153195
IP_DEFAULT="$DETECTED_IP"
154196

155-
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
156202
INPUT_IP=${INPUT_IP:-$IP_DEFAULT}
157203

158204
COMMENT_IP="User-defined"
@@ -166,7 +212,11 @@ else
166212
# Logic: Default to the IP address entered above
167213
HOST_DEFAULT=${CURRENT_HOST:-$INPUT_IP}
168214

169-
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
170220
INPUT_HOST=${INPUT_HOST:-$HOST_DEFAULT}
171221

172222
COMMENT_HOST="User-defined"
@@ -197,7 +247,12 @@ else
197247
echo -e " 1) Keep existing passwords (Recommended if preserving data)"
198248
echo -e " 2) Rename old data dir & Generate new passwords (WARNING: Hides old data)"
199249
echo -e " 3) Abort deployment"
200-
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
201256
DATA_OPT=${DATA_OPT:-1}
202257

203258
case $DATA_OPT in
@@ -225,7 +280,12 @@ else
225280
esac
226281
else
227282
# Data dir empty or doesn't exist, safe to prompt for generation
228-
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
229289
if [[ "$GEN_PASS" != "n" && "$GEN_PASS" != "N" ]]; then
230290
SHOULD_GENERATE_PASS="y"
231291
fi
@@ -236,7 +296,7 @@ else
236296
# Check if variable exists in the file
237297
if grep -q "^$var=" "$TARGET_ENV"; then
238298
NEW_PASS=$(generate_password)
239-
set_env_val "$var" "$NEW_PASS" "Auto-generated random password"
299+
set_env_val "$var" "$NEW_PASS" "Auto-generated. DO NOT CHANGE after startup or services will break."
240300
echo "Updated $var with new random password."
241301
fi
242302
done
@@ -249,7 +309,12 @@ else
249309
# Heuristic: if ssl folder exists, and current config is placeholder or empty, prompt to update
250310
if [[ "$SSL_VAL" == *"placeholder"* ]] || [ -z "$SSL_VAL" ]; then
251311
echo -e "${YELLOW}Local SSL certificates detected in ./ssl directory.${NC}"
252-
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
253318
if [[ "$UPD_SSL" != "n" && "$UPD_SSL" != "N" ]]; then
254319
# Find the crt file
255320
CRT_FILE=$(find "$TARGET_DIR/ssl" -name "*.crt" | head -n 1)
@@ -269,6 +334,12 @@ fi
269334
echo -e "${GREEN}Deployment setup complete!${NC}"
270335
echo -e "Configuration file: ${YELLOW}$TARGET_ENV${NC}"
271336

337+
echo -e "\n${RED}!!! IMPORTANT CONFIGURATION WARNING !!!${NC}"
338+
echo -e "${YELLOW}Passwords have been auto-generated and synchronized.${NC}"
339+
echo -e "${YELLOW}DO NOT change them manually in the .env file after this point.${NC}"
340+
echo -e "${YELLOW}Changing them will break connections between services and databases.${NC}"
341+
echo -e "${RED}!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!${NC}"
342+
272343
# --- SSL Certificate Checklist ---
273344
SSL_CERT_VAL=$(get_env_val "SSL_CERTIFICATE")
274345
# Only show checklist if SSL var is set AND the selected example implies HTTPS usage
@@ -286,6 +357,63 @@ if [[ -n "$SSL_CERT_VAL" ]] && [[ "$SELECTED_EXAMPLE" == *"https"* || "$SELECTED
286357
echo -e "${YELLOW}=================================================${NC}"
287358
fi
288359

360+
# --- 5. Install Optional Tools (FFmpeg & ifv2mp4) ---
361+
echo -e "\n${BLUE}Optional Tools Installation (FFmpeg & ifv2mp4)${NC}"
362+
echo -e "These tools are recommended for video processing services (e.g. jtt808)."
363+
364+
if [ "$AUTO_YES" == "true" ]; then
365+
INSTALL_TOOLS="n"
366+
echo -e "${YELLOW}Skipping optional tools in non-interactive mode.${NC}"
367+
else
368+
read -p "Install video processing tools (FFmpeg, ifv2mp4)? (y/N) " INSTALL_TOOLS
369+
fi
370+
371+
if [[ "$INSTALL_TOOLS" == "y" || "$INSTALL_TOOLS" == "Y" ]]; then
372+
OPT_DIR="$TARGET_DIR/opt"
373+
mkdir -p "$OPT_DIR"
374+
375+
# 1. FFmpeg
376+
if [[ -f "$OPT_DIR/ffmpeg" && -f "$OPT_DIR/ffprobe" ]]; then
377+
echo -e "${GREEN}FFmpeg already exists in $OPT_DIR. Skipping download.${NC}"
378+
else
379+
echo -e "${BLUE}Installing FFmpeg...${NC}"
380+
curl -L -o "$OPT_DIR/ffmpeg.tar.xz" "https://johnvansickle.com/ffmpeg/releases/ffmpeg-release-amd64-static.tar.xz"
381+
382+
if [ -f "$OPT_DIR/ffmpeg.tar.xz" ]; then
383+
echo "Extracting FFmpeg..."
384+
tar -xf "$OPT_DIR/ffmpeg.tar.xz" -C "$OPT_DIR"
385+
386+
# Flatten structure: move binaries to $OPT_DIR
387+
FFMPEG_SUBDIR=$(find "$OPT_DIR" -maxdepth 1 -type d -name "ffmpeg-*-static" | head -n 1)
388+
if [ -n "$FFMPEG_SUBDIR" ]; then
389+
cp "$FFMPEG_SUBDIR/ffmpeg" "$FFMPEG_SUBDIR/ffprobe" "$OPT_DIR/"
390+
echo -e "${GREEN}FFmpeg installed to: $OPT_DIR${NC}"
391+
fi
392+
rm "$OPT_DIR/ffmpeg.tar.xz"
393+
else
394+
echo -e "${RED}Failed to download FFmpeg.${NC}"
395+
fi
396+
fi
397+
398+
# 2. ifv2mp4
399+
IFV_DIR="$OPT_DIR/ifv2mp4"
400+
if [[ -f "$IFV_DIR/release/tlgrectomp4" ]]; then
401+
echo -e "${GREEN}ifv2mp4 already exists in $IFV_DIR. Skipping download.${NC}"
402+
else
403+
echo -e "${BLUE}Installing ifv2mp4...${NC}"
404+
mkdir -p "$IFV_DIR"
405+
curl -L -o "$IFV_DIR/tlg.tar.gz" "https://github.com/TranscodeGroup/docker/releases/download/v1.0.4/tlgrectomp4_linux1.0.0.4.tar.gz"
406+
407+
if [ -f "$IFV_DIR/tlg.tar.gz" ]; then
408+
echo "Extracting ifv2mp4..."
409+
tar -xzf "$IFV_DIR/tlg.tar.gz" -C "$IFV_DIR"
410+
echo -e "${GREEN}ifv2mp4 installed to: $IFV_DIR${NC}"
411+
else
412+
echo -e "${RED}Failed to download ifv2mp4.${NC}"
413+
fi
414+
fi
415+
fi
416+
289417
if [ -n "$INPUT_IP" ]; then
290418
echo -e "\n${GREEN}Service Access URLs:${NC}"
291419
echo -e " HTTP: ${BLUE}http://${INPUT_IP}${NC}"

0 commit comments

Comments
 (0)