From 20aee89dcc365ed61165a23f1d072b0427994533 Mon Sep 17 00:00:00 2001 From: shaw Date: Thu, 18 Dec 2025 16:00:57 +0800 Subject: [PATCH] fix: Fixed installation issues with the install.sh script. --- README.md | 1 - README_CN.md | 1 - deploy/install.sh | 51 +++++++++++++++++++++++++++++++++++++++-------- 3 files changed, 43 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index a0988228..6f2c3daa 100644 --- a/README.md +++ b/README.md @@ -57,7 +57,6 @@ One-click installation script that downloads pre-built binaries from GitHub Rele #### Installation Steps ```bash -# Download and run the installation script curl -sSL https://raw.githubusercontent.com/Wei-Shaw/sub2api/main/deploy/install.sh | sudo bash ``` diff --git a/README_CN.md b/README_CN.md index db25c4e4..ae9417c0 100644 --- a/README_CN.md +++ b/README_CN.md @@ -57,7 +57,6 @@ Sub2API 是一个 AI API 网关平台,用于分发和管理 AI 产品订阅( #### 安装步骤 ```bash -# 下载并运行安装脚本 curl -sSL https://raw.githubusercontent.com/Wei-Shaw/sub2api/main/deploy/install.sh | sudo bash ``` diff --git a/deploy/install.sh b/deploy/install.sh index ea00e6fe..96b46b26 100644 --- a/deploy/install.sh +++ b/deploy/install.sh @@ -260,8 +260,19 @@ print_error() { echo -e "${RED}[$(msg 'error')]${NC} $1" } +# Check if running interactively (stdin is a terminal) +is_interactive() { + [ -t 0 ] +} + # Select language select_language() { + # If not interactive (piped), use default language + if ! is_interactive; then + LANG_CHOICE="zh" + return + fi + echo "" echo -e "${CYAN}==============================================" echo " $(msg 'select_lang')" @@ -271,8 +282,7 @@ select_language() { echo " 2) $(msg 'lang_en')" echo "" - # Read with timeout for piped input - read -t 10 -p "$(msg 'enter_choice'): " lang_input 2>/dev/null || lang_input="" + read -p "$(msg 'enter_choice'): " lang_input case "$lang_input" in 2|en|EN|english|English) @@ -297,6 +307,12 @@ validate_port() { # Configure server settings configure_server() { + # If not interactive (piped), use default settings + if ! is_interactive; then + print_info "$(msg 'server_config_summary'): ${SERVER_HOST}:${SERVER_PORT} (default)" + return + fi + echo "" echo -e "${CYAN}==============================================" echo " $(msg 'server_config_title')" @@ -663,11 +679,20 @@ upgrade() { # Uninstall function uninstall() { print_warning "$(msg 'uninstall_confirm')" - read -p "$(msg 'are_you_sure') " -n 1 -r - echo - if [[ ! $REPLY =~ ^[Yy]$ ]]; then - print_info "$(msg 'uninstall_cancelled')" - exit 0 + + # If not interactive (piped), require -y flag or skip confirmation + if ! is_interactive; then + if [ "${FORCE_YES:-}" != "true" ]; then + print_error "Non-interactive mode detected. Use 'bash -s -- uninstall -y' to confirm." + exit 1 + fi + else + read -p "$(msg 'are_you_sure') " -n 1 -r + echo + if [[ ! $REPLY =~ ^[Yy]$ ]]; then + print_info "$(msg 'uninstall_cancelled')" + exit 0 + fi fi print_info "$(msg 'stopping_service')" @@ -693,6 +718,13 @@ uninstall() { # Main main() { + # Parse -y flag first + for arg in "$@"; do + if [ "$arg" = "-y" ] || [ "$arg" = "--yes" ]; then + FORCE_YES="true" + fi + done + # Select language first select_language @@ -716,13 +748,16 @@ main() { exit 0 ;; --help|-h) - echo "$(msg 'usage'): $0 [command]" + echo "$(msg 'usage'): $0 [command] [options]" echo "" echo "Commands:" echo " $(msg 'cmd_none') $(msg 'cmd_install')" echo " upgrade $(msg 'cmd_upgrade')" echo " uninstall $(msg 'cmd_uninstall')" echo "" + echo "Options:" + echo " -y, --yes Skip confirmation prompts (for uninstall)" + echo "" exit 0 ;; esac