Skip to content

Commit 687fdab

Browse files
shuguangshuguang
authored andcommitted
feat: 添加 install.sh 路径解析功能以兼容不同部署位置
1 parent 2caeb49 commit 687fdab

File tree

1 file changed

+36
-4
lines changed

1 file changed

+36
-4
lines changed

docker-backup-menu.sh

Lines changed: 36 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,30 @@ set -euo pipefail
1111
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
1212
source "${SCRIPT_DIR}/backup-utils.sh"
1313

14+
# 解析 install.sh 路径(兼容不同部署位置)
15+
get_install_sh() {
16+
local candidate
17+
candidate="${SCRIPT_DIR}/install.sh"
18+
if [[ -x "$candidate" ]]; then
19+
echo "$candidate"
20+
return 0
21+
fi
22+
23+
candidate="./install.sh"
24+
if [[ -x "$candidate" ]]; then
25+
echo "$candidate"
26+
return 0
27+
fi
28+
29+
if command -v install.sh >/dev/null 2>&1; then
30+
echo "$(command -v install.sh)"
31+
return 0
32+
fi
33+
34+
log_error "未找到 install.sh,请将脚本复制到 ${SCRIPT_DIR} 或确保当前目录存在 install.sh"
35+
return 1
36+
}
37+
1438
# 颜色定义
1539
RED='\033[0;31m'
1640
GREEN='\033[0;32m'
@@ -546,13 +570,17 @@ start_http_server_menu() {
546570
return
547571
;;
548572
a)
549-
execute_backup "${SCRIPT_DIR}/install.sh --start-http" "启动HTTP服务器(所有备份)"
573+
local install_sh
574+
install_sh=$(get_install_sh) || { read -p "按回车键继续..."; return; }
575+
execute_backup "${install_sh} --start-http" "启动HTTP服务器(所有备份)"
550576
;;
551577
*)
552578
if [[ "$choice" =~ ^[0-9]+$ ]] && [[ "$choice" -ge 1 ]] && [[ "$choice" -le ${#backups[@]} ]]; then
553579
local selected_backup="${backups[$((choice-1))]}"
554580
local backup_name=$(basename "${selected_backup}")
555-
execute_backup "${SCRIPT_DIR}/install.sh --start-http -b '$selected_backup'" "启动HTTP服务器($backup_name"
581+
local install_sh
582+
install_sh=$(get_install_sh) || { read -p "按回车键继续..."; return; }
583+
execute_backup "${install_sh} --start-http -b '$selected_backup'" "启动HTTP服务器($backup_name"
556584
else
557585
log_error "无效选择"
558586
read -p "按回车键继续..."
@@ -566,7 +594,9 @@ stop_http_server_menu() {
566594
echo -e "${CYAN}停止HTTP服务器${NC}"
567595
echo ""
568596

569-
execute_backup "${SCRIPT_DIR}/install.sh --stop-http" "停止HTTP服务器"
597+
local install_sh
598+
install_sh=$(get_install_sh) || { read -p "按回车键继续..."; return; }
599+
execute_backup "${install_sh} --stop-http" "停止HTTP服务器"
570600
}
571601

572602
# 下载并恢复备份
@@ -598,7 +628,9 @@ download_restore_menu() {
598628
echo ""
599629

600630
if ask_confirmation "确认下载并恢复此备份吗?"; then
601-
execute_backup "${SCRIPT_DIR}/install.sh --download-restore '$download_url'" "下载并恢复备份"
631+
local install_sh
632+
install_sh=$(get_install_sh) || { read -p "按回车键继续..."; return; }
633+
execute_backup "${install_sh} --download-restore '$download_url'" "下载并恢复备份"
602634
fi
603635
}
604636

0 commit comments

Comments
 (0)