From ee4354b571a54f46395ef27b425aa1904022d7f3 Mon Sep 17 00:00:00 2001 From: CN-JS-HuiBai Date: Mon, 6 Apr 2026 16:45:00 +0800 Subject: [PATCH] =?UTF-8?q?=E6=94=AF=E6=8C=81=E8=87=AA=E5=8A=A8=E8=AF=86?= =?UTF-8?q?=E5=88=AB=E7=9B=AE=E5=BD=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- update.sh | 36 +++++++++++++++++++++++++++--------- 1 file changed, 27 insertions(+), 9 deletions(-) diff --git a/update.sh b/update.sh index 8b90cb9..cc2e7b5 100644 --- a/update.sh +++ b/update.sh @@ -6,10 +6,10 @@ set -e # Config -APP_DIR="/opt/promdata-panel" SERVICE_NAME="promdatapanel" +DEFAULT_APP_DIR="/opt/promdata-panel" -# 1. Colors for logs +# 1. Colors & Banner GREEN='\033[0;32m' BLUE='\033[0;34m' RED='\033[0;31m' @@ -17,16 +17,34 @@ NC='\033[0m' # No Color echo -e "${BLUE}=== Starting PromdataPanel Update ===${NC}" -# Detect if we're in the app directory -if [ ! -d ".git" ]; then - if [ -d "$APP_DIR/.git" ]; then - cd "$APP_DIR" - else - echo -e "${RED}Error: Not in a git repository or $APP_DIR. Please run this from the app root.${NC}" - exit 1 +# 2. Detect APP_DIR automatically from systemd service +if systemctl list-unit-files | grep -q "^$SERVICE_NAME.service"; then + echo "Detecting application directory from systemd service..." + # Get WorkingDirectory from systemd (using env to handle it safely) + SERVICE_DIR=$(systemctl show -p WorkingDirectory "$SERVICE_NAME" | cut -d= -f2-) + if [ -n "$SERVICE_DIR" ] && [ -d "$SERVICE_DIR" ]; then + APP_DIR="$SERVICE_DIR" fi fi +# Fallback 1: Current directory if it contains package.json +if [ -z "$APP_DIR" ]; then + if [ -f "package.json" ]; then + APP_DIR=$(pwd) + else + APP_DIR="$DEFAULT_APP_DIR" + fi +fi + +echo -e "${BLUE}Application directory: $APP_DIR${NC}" + +if [ ! -d "$APP_DIR" ]; then + echo -e "${RED}Error: Could not find application directory at $APP_DIR. Check if you installed it correctly.${NC}" + exit 1 +fi + +cd "$APP_DIR" + # 2. Update logic if [ -d ".git" ]; then echo -e "${BLUE}Git repository detected. Pulling latest code...${NC}"