-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathupdate.sh
More file actions
executable file
·90 lines (75 loc) · 2.8 KB
/
update.sh
File metadata and controls
executable file
·90 lines (75 loc) · 2.8 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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
#!/bin/bash
#
# update.sh - Update astrbot-git AUR package
#
# This script handles the full update workflow:
# 1. Pull latest from origin (AUR)
# 2. Download and compute new pkgver from upstream repos
# 3. Bump pkgrel (always, to force rebuild even on hotfix changes)
# 4. Commit and push to both AUR and GitHub mirror
#
set -euo pipefail
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
cd "$SCRIPT_DIR"
BRANCH=$(git symbolic-ref --short HEAD)
PKGNAME=$(awk -F= '/^pkgname=/{gsub(/'\''|"/, "", $2); print $2; exit}' PKGBUILD)
echo "=== Updating astrbot-git ==="
echo "[1/5] Fetching latest from AUR..."
git fetch --prune origin
echo "[2/5] Checking for divergence..."
LOCAL=$(git rev-parse @)
REMOTE=$(git rev-parse origin/$BRANCH)
BASE=$(git merge-base @ origin/$BRANCH)
if [ "$LOCAL" = "$REMOTE" ]; then
echo ">>> Already up to date with AUR."
elif [ "$LOCAL" = "$BASE" ]; then
echo ">>> Fast-forwarding to latest AUR..."
git pull origin "$BRANCH"
elif [ "$REMOTE" = "$BASE" ]; then
echo ">>> Local commits ahead — will push after rebuild."
git pull --rebase origin "$BRANCH" || {
echo "❌ Pull with rebase failed. Resolve conflicts manually."
exit 1
}
else
echo "❌ Diverged from AUR. Manual resolution required."
git status
exit 1
fi
echo "[3/5] Downloading upstream sources and computing version..."
rm -rf src/ pkg/ "$PKGNAME"*.pkg.tar.* 2>/dev/null || true
makepkg -od --noconfirm
TMP_SRCINFO="$(mktemp)"
trap 'rm -f "$TMP_SRCINFO"' EXIT
makepkg --printsrcinfo >"$TMP_SRCINFO"
NEW_VER=$(awk '$1 == "pkgver" && $2 == "=" { print $3; exit }' "$TMP_SRCINFO")
[ -n "$NEW_VER" ] || {
echo "❌ 无法从 .SRCINFO 解析 pkgver"
exit 1
}
OLD_VER=$(awk -F= '/^pkgver=/{gsub(/'\''|"/, "", $2); print $2; exit}' PKGBUILD)
OLD_PKGREL=$(awk -F= '/^pkgrel=/{gsub(/'\''|"/, "", $2); print $2; exit}' PKGBUILD)
if [ "$NEW_VER" != "$OLD_VER" ]; then
echo ">>> 版本变化: ${OLD_VER} → ${NEW_VER},重置 pkgrel=1"
NEW_PKGREL=1
else
echo ">>> 版本未变,递增 pkgrel: ${OLD_PKGREL} → $((OLD_PKGREL + 1))"
NEW_PKGREL=$((OLD_PKGREL + 1))
fi
echo "[4/5] Updating PKGBUILD and .SRCINFO..."
sed -i "s/^pkgver=.*/pkgver=${NEW_VER}/" PKGBUILD
sed -i "s/^pkgrel=.*/pkgrel=${NEW_PKGREL}/" PKGBUILD
makepkg --printsrcinfo >.SRCINFO
echo "[5/5] Committing and pushing..."
git add PKGBUILD .SRCINFO
if git diff --cached --quiet; then
echo ">>> 没有 PKGBUILD/.SRCINFO 更改,跳过提交"
else
git commit -m "update to version $NEW_VER-$NEW_PKGREL"
fi
git push origin "$BRANCH"
git push github "$BRANCH" 2>/dev/null || echo "⚠️ GitHub push failed (check credentials)"
echo "=== ✅ 完成!版本: $NEW_VER-$NEW_PKGREL ==="
echo ""
echo "在远程服务器上执行以下命令更新:"
echo " ssh ArchDmit 'sudo -u lightjunction paru -Syu astrbot-git --noconfirm'"