-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathsync.sh
More file actions
executable file
·248 lines (218 loc) · 6.27 KB
/
Copy pathsync.sh
File metadata and controls
executable file
·248 lines (218 loc) · 6.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
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
#!/usr/bin/env bash
set -euo pipefail
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
source "$SCRIPT_DIR/scripts/setup_lib.sh"
print_usage() {
cat <<'EOF'
Usage: ./sync.sh [options]
Options:
--check Verify state without making changes
--verbose Show exact missing items during checks
--with-sudo Update the login shell using sudo-backed chsh
--bootstrap-brew Install platform prerequisites and Homebrew if needed
--adopt Let stow adopt unmanaged files
--launch-shell Exec into a new login shell after syncing
--help Show this help text
Examples:
./sync.sh
./sync.sh --check
./sync.sh --check --verbose
./sync.sh --with-sudo
./sync.sh --bootstrap-brew --with-sudo --launch-shell
EOF
}
run_checks() {
local verbose="$1"
local brew_ready="$2"
local issues=0
local missing
if (( brew_ready )); then
if brew_bundle_check; then
printf 'OK Homebrew packages match Brewfile\n'
else
printf 'MISS Homebrew packages are out of sync with Brewfile\n'
if (( verbose )); then
missing="$(missing_brewfile_formulae)"
[[ -n "$missing" ]] && printf '%s\n' "$missing" | while IFS= read -r line; do printf ' - %s\n' "$line"; done
fi
issues=$((issues + 1))
fi
else
printf 'WARN Homebrew is unavailable or not usable; skipping Brewfile check\n'
fi
if check_manifest_npm_packages; then
printf 'OK npm packages from manifest are installed\n'
else
printf 'MISS npm packages from manifest are missing\n'
if (( verbose )); then
missing="$(missing_manifest_npm_packages)"
[[ -n "$missing" ]] && printf '%s\n' "$missing" | while IFS= read -r line; do printf ' - %s\n' "$line"; done
fi
issues=$((issues + 1))
fi
if check_pi_packages_from_settings; then
printf 'OK Pi packages from home/.pi/agent/settings.json are installed\n'
else
printf 'MISS Pi packages from home/.pi/agent/settings.json are missing\n'
if (( verbose )); then
missing="$(missing_pi_packages_from_settings || true)"
[[ -n "$missing" ]] && printf '%s\n' "$missing" | while IFS= read -r line; do printf ' - %s\n' "$line"; done
fi
issues=$((issues + 1))
fi
if check_manifest_uv_tools; then
printf 'OK uv tools from manifest are installed\n'
else
printf 'MISS uv tools from manifest are missing\n'
if (( verbose )); then
missing="$(missing_manifest_uv_tools)"
[[ -n "$missing" ]] && printf '%s\n' "$missing" | while IFS= read -r line; do printf ' - %s\n' "$line"; done
fi
issues=$((issues + 1))
fi
if check_manifest_git_clones; then
printf 'OK git-managed extras from manifest are present\n'
else
printf 'MISS git-managed extras from manifest are missing\n'
if (( verbose )); then
missing="$(missing_manifest_git_clones)"
[[ -n "$missing" ]] && printf '%s\n' "$missing" | while IFS= read -r line; do printf ' - %s\n' "$line"; done
fi
issues=$((issues + 1))
fi
if check_tmux_terminfo; then
printf 'OK tmux-256color terminfo is installed\n'
else
printf 'MISS tmux-256color terminfo is missing\n'
if (( verbose )); then
printf ' - %s\n' "$TMUX_TERMINFO_SOURCE_PATH"
printf ' - install with: tic -x -o ~/.terminfo %s\n' "$TMUX_TERMINFO_SOURCE_PATH"
fi
issues=$((issues + 1))
fi
if require_cmd bat; then
if check_bat_theme; then
printf 'OK bat theme is present\n'
else
printf 'MISS bat theme is missing\n'
if (( verbose )); then
printf ' - %s\n' "$(bat --config-dir)/themes/Catppuccin Mocha.tmTheme"
fi
issues=$((issues + 1))
fi
else
printf 'WARN bat is unavailable; skipping bat theme check\n'
fi
if check_agent_socket; then
printf 'OK ssh agent socket placeholder exists\n'
else
printf 'MISS ssh agent socket placeholder is missing\n'
if (( verbose )); then
printf ' - %s\n' "$HOME/.ssh/.agent_socket"
fi
issues=$((issues + 1))
fi
if check_stow_sync; then
printf 'OK stow links are up to date\n'
else
printf 'MISS stow would still make changes; run ./sync.sh\n'
if (( verbose )); then
missing="$(stow_check_output)"
[[ -n "$missing" ]] && printf '%s\n' "$missing"
fi
issues=$((issues + 1))
fi
return "$issues"
}
run_apply() {
local with_sudo="$1"
local adopt_stow="$2"
local launch_shell="$3"
local brew_ready="$4"
if (( brew_ready )); then
brew_bundle_install
else
printf 'WARN Homebrew is unavailable or not usable; skipping Brewfile-managed installs\n'
fi
ensure_manifest_npm_packages
ensure_manifest_uv_tools
ensure_base_directories
ensure_manifest_git_clones
ensure_tmux_terminfo
ensure_bat_theme
restow_home "$adopt_stow"
ensure_pi_packages_from_settings
ensure_fzf
ensure_tmux_plugins
ensure_agent_socket
ensure_nvim_plugins
if (( with_sudo || launch_shell )); then
ensure_login_shell "$with_sudo"
fi
if (( launch_shell )); then
exec zsh -l
fi
printf 'Sync complete.\n'
}
main() {
local check_only=0
local verbose=0
local with_sudo=0
local bootstrap_brew=0
local adopt_stow=0
local launch_shell=0
local brew_ready=0
while [[ $# -gt 0 ]]; do
case "$1" in
--check)
check_only=1
;;
--verbose)
verbose=1
;;
--with-sudo)
with_sudo=1
;;
--bootstrap-brew)
bootstrap_brew=1
;;
--adopt)
adopt_stow=1
;;
--launch-shell)
launch_shell=1
;;
--help)
print_usage
exit 0
;;
*)
printf 'Unknown option: %s\n' "$1" >&2
print_usage >&2
exit 1
;;
esac
shift
done
if (( with_sudo )); then
ensure_sudo
fi
if (( verbose == 0 )); then
maybe_delegate_sync_to_mise "$check_only" "$with_sudo" "$bootstrap_brew" "$adopt_stow" "$launch_shell" || true
fi
if (( bootstrap_brew )); then
install_platform_prereqs
ensure_homebrew_installed
brew_ready=1
elif ensure_homebrew_available; then
brew_ready=1
else
printf 'WARN Continuing without Homebrew-managed steps.\n' >&2
fi
if (( check_only )); then
run_checks "$verbose" "$brew_ready"
exit $?
fi
run_apply "$with_sudo" "$adopt_stow" "$launch_shell" "$brew_ready"
}
main "$@"