优化升级脚本
This commit is contained in:
52
update.sh
52
update.sh
@@ -27,9 +27,57 @@ if [ ! -d ".git" ]; then
|
|||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# 2. Pull latest code from current branch
|
# 2. Update logic
|
||||||
echo -e "${BLUE}Pulling latest code from git...${NC}"
|
if [ -d ".git" ]; then
|
||||||
|
echo -e "${BLUE}Git repository detected. Pulling latest code...${NC}"
|
||||||
git pull
|
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
|
# 3. Update dependencies
|
||||||
echo -e "${BLUE}Updating npm dependencies...${NC}"
|
echo -e "${BLUE}Updating npm dependencies...${NC}"
|
||||||
|
|||||||
Reference in New Issue
Block a user