Repository navigation
Expand file tree
/
Copy pathcloud-agent-update
More file actions
executable file
·153 lines (137 loc) · 3.27 KB
/
Copy pathcloud-agent-update
File metadata and controls
executable file
·153 lines (137 loc) · 3.27 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
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
#!/usr/bin/env bash
set -euo pipefail
DOTFILES_DIR="${HOME}/dotfiles"
DOTFILES_URL="https://github.com/mr-lee/dotfiles.git"
BRANCH="master"
UPDATE_SYSTEM=false
UPDATE_AGENTS=true
RUN_DOCTOR=true
FULL_DOCTOR=false
DRY_RUN=false
usage() {
cat <<'EOF'
usage: cloud-agent-update [options]
Update dotfiles-managed cloud agent tooling, then run a health check.
Defaults:
- fetch dotfiles over public HTTPS with global Git config disabled
- refresh user-level agent tools, Cline Pass adapters, tmux wrappers, and helpers
- do not run apt/system package changes unless --system is passed
- run quick cloud-agent-doctor
Options:
--dotfiles DIR Dotfiles checkout (default: ~/dotfiles)
--repo URL Public dotfiles URL (default: https://github.com/mr-lee/dotfiles.git)
--branch BRANCH Branch to fetch (default: master)
--system Include apt/system package installation
--no-agents Skip agent CLI updates
--no-doctor Skip doctor after update
--full-doctor Run model probes in doctor; may incur provider usage
--dry-run Print commands without changing the machine
-h, --help Show this help
EOF
}
while [[ $# -gt 0 ]]; do
case "$1" in
--dotfiles)
DOTFILES_DIR="$2"
shift 2
;;
--repo)
DOTFILES_URL="$2"
shift 2
;;
--branch)
BRANCH="$2"
shift 2
;;
--system)
UPDATE_SYSTEM=true
shift
;;
--no-agents)
UPDATE_AGENTS=false
shift
;;
--no-doctor)
RUN_DOCTOR=false
shift
;;
--full-doctor)
FULL_DOCTOR=true
shift
;;
--dry-run)
DRY_RUN=true
shift
;;
-h|--help)
usage
exit 0
;;
*)
echo "ERROR: unknown option: $1" >&2
usage >&2
exit 2
;;
esac
done
run() {
printf '+'
printf ' %q' "$@"
printf '\n'
if [[ "$DRY_RUN" != true ]]; then
"$@"
fi
}
fetch_dotfiles() {
if [[ -d "${DOTFILES_DIR}/.git" ]]; then
run env GIT_CONFIG_GLOBAL=/dev/null git -C "$DOTFILES_DIR" fetch "$DOTFILES_URL" "$BRANCH"
run git -C "$DOTFILES_DIR" merge --ff-only FETCH_HEAD
else
run env GIT_CONFIG_GLOBAL=/dev/null git clone --branch "$BRANCH" "$DOTFILES_URL" "$DOTFILES_DIR"
fi
}
run_setup() {
local setup="${DOTFILES_DIR}/setup-cloud-agent-machine.sh"
if [[ ! -x "$setup" ]]; then
echo "ERROR: missing executable setup script: ${setup}" >&2
exit 1
fi
local args=()
if [[ "$UPDATE_SYSTEM" != true ]]; then
args+=(--no-system)
fi
args+=(--no-tailscale)
if [[ "$UPDATE_AGENTS" != true ]]; then
args+=(--no-agents)
fi
if [[ "$DRY_RUN" == true ]]; then
args+=(--dry-run)
fi
run "$setup" "${args[@]}"
}
run_doctor() {
if [[ "$RUN_DOCTOR" != true ]]; then
return
fi
local doctor="${DOTFILES_DIR}/cloud-agent-doctor"
if [[ ! -x "$doctor" ]]; then
doctor="${HOME}/.local/bin/cloud-agent-doctor"
fi
if [[ ! -x "$doctor" ]]; then
echo "WARN: cloud-agent-doctor not found; skipping" >&2
return
fi
local args=()
if [[ "$FULL_DOCTOR" == true ]]; then
args+=(--full)
fi
run "$doctor" "${args[@]}"
}
echo "cloud-agent-update -> ${DOTFILES_DIR}"
if [[ "$DRY_RUN" == true ]]; then
echo "(dry run - no changes will be made)"
fi
echo
fetch_dotfiles
run_setup
run_doctor