From 480cdf3f6dc27f3cb01ec3b4bfd3e46bbfbf5970 Mon Sep 17 00:00:00 2001 From: CN-JS-HuiBai Date: Mon, 6 Apr 2026 16:34:21 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E5=8D=87=E7=BA=A7=E8=84=9A?= =?UTF-8?q?=E6=9C=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- update.sh | 54 +++++++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 51 insertions(+), 3 deletions(-) diff --git a/update.sh b/update.sh index ea7a4b5..fe7bae2 100644 --- a/update.sh +++ b/update.sh @@ -27,9 +27,57 @@ if [ ! -d ".git" ]; then fi fi -# 2. Pull latest code from current branch -echo -e "${BLUE}Pulling latest code from git...${NC}" -git pull +# 2. Update logic +if [ -d ".git" ]; then + echo -e "${BLUE}Git repository detected. Pulling latest code...${NC}" + git pull +else + echo -e "${BLUE}No git repository found. Updating via ZIP archive...${NC}" + + # URL for zip download (adjust as needed for specific versioning) + ZIP_URL="https://git.littlediary.cn/CN-JS-HuiBai/PromdataPanel/archive/main.tar.gz" + TEMP_DIR="/tmp/promdata_update_$(date +%s)" + + mkdir -p "$TEMP_DIR" + echo "Downloading latest version..." + curl -L "$ZIP_URL" -o "$TEMP_DIR/latest.tar.gz" + + echo "Extracting archive..." + tar -xzf "$TEMP_DIR/latest.tar.gz" -C "$TEMP_DIR" + + # The extracted folder is usually named project-main or similar + EXTRACTED_FOLDER=$(ls -d "$TEMP_DIR"/*/ | head -n 1) + + # Ensure rsync is available (Auto-install if missing) + if ! command -v rsync &> /dev/null; then + echo -e "${BLUE}rsync is not installed. Attempting to install it...${NC}" + if command -v apt-get &> /dev/null; then + sudo apt-get update && sudo apt-get install -y rsync + elif command -v dnf &> /dev/null; then + sudo dnf install -y rsync + elif command -v yum &> /dev/null; then + sudo yum install -y rsync + elif command -v apk &> /dev/null; then + sudo apk add rsync + else + echo -e "${RED}Error: 'rsync' is not installed and could not auto-install. Please install it manually.${NC}" + rm -rf "$TEMP_DIR" + exit 1 + fi + fi + + if [ -n "$EXTRACTED_FOLDER" ]; then + echo "Applying updates (preserving .env)..." + # Copy everything except .env + rsync -av --exclude '.env' --exclude 'node_modules' "$EXTRACTED_FOLDER" ./ + else + echo -e "${RED}Extraction failed. Please check the archive structure.${NC}" + exit 1 + fi + + # Cleanup + rm -rf "$TEMP_DIR" +fi # 3. Update dependencies echo -e "${BLUE}Updating npm dependencies...${NC}"