-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathupgrade.sh
More file actions
executable file
·61 lines (50 loc) · 2.37 KB
/
Copy pathupgrade.sh
File metadata and controls
executable file
·61 lines (50 loc) · 2.37 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#!/usr/bin/env bash
# ─────────────────────────────────────────────────────────────────────────────
# ThingsPanel All-in-One — 升级脚本
# 用法: ./upgrade.sh [版本号]
# 示例: ./upgrade.sh v1.2.8.1
# ─────────────────────────────────────────────────────────────────────────────
set -euo pipefail
INSTALL_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
REPO="ThingsPanel/thingspanel-installer"
RAW_BASE="https://install.thingspanel.io"
RED='\033[0;31m'; YELLOW='\033[1;33m'; GREEN='\033[0;32m'
BLUE='\033[0;34m'; BOLD='\033[1m'; RESET='\033[0m'
info() { echo -e "${BLUE}[INFO]${RESET} $*"; }
success() { echo -e "${GREEN}[OK]${RESET} $*"; }
warn() { echo -e "${YELLOW}[WARN]${RESET} $*"; }
error() { echo -e "${RED}[ERROR]${RESET} $*" >&2; exit 1; }
step() { echo -e "\n${BOLD}▶ $*${RESET}"; }
main() {
echo -e "${BOLD}ThingsPanel — 升级程序${RESET}"
echo ""
TARGET_VERSION="${1:-}"
if [ -z "$TARGET_VERSION" ]; then
TARGET_VERSION=$(curl -fsSL \
"https://api.github.com/repos/${REPO}/releases/latest" \
2>/dev/null | grep '"tag_name"' | head -1 | sed 's/.*"tag_name": *"\([^"]*\)".*/\1/' || true)
fi
if [ -z "$TARGET_VERSION" ]; then
error "无法获取最新版本,请手动指定:./upgrade.sh v1.2.8.1"
fi
info "目标版本: $TARGET_VERSION"
step "备份配置文件"
if [ -f "${INSTALL_DIR}/docker-compose.yml" ]; then
cp "${INSTALL_DIR}/docker-compose.yml" "${INSTALL_DIR}/docker-compose.yml.bak.$(date +%Y%m%d%H%M%S)"
fi
success "已备份"
step "更新配置文件"
curl -fsSL "${RAW_BASE}/docker-compose.yml" -o "${INSTALL_DIR}/docker-compose.yml"
success "配置文件已更新"
step "拉取新镜像"
cd "$INSTALL_DIR"
docker compose pull --quiet
success "镜像拉取完成"
step "重启服务"
docker compose up -d --wait --timeout 180
success "升级完成!当前版本: $TARGET_VERSION"
echo ""
echo -e "${GREEN}✓ ThingsPanel 已成功升级到 ${BOLD}${TARGET_VERSION}${RESET}"
echo ""
}
main "$@"