-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathupdate.sh
More file actions
executable file
·127 lines (106 loc) · 3.52 KB
/
Copy pathupdate.sh
File metadata and controls
executable file
·127 lines (106 loc) · 3.52 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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
#!/bin/bash
set -u
BOLO_DIR="$(cd "$(dirname "$0")" && pwd)"
result() {
echo "BOLO_UPDATE_RESULT=$1"
if [ "${2:-}" != "" ]; then
echo "BOLO_UPDATE_REASON=$2"
fi
}
cd "$BOLO_DIR" || {
result skipped "Bolo directory is unavailable."
exit 0
}
if [ ! -d .git ]; then
result skipped "This Bolo install is not a Git checkout."
exit 0
fi
if ! command -v git >/dev/null 2>&1; then
result skipped "Git is not installed."
exit 0
fi
if ! command -v cargo >/dev/null 2>&1; then
result skipped "Rust Cargo is not installed."
exit 0
fi
if ! git diff --quiet -- . || ! git diff --cached --quiet -- .; then
result skipped "Local Bolo files have uncommitted changes. Skipping update."
exit 0
fi
branch="$(git rev-parse --abbrev-ref HEAD 2>/dev/null || true)"
if [ "$branch" = "HEAD" ] || [ "$branch" = "" ]; then
result skipped "Bolo is on a detached Git commit. Skipping update."
exit 0
fi
if ! git remote get-url origin >/dev/null 2>&1; then
result skipped "Bolo has no origin remote configured."
exit 0
fi
if ! git fetch --quiet origin; then
result skipped "Could not reach GitHub for updates."
exit 0
fi
upstream="$(git rev-parse --abbrev-ref --symbolic-full-name '@{u}' 2>/dev/null || true)"
if [ "$upstream" = "" ]; then
if git rev-parse --verify --quiet "origin/$branch^{commit}" >/dev/null; then
upstream="origin/$branch"
elif git rev-parse --verify --quiet "origin/main^{commit}" >/dev/null; then
upstream="origin/main"
else
result skipped "No upstream branch found for updates."
exit 0
fi
fi
local_head="$(git rev-parse HEAD)"
remote_head="$(git rev-parse "$upstream")"
if [ "$local_head" = "$remote_head" ]; then
result current
exit 0
fi
if ! git merge-base --is-ancestor HEAD "$upstream"; then
result skipped "Local Bolo is not behind $upstream cleanly. Skipping update."
exit 0
fi
tmp_dir="$(mktemp -d "${TMPDIR:-/tmp}/bolo-update.XXXXXX")"
cleanup() {
if [ "${worktree_dir:-}" != "" ] && [ -d "$worktree_dir" ]; then
git worktree remove --force "$worktree_dir" >/dev/null 2>&1 || true
fi
rm -rf "$tmp_dir"
}
trap cleanup EXIT
worktree_dir="$tmp_dir/source"
target_dir="$tmp_dir/target"
if ! git worktree add --detach "$worktree_dir" "$upstream" >/dev/null 2>&1; then
result skipped "Could not prepare the fetched Bolo update."
exit 0
fi
if [ ! -x "$worktree_dir/ensure-python-env.sh" ]; then
result skipped "Fetched Bolo update has no Python helper installer."
exit 0
fi
if ! "$worktree_dir/ensure-python-env.sh" --sync >/dev/null; then
result skipped "Fetched Bolo update could not prepare its Python helpers."
exit 0
fi
if ! cargo build --release --manifest-path "$worktree_dir/Cargo.toml" --target-dir "$target_dir"; then
result skipped "Fetched Bolo update did not build."
exit 0
fi
if ! git merge --ff-only "$upstream"; then
result skipped "Could not fast-forward Bolo to $upstream."
exit 0
fi
new_binary="$BOLO_DIR/target/release/bolo.new"
if ! cp "$target_dir/release/bolo" "$new_binary"; then
result skipped "Bolo updated, but the new binary could not be installed."
exit 0
fi
chmod +x "$new_binary"
if ! mv "$new_binary" "$BOLO_DIR/target/release/bolo"; then
rm -f "$new_binary"
result skipped "Bolo updated, but the new binary could not be activated."
exit 0
fi
result updated
osascript -e 'display notification "Code and Python helpers are ready. Bolo will restart now." with title "Bolo updated" with sound name "Glass"' >/dev/null 2>&1 || true