-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbootstrap.sh
More file actions
executable file
·301 lines (265 loc) · 6.58 KB
/
bootstrap.sh
File metadata and controls
executable file
·301 lines (265 loc) · 6.58 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
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
#!/usr/bin/env bash
set -Eeuo pipefail
SCRIPT_DIR="$(dirname "${BASH_SOURCE[0]}")"
ROOT_DIR="$(cd "${SCRIPT_DIR}" && pwd -P)"
source "${ROOT_DIR}/scripts/lib/common.sh"
source "${ROOT_DIR}/scripts/lib/package-manager.sh"
source "${ROOT_DIR}/scripts/lib/tool-map.sh"
CORE_TOOLS=(git curl ssh tmux yazi claude codex)
OPTIONAL_TOOLS=(fish zsh nvim oh-my-posh ranger)
ASSUME_YES="${ASSUME_YES:-0}"
DRY_RUN="${DRY_RUN:-0}"
usage() {
cat <<EOF
Usage: $0 <command> [module...]
Commands:
doctor Check platform, package manager, and tool availability
core Install/check core tools, then run ./install.sh link
install Alias for core
link Run ./install.sh link only
ai Link Claude Code and Codex shared config only
macos Link macOS config and run the macOS setup menu
interactive|choose Choose optional setup groups interactively
optional Show optional modules
optional MODULE... Install/configure optional modules: ${OPTIONAL_TOOLS[*]}
all Run core, then optional fish nvim oh-my-posh
Environment:
ASSUME_YES=1 Skip package installation confirmation
DRY_RUN=1 Print install/link actions without applying them where supported
Core tools: ${CORE_TOOLS[*]}
EOF
}
missing_tools() {
local tool
for tool in "$@"; do
if ! has "${tool}"; then
printf '%s\n' "${tool}"
fi
done
}
confirm_install() {
local packages="$1"
if [[ -z "${packages}" ]]; then
return 0
fi
if [[ "${DRY_RUN}" == "1" || "${ASSUME_YES}" == "1" ]]; then
return 0
fi
say "packages to install: ${packages}"
read -r -p "Proceed with package installation? [y/N] " reply
[[ "${reply}" == "y" || "${reply}" == "Y" ]]
}
install_missing_tools() {
local pm="$1"
shift
local tool package
local missing=()
local packages=()
for tool in "$@"; do
if ! has "${tool}"; then
missing+=("${tool}")
fi
done
if [[ ${#missing[@]} -eq 0 ]]; then
return 0
fi
for tool in "${missing[@]}"; do
package="$(package_for_tool "${tool}" "${pm}")"
if [[ -n "${package}" ]]; then
packages+=("${package}")
else
warn "no automatic package mapping for missing tool: ${tool}"
fi
done
if [[ ${#packages[@]} -eq 0 ]]; then
warn "missing tools require manual installation: ${missing[*]}"
return 0
fi
if confirm_install "${packages[*]}"; then
install_packages "${pm}" "${packages[@]}"
else
warn "package installation skipped"
fi
}
cmd_doctor() {
local platform pm missing
platform="$(platform_name)"
pm="$(package_manager)"
say "platform: ${platform}"
say "package manager: ${pm}"
say "core tools:"
for tool in "${CORE_TOOLS[@]}"; do
if has "${tool}"; then
say " ok: ${tool} ($(command -v "${tool}"))"
else
say " missing: ${tool}"
fi
done
say "optional tools:"
for tool in "${OPTIONAL_TOOLS[@]}"; do
if has "${tool}"; then
say " ok: ${tool} ($(command -v "${tool}"))"
else
say " missing: ${tool}"
fi
done
if [[ "${pm}" == "none" ]]; then
warn "no supported package manager detected"
fi
if [[ "${platform}" == "linux" && "${pm}" == "apt" ]]; then
say "note: yazi and oh-my-posh may need snap, cargo, Homebrew on Linux, or upstream installers on older Ubuntu."
fi
missing="$(missing_tools "${CORE_TOOLS[@]}" || true)"
if [[ -z "${missing}" ]]; then
say "core environment looks ready"
else
say "missing core tools:"
printf '%s\n' "${missing}"
fi
}
run_install_link() {
if [[ "${DRY_RUN}" == "1" ]]; then
"${ROOT_DIR}/install.sh" dry-run
else
"${ROOT_DIR}/install.sh" link
fi
}
cmd_core() {
local pm
pm="$(package_manager)"
install_missing_tools "${pm}" "${CORE_TOOLS[@]}"
run_install_link
cmd_doctor
}
run_optional_module() {
local module="$1"
local pm="$2"
case "${module}" in
fish)
install_missing_tools "${pm}" fish
"${ROOT_DIR}/scripts/optional/fish.sh"
;;
zsh)
install_missing_tools "${pm}" zsh
"${ROOT_DIR}/scripts/optional/zsh.sh"
;;
nvim|neovim)
install_missing_tools "${pm}" nvim
"${ROOT_DIR}/scripts/optional/nvim.sh"
;;
oh-my-posh|omp)
install_missing_tools "${pm}" unzip
"${ROOT_DIR}/scripts/optional/oh-my-posh.sh"
;;
ranger)
install_missing_tools "${pm}" ranger
"${ROOT_DIR}/scripts/optional/ranger.sh"
;;
*)
warn "unknown optional module: ${module}"
return 1
;;
esac
}
cmd_optional() {
local pm module
pm="$(package_manager)"
if [[ $# -eq 0 ]]; then
cat <<EOF
Optional modules:
fish Link old fish and OMF config after installing fish if needed
zsh Show preserved legacy zsh/oh-my-zsh installer after installing zsh if needed
nvim Link LazyVim-based Neovim config after installing neovim if needed
oh-my-posh Link old Oh My Posh themes after installing oh-my-posh when package mapping exists
ranger Install ranger package when available and show vendored source note
Examples:
./bootstrap.sh optional nvim
./bootstrap.sh optional fish nvim oh-my-posh
ASSUME_YES=1 ./bootstrap.sh all
DRY_RUN=1 ./bootstrap.sh all
EOF
return 0
fi
for module in "$@"; do
run_optional_module "${module}" "${pm}"
done
}
cmd_ai() {
if [[ "${DRY_RUN}" == "1" ]]; then
"${ROOT_DIR}/install.sh" dry-run-ai
else
"${ROOT_DIR}/install.sh" ai
fi
}
cmd_macos() {
if [[ "$(platform_name)" != "macos" ]]; then
warn "macOS setup is only available on Darwin"
return 2
fi
if [[ "${DRY_RUN}" == "1" ]]; then
"${ROOT_DIR}/install.sh" dry-run-macos
"${ROOT_DIR}/scripts/macos.sh" list
else
"${ROOT_DIR}/install.sh" macos
"${ROOT_DIR}/scripts/macos.sh" interactive
fi
}
cmd_interactive() {
cat <<EOF
Choose setup mode:
1) core
2) ai
3) macos
4) optional fish nvim oh-my-posh
5) skip
EOF
read -r -p "Mode: " mode
case "${mode}" in
1) cmd_core ;;
2) cmd_ai ;;
3) cmd_macos ;;
4) cmd_optional fish nvim oh-my-posh ;;
5|"") say "skipped" ;;
*) warn "unknown selection: ${mode}"; return 2 ;;
esac
}
cmd_all() {
cmd_core
cmd_optional fish nvim oh-my-posh
}
cmd="${1:-doctor}"
shift || true
case "${cmd}" in
doctor)
cmd_doctor
;;
core|install)
cmd_core
;;
link)
run_install_link
;;
ai)
cmd_ai
;;
macos)
cmd_macos
;;
interactive|choose)
cmd_interactive
;;
optional)
cmd_optional "$@"
;;
all)
cmd_all
;;
-h|--help|help)
usage
;;
*)
warn "unknown command: ${cmd}"
usage >&2
exit 2
;;
esac