oh-my-devpod 0.14.4 → 0.15.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/runtime/VERSION +1 -1
- package/runtime/bin/omd +0 -0
- package/runtime/build/omd-brew-gateway.sh +326 -0
- package/runtime/build/omd-brew-provisioner.sh +733 -0
- package/runtime/components.toml +10 -0
- package/runtime/install/bootstrap.sh +42 -2
- package/runtime/install/update.sh +22 -1
- package/runtime/modules/core/linuxbrew.sh +36 -1
- package/runtime/modules/lib/common.sh +50 -8
- package/runtime/modules/lib/shared-linuxbrew.sh +242 -0
- package/runtime/modules/lib/source-config.sh +8 -3
- package/runtime/modules/tools/witr.sh +26 -0
- package/runtime/modules/tools/zsh-config.sh +8 -0
package/runtime/components.toml
CHANGED
|
@@ -170,6 +170,16 @@ requires = []
|
|
|
170
170
|
install_requires = ["linuxbrew"]
|
|
171
171
|
uninstall = true
|
|
172
172
|
|
|
173
|
+
[[component]]
|
|
174
|
+
id = "witr"
|
|
175
|
+
name = "witr"
|
|
176
|
+
description = "Trace processes, ports, containers, and files to their launch chain"
|
|
177
|
+
category = "terminal"
|
|
178
|
+
module = "modules/tools/witr.sh"
|
|
179
|
+
requires = []
|
|
180
|
+
install_requires = ["linuxbrew"]
|
|
181
|
+
uninstall = true
|
|
182
|
+
|
|
173
183
|
[[component]]
|
|
174
184
|
id = "neovim"
|
|
175
185
|
name = "Neovim"
|
|
@@ -137,6 +137,9 @@ omd_validate_bundle() {
|
|
|
137
137
|
components.toml \
|
|
138
138
|
install/bootstrap.sh \
|
|
139
139
|
install/update.sh \
|
|
140
|
+
modules/lib/shared-linuxbrew.sh \
|
|
141
|
+
build/omd-brew-gateway.sh \
|
|
142
|
+
build/omd-brew-provisioner.sh \
|
|
140
143
|
modules \
|
|
141
144
|
build \
|
|
142
145
|
config \
|
|
@@ -154,7 +157,7 @@ omd_validate_bundle() {
|
|
|
154
157
|
omd_install_archive() {
|
|
155
158
|
local archive="$1" prefix="$2" bin_dir="${3:-${OMD_DEFAULT_BIN_DIR}}"
|
|
156
159
|
local releases_dir staging_dir bundle_root version release_dir previous_dir="" link_tmp
|
|
157
|
-
local active_path
|
|
160
|
+
local active_path previous_active_target="" mirror_profile
|
|
158
161
|
[[ -f "${archive}" ]] || {
|
|
159
162
|
omd_warn "Missing omd archive: ${archive}"
|
|
160
163
|
return 1
|
|
@@ -202,6 +205,9 @@ omd_install_archive() {
|
|
|
202
205
|
rm -rf "${staging_dir}" || true
|
|
203
206
|
|
|
204
207
|
active_path="${bin_dir}/omd"
|
|
208
|
+
if [[ -L "${active_path}" ]]; then
|
|
209
|
+
previous_active_target="$(readlink "${active_path}")"
|
|
210
|
+
fi
|
|
205
211
|
link_tmp="${bin_dir}/.omd.$$.tmp"
|
|
206
212
|
if ! ln -s "${release_dir}/bin/omd" "${link_tmp}"; then
|
|
207
213
|
rm -rf "${release_dir}"
|
|
@@ -221,6 +227,16 @@ omd_install_archive() {
|
|
|
221
227
|
[[ -z "${previous_dir}" ]] || mv "${previous_dir}" "${release_dir}"
|
|
222
228
|
return 1
|
|
223
229
|
fi
|
|
230
|
+
mirror_profile="${OHMYDEVPOD_MIRROR_PROFILE:-upstream}"
|
|
231
|
+
case "${mirror_profile}" in upstream|cn) ;; *) mirror_profile=upstream ;; esac
|
|
232
|
+
if ! omd_activate_shared_linuxbrew_profile_if_present "${release_dir}" "${mirror_profile}"; then
|
|
233
|
+
rm -f "${active_path}"
|
|
234
|
+
[[ -z "${previous_active_target}" ]] || ln -s "${previous_active_target}" "${active_path}"
|
|
235
|
+
rm -rf "${release_dir}"
|
|
236
|
+
[[ -z "${previous_dir}" ]] || mv "${previous_dir}" "${release_dir}"
|
|
237
|
+
omd_warn "Shared Linuxbrew activation failed; restored the previous omd release"
|
|
238
|
+
return 1
|
|
239
|
+
fi
|
|
224
240
|
[[ -z "${previous_dir}" ]] || rm -rf "${previous_dir}" || true
|
|
225
241
|
printf '%s\n' "${version}"
|
|
226
242
|
}
|
|
@@ -404,6 +420,30 @@ omd_source_brew_core_remote() {
|
|
|
404
420
|
esac
|
|
405
421
|
}
|
|
406
422
|
|
|
423
|
+
omd_activate_shared_linuxbrew_profile_if_present() {
|
|
424
|
+
local release_root="$1" profile="$2" helper prefix state_dir
|
|
425
|
+
helper="${release_root}/modules/lib/shared-linuxbrew.sh"
|
|
426
|
+
if [[ "${OHMYDEVPOD_SHARED_BREW_TEST_MODE:-0}" == "1" ]]; then
|
|
427
|
+
prefix="${OHMYDEVPOD_SHARED_BREW_PREFIX:-/home/linuxbrew/.linuxbrew}"
|
|
428
|
+
state_dir="${OHMYDEVPOD_SHARED_BREW_STATE_DIR:-/var/lib/oh-my-devpod/linuxbrew}"
|
|
429
|
+
else
|
|
430
|
+
prefix="/home/linuxbrew/.linuxbrew"
|
|
431
|
+
state_dir="/var/lib/oh-my-devpod/linuxbrew"
|
|
432
|
+
fi
|
|
433
|
+
[[ -e "${prefix}" || -L "${prefix}" || -e "${state_dir}/manifest" || -L "${state_dir}/manifest" ]] || return 0
|
|
434
|
+
[[ -f "${helper}" && ! -L "${helper}" ]] || {
|
|
435
|
+
omd_warn "Installed release cannot activate the existing shared Linuxbrew installation"
|
|
436
|
+
return 1
|
|
437
|
+
}
|
|
438
|
+
bash -c 'set -euo pipefail; source "$1"; omd_shared_linuxbrew_activate_if_present "$2" "$3"' _ "${helper}" "${release_root}" "${profile}"
|
|
439
|
+
}
|
|
440
|
+
|
|
441
|
+
omd_activate_shared_linuxbrew_if_present() {
|
|
442
|
+
local release_root="$1" source="$2" profile
|
|
443
|
+
profile="$(omd_source_mirror_profile "${source}")" || return 1
|
|
444
|
+
omd_activate_shared_linuxbrew_profile_if_present "${release_root}" "${profile}"
|
|
445
|
+
}
|
|
446
|
+
|
|
407
447
|
omd_main() {
|
|
408
448
|
local os_release target requested_version source bin_dir prefix cache_dir config_dir
|
|
409
449
|
local archive checksum selected_source installed_version candidate
|
|
@@ -458,7 +498,7 @@ omd_main() {
|
|
|
458
498
|
selected_source="${OMD_SELECTED_SOURCE}"
|
|
459
499
|
fi
|
|
460
500
|
|
|
461
|
-
installed_version="$(omd_install_archive "${archive}" "${prefix}" "${bin_dir}")"
|
|
501
|
+
installed_version="$(OHMYDEVPOD_MIRROR_PROFILE="$(omd_source_mirror_profile "${selected_source}")" omd_install_archive "${archive}" "${prefix}" "${bin_dir}")"
|
|
462
502
|
omd_persist_source "${selected_source}" "${config_dir}"
|
|
463
503
|
omd_persist_install_paths "${prefix}" "${bin_dir}" "${cache_dir}" "${config_dir}"
|
|
464
504
|
omd_info "Installed oh-my-devpod ${installed_version} from ${selected_source}"
|
|
@@ -101,10 +101,19 @@ OMD_UPDATE_BREW_CORE_PREFIX=""
|
|
|
101
101
|
OMD_UPDATE_BREW_CORE_REMOTE=""
|
|
102
102
|
OMD_UPDATE_BREW_CORE_REMOTE_PRESENT=0
|
|
103
103
|
OMD_UPDATE_BREW_CORE_REMOTE_CHANGED=0
|
|
104
|
+
OMD_UPDATE_BREW_SHARED=0
|
|
105
|
+
OMD_UPDATE_BREW_SHARED_PROFILE=""
|
|
106
|
+
OMD_UPDATE_BREW_SHARED_CHANGED=0
|
|
104
107
|
|
|
105
108
|
omd_update_capture_brew_remote() {
|
|
106
109
|
local marker_prefix core_prefix
|
|
107
110
|
omd_module_is_managed linuxbrew || return 0
|
|
111
|
+
if omd_shared_linuxbrew_managed; then
|
|
112
|
+
OMD_UPDATE_BREW_SHARED=1
|
|
113
|
+
OMD_UPDATE_BREW_PREFIX="$(omd_shared_linuxbrew_prefix)"
|
|
114
|
+
OMD_UPDATE_BREW_SHARED_PROFILE="$(omd_shared_linuxbrew_manifest_value mirror_profile || true)"
|
|
115
|
+
case "${OMD_UPDATE_BREW_SHARED_PROFILE}" in upstream|cn) return 0 ;; *) return 1 ;; esac
|
|
116
|
+
fi
|
|
108
117
|
marker_prefix="$(omd_module_marker_value linuxbrew artifact || true)"
|
|
109
118
|
[[ -n "${marker_prefix}" && -d "${marker_prefix}" && -x "${marker_prefix}/bin/brew" ]] || {
|
|
110
119
|
omd_warn "Managed Homebrew prefix is missing or invalid: ${marker_prefix:-<empty>}"
|
|
@@ -145,8 +154,16 @@ omd_update_capture_brew_remote() {
|
|
|
145
154
|
}
|
|
146
155
|
|
|
147
156
|
omd_update_apply_brew_remote() {
|
|
148
|
-
local source="$1" target_remote target_core_remote
|
|
157
|
+
local source="$1" target_remote target_core_remote target_profile
|
|
149
158
|
[[ -n "${OMD_UPDATE_BREW_PREFIX}" ]] || return 0
|
|
159
|
+
if [[ "${OMD_UPDATE_BREW_SHARED}" == "1" ]]; then
|
|
160
|
+
target_profile="$(omd_source_mirror_profile "${source}")" || return 1
|
|
161
|
+
if [[ "${target_profile}" != "${OMD_UPDATE_BREW_SHARED_PROFILE}" ]]; then
|
|
162
|
+
omd_shared_linuxbrew_set_profile "${target_profile}" || return 1
|
|
163
|
+
OMD_UPDATE_BREW_SHARED_CHANGED=1
|
|
164
|
+
fi
|
|
165
|
+
return 0
|
|
166
|
+
fi
|
|
150
167
|
target_remote="$(omd_source_brew_remote "${source}")" || return 1
|
|
151
168
|
if [[ "${OMD_UPDATE_BREW_LEGACY}" == "1" ]]; then
|
|
152
169
|
git -C "${OMD_UPDATE_BREW_PREFIX}" init -q || return 1
|
|
@@ -182,6 +199,10 @@ omd_update_apply_brew_remote() {
|
|
|
182
199
|
|
|
183
200
|
omd_update_restore_brew_remote() {
|
|
184
201
|
local rollback_failed=0
|
|
202
|
+
if [[ "${OMD_UPDATE_BREW_SHARED_CHANGED}" == "1" ]]; then
|
|
203
|
+
omd_shared_linuxbrew_set_profile "${OMD_UPDATE_BREW_SHARED_PROFILE}" || rollback_failed=1
|
|
204
|
+
return "${rollback_failed}"
|
|
205
|
+
fi
|
|
185
206
|
if [[ "${OMD_UPDATE_BREW_CORE_REMOTE_CHANGED}" == "1" ]]; then
|
|
186
207
|
if [[ "${OMD_UPDATE_BREW_CORE_REMOTE_PRESENT}" == "1" ]]; then
|
|
187
208
|
git -C "${OMD_UPDATE_BREW_CORE_PREFIX}" remote set-url origin "${OMD_UPDATE_BREW_CORE_REMOTE}" ||
|
|
@@ -4,9 +4,26 @@ set -euo pipefail
|
|
|
4
4
|
source "$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)/lib/common.sh"
|
|
5
5
|
|
|
6
6
|
component="linuxbrew"
|
|
7
|
-
|
|
7
|
+
if omd_shared_linuxbrew_enabled; then
|
|
8
|
+
brew_prefix="$(omd_shared_linuxbrew_prefix)"
|
|
9
|
+
else
|
|
10
|
+
brew_prefix="${HOMEBREW_PREFIX:-/home/linuxbrew/.linuxbrew}"
|
|
11
|
+
fi
|
|
8
12
|
|
|
9
13
|
status() {
|
|
14
|
+
if omd_shared_linuxbrew_enabled; then
|
|
15
|
+
if omd_shared_linuxbrew_managed && omd_shared_linuxbrew_current_user_enrolled; then
|
|
16
|
+
return 0
|
|
17
|
+
fi
|
|
18
|
+
if omd_shared_linuxbrew_state_claim_present; then
|
|
19
|
+
return 1
|
|
20
|
+
fi
|
|
21
|
+
if omd_module_marker_matches "${component}" "${brew_prefix}"; then
|
|
22
|
+
[[ -x "${brew_prefix}/bin/brew" ]]
|
|
23
|
+
return
|
|
24
|
+
fi
|
|
25
|
+
return 1
|
|
26
|
+
fi
|
|
10
27
|
if managed; then
|
|
11
28
|
[[ -x "${brew_prefix}/bin/brew" ]]
|
|
12
29
|
return
|
|
@@ -15,6 +32,12 @@ status() {
|
|
|
15
32
|
}
|
|
16
33
|
|
|
17
34
|
managed() {
|
|
35
|
+
if omd_shared_linuxbrew_managed && omd_shared_linuxbrew_current_user_enrolled; then
|
|
36
|
+
return 0
|
|
37
|
+
fi
|
|
38
|
+
if omd_shared_linuxbrew_state_claim_present; then
|
|
39
|
+
return 1
|
|
40
|
+
fi
|
|
18
41
|
omd_module_marker_matches "${component}" "${brew_prefix}"
|
|
19
42
|
}
|
|
20
43
|
|
|
@@ -23,6 +46,18 @@ install_or_update() {
|
|
|
23
46
|
shift
|
|
24
47
|
omd_module_reject_unknown_flags "$@" || return
|
|
25
48
|
|
|
49
|
+
if omd_shared_linuxbrew_enabled; then
|
|
50
|
+
if omd_module_dry_run "$@"; then
|
|
51
|
+
omd_module_info plan "${action} host-shared Linuxbrew under ${brew_prefix}"
|
|
52
|
+
return 0
|
|
53
|
+
fi
|
|
54
|
+
omd_shared_linuxbrew_provision "$(omd_module_repo_root)" "${OHMYDEVPOD_MIRROR_PROFILE:-upstream}"
|
|
55
|
+
if [[ "${action}" == "update" ]]; then
|
|
56
|
+
omd_module_brew_exec "$(omd_shared_linuxbrew_gateway)" update
|
|
57
|
+
fi
|
|
58
|
+
return 0
|
|
59
|
+
fi
|
|
60
|
+
|
|
26
61
|
if status && ! managed; then
|
|
27
62
|
omd_module_external_installation "${component}"
|
|
28
63
|
return 0
|
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
#!/usr/bin/env bash
|
|
2
2
|
# Shared helpers for oh-my-devpod component modules.
|
|
3
3
|
|
|
4
|
+
# shellcheck source=shared-linuxbrew.sh
|
|
5
|
+
source "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/shared-linuxbrew.sh"
|
|
6
|
+
|
|
4
7
|
omd_module_repo_root() {
|
|
5
8
|
local script_dir
|
|
6
9
|
script_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
|
@@ -34,6 +37,10 @@ omd_module_marker_path() {
|
|
|
34
37
|
|
|
35
38
|
omd_module_is_managed() {
|
|
36
39
|
local component="$1" marker
|
|
40
|
+
if [[ "${component}" == "linuxbrew" ]] && omd_shared_linuxbrew_state_claim_present; then
|
|
41
|
+
omd_shared_linuxbrew_managed && omd_shared_linuxbrew_current_user_enrolled
|
|
42
|
+
return
|
|
43
|
+
fi
|
|
37
44
|
marker="$(omd_module_marker_path "${component}")" || return
|
|
38
45
|
[[ -f "${marker}" ]] && grep -qx 'managed_by=oh-my-devpod' "${marker}"
|
|
39
46
|
}
|
|
@@ -60,6 +67,15 @@ omd_module_mark_managed() {
|
|
|
60
67
|
|
|
61
68
|
omd_module_marker_value() {
|
|
62
69
|
local component="$1" key="$2" marker
|
|
70
|
+
if [[ "${component}" == "linuxbrew" ]] && omd_shared_linuxbrew_state_claim_present; then
|
|
71
|
+
omd_shared_linuxbrew_managed && omd_shared_linuxbrew_current_user_enrolled || return 1
|
|
72
|
+
case "${key}" in
|
|
73
|
+
artifact) omd_shared_linuxbrew_prefix ;;
|
|
74
|
+
kind) printf 'directory\n' ;;
|
|
75
|
+
*) omd_shared_linuxbrew_manifest_value "${key}" ;;
|
|
76
|
+
esac
|
|
77
|
+
return
|
|
78
|
+
fi
|
|
63
79
|
marker="$(omd_module_marker_path "${component}")" || return
|
|
64
80
|
[[ -f "${marker}" ]] || return 1
|
|
65
81
|
sed -n "s/^${key}=//p" "${marker}" | head -n 1
|
|
@@ -171,6 +187,12 @@ omd_module_brew_cmd() {
|
|
|
171
187
|
printf '%s\n' "${OHMYDEVPOD_BREW_BIN}"
|
|
172
188
|
return 0
|
|
173
189
|
fi
|
|
190
|
+
if omd_shared_linuxbrew_managed; then
|
|
191
|
+
candidate="$(omd_shared_linuxbrew_gateway)"
|
|
192
|
+
[[ -x "${candidate}" ]] || return 1
|
|
193
|
+
printf '%s\n' "${candidate}"
|
|
194
|
+
return 0
|
|
195
|
+
fi
|
|
174
196
|
if command -v brew >/dev/null 2>&1; then
|
|
175
197
|
command -v brew
|
|
176
198
|
return 0
|
|
@@ -245,6 +267,7 @@ omd_module_brew_exec() {
|
|
|
245
267
|
local brew="$1"
|
|
246
268
|
shift
|
|
247
269
|
env -u HOMEBREW_ASK \
|
|
270
|
+
OHMYDEVPOD_BREW_NONINTERACTIVE=1 \
|
|
248
271
|
NONINTERACTIVE=1 \
|
|
249
272
|
HOMEBREW_NO_ASK=1 \
|
|
250
273
|
HOMEBREW_NO_AUTO_UPDATE=1 \
|
|
@@ -266,6 +289,10 @@ omd_module_formula_status() {
|
|
|
266
289
|
|
|
267
290
|
omd_module_formula_managed() {
|
|
268
291
|
local component="$1" formula="$2" kind
|
|
292
|
+
if omd_shared_linuxbrew_state_claim_present; then
|
|
293
|
+
omd_shared_linuxbrew_formula_managed "${component}" "${formula}"
|
|
294
|
+
return
|
|
295
|
+
fi
|
|
269
296
|
omd_module_marker_matches "${component}" "${formula}" || return 1
|
|
270
297
|
kind="$(omd_module_marker_value "${component}" kind || true)"
|
|
271
298
|
[[ "${kind}" == "brew-formula" ]]
|
|
@@ -273,6 +300,10 @@ omd_module_formula_managed() {
|
|
|
273
300
|
|
|
274
301
|
omd_module_formula_marker_prefix() {
|
|
275
302
|
local component="$1" formula="$2" prefix linuxbrew_kind
|
|
303
|
+
if omd_shared_linuxbrew_state_claim_present; then
|
|
304
|
+
omd_shared_linuxbrew_formula_prefix "${component}" "${formula}"
|
|
305
|
+
return
|
|
306
|
+
fi
|
|
276
307
|
omd_module_formula_managed "${component}" "${formula}" || return 1
|
|
277
308
|
prefix="$(omd_module_marker_value "${component}" brew_prefix || true)"
|
|
278
309
|
if [[ -z "${prefix}" ]] && omd_module_is_managed linuxbrew; then
|
|
@@ -293,6 +324,10 @@ omd_module_formula_marker_prefix() {
|
|
|
293
324
|
|
|
294
325
|
omd_module_formula_brew_cmd() {
|
|
295
326
|
local component="$1" formula="$2" prefix
|
|
327
|
+
if omd_shared_linuxbrew_formula_managed "${component}" "${formula}"; then
|
|
328
|
+
omd_shared_linuxbrew_gateway
|
|
329
|
+
return
|
|
330
|
+
fi
|
|
296
331
|
prefix="$(omd_module_formula_marker_prefix "${component}" "${formula}")" || return 1
|
|
297
332
|
printf '%s/bin/brew\n' "${prefix}"
|
|
298
333
|
}
|
|
@@ -309,7 +344,7 @@ omd_module_formula_install_or_update() {
|
|
|
309
344
|
fi
|
|
310
345
|
|
|
311
346
|
if omd_module_dry_run "$@"; then
|
|
312
|
-
omd_module_info plan "${action} Homebrew formula ${formula}"
|
|
347
|
+
omd_module_info plan "${action} host-shared Homebrew formula ${formula}"
|
|
313
348
|
return 0
|
|
314
349
|
fi
|
|
315
350
|
|
|
@@ -335,11 +370,18 @@ omd_module_formula_install_or_update() {
|
|
|
335
370
|
else
|
|
336
371
|
omd_module_brew_exec "${brew}" install "${formula}"
|
|
337
372
|
fi
|
|
338
|
-
|
|
339
|
-
"${component}"
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
373
|
+
if omd_shared_linuxbrew_managed; then
|
|
374
|
+
omd_shared_linuxbrew_formula_managed "${component}" "${formula}" || {
|
|
375
|
+
omd_module_info error "shared Brew inventory did not record ${formula}"
|
|
376
|
+
return 1
|
|
377
|
+
}
|
|
378
|
+
else
|
|
379
|
+
omd_module_mark_managed \
|
|
380
|
+
"${component}" \
|
|
381
|
+
brew-formula \
|
|
382
|
+
"${formula}" \
|
|
383
|
+
"brew_prefix=${brew_prefix}"
|
|
384
|
+
fi
|
|
343
385
|
}
|
|
344
386
|
|
|
345
387
|
omd_module_formula_uninstall_impl() {
|
|
@@ -348,7 +390,7 @@ omd_module_formula_uninstall_impl() {
|
|
|
348
390
|
omd_module_reject_unknown_flags "$@" || return
|
|
349
391
|
|
|
350
392
|
if omd_module_dry_run "$@"; then
|
|
351
|
-
omd_module_info plan "uninstall
|
|
393
|
+
omd_module_info plan "uninstall host-shared Homebrew formula ${formula} for all users"
|
|
352
394
|
return 0
|
|
353
395
|
fi
|
|
354
396
|
|
|
@@ -376,7 +418,7 @@ omd_module_formula_uninstall_impl() {
|
|
|
376
418
|
return 1
|
|
377
419
|
fi
|
|
378
420
|
omd_module_brew_exec "${brew}" uninstall "${formula}"
|
|
379
|
-
if [[ "${remove_marker}" == "1" ]]; then
|
|
421
|
+
if [[ "${remove_marker}" == "1" ]] && ! omd_shared_linuxbrew_managed; then
|
|
380
422
|
omd_module_unmark_managed "${component}"
|
|
381
423
|
fi
|
|
382
424
|
}
|
|
@@ -0,0 +1,242 @@
|
|
|
1
|
+
#!/usr/bin/env bash
|
|
2
|
+
# Host-scoped Linuxbrew state shared by every OMD user.
|
|
3
|
+
|
|
4
|
+
omd_shared_linuxbrew_test_mode() {
|
|
5
|
+
[[ "${OHMYDEVPOD_SHARED_BREW_TEST_MODE:-0}" == "1" ]]
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
omd_shared_linuxbrew_prefix() {
|
|
9
|
+
if omd_shared_linuxbrew_test_mode; then
|
|
10
|
+
printf '%s\n' "${OHMYDEVPOD_SHARED_BREW_PREFIX:-/home/linuxbrew/.linuxbrew}"
|
|
11
|
+
else
|
|
12
|
+
printf '%s\n' "/home/linuxbrew/.linuxbrew"
|
|
13
|
+
fi
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
omd_shared_linuxbrew_state_dir() {
|
|
17
|
+
if omd_shared_linuxbrew_test_mode; then
|
|
18
|
+
printf '%s\n' "${OHMYDEVPOD_SHARED_BREW_STATE_DIR:-/var/lib/oh-my-devpod/linuxbrew}"
|
|
19
|
+
else
|
|
20
|
+
printf '%s\n' "/var/lib/oh-my-devpod/linuxbrew"
|
|
21
|
+
fi
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
omd_shared_linuxbrew_libexec_dir() {
|
|
25
|
+
if omd_shared_linuxbrew_test_mode; then
|
|
26
|
+
printf '%s\n' "${OHMYDEVPOD_SHARED_BREW_LIBEXEC_DIR:-/usr/local/libexec/oh-my-devpod}"
|
|
27
|
+
else
|
|
28
|
+
printf '%s\n' "/usr/local/libexec/oh-my-devpod"
|
|
29
|
+
fi
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
omd_shared_linuxbrew_gateway() {
|
|
33
|
+
printf '%s/bin/brew\n' "$(omd_shared_linuxbrew_libexec_dir)"
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
omd_shared_linuxbrew_manifest() {
|
|
37
|
+
printf '%s/manifest\n' "$(omd_shared_linuxbrew_state_dir)"
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
omd_shared_linuxbrew_state_claim_present() {
|
|
41
|
+
local manifest
|
|
42
|
+
manifest="$(omd_shared_linuxbrew_manifest)"
|
|
43
|
+
[[ -e "${manifest}" || -L "${manifest}" ]]
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
omd_shared_linuxbrew_enabled() {
|
|
47
|
+
[[ "${OHMYDEVPOD_SHARED_BREW_DISABLE:-0}" != "1" ]]
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
omd_shared_linuxbrew_manifest_value() {
|
|
51
|
+
local key="$1" manifest
|
|
52
|
+
manifest="$(omd_shared_linuxbrew_manifest)"
|
|
53
|
+
[[ -f "${manifest}" && ! -L "${manifest}" ]] || return 1
|
|
54
|
+
sed -n "s/^${key}=//p" "${manifest}" | head -n 1
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
omd_shared_linuxbrew_group_gid() {
|
|
58
|
+
local group="$1"
|
|
59
|
+
if command -v getent >/dev/null 2>&1; then
|
|
60
|
+
getent group "${group}" | awk -F: '{print $3}'
|
|
61
|
+
else
|
|
62
|
+
id -g "${group}"
|
|
63
|
+
fi
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
omd_shared_linuxbrew_stat_uid() {
|
|
67
|
+
if stat -c '%u' "$1" >/dev/null 2>&1; then stat -c '%u' "$1"; else stat -f '%u' "$1"; fi
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
omd_shared_linuxbrew_stat_gid() {
|
|
71
|
+
if stat -c '%g' "$1" >/dev/null 2>&1; then stat -c '%g' "$1"; else stat -f '%g' "$1"; fi
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
omd_shared_linuxbrew_stat_mode() {
|
|
75
|
+
if stat -c '%a' "$1" >/dev/null 2>&1; then stat -c '%a' "$1"; else stat -f '%Lp' "$1"; fi
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
omd_shared_linuxbrew_validate() {
|
|
79
|
+
local manifest prefix recorded_prefix service_user manager_group installation_id
|
|
80
|
+
local expected_uid expected_gid actual_uid actual_gid
|
|
81
|
+
omd_shared_linuxbrew_enabled || return 1
|
|
82
|
+
manifest="$(omd_shared_linuxbrew_manifest)"
|
|
83
|
+
[[ -f "${manifest}" && ! -L "${manifest}" ]] || return 1
|
|
84
|
+
[[ "$(omd_shared_linuxbrew_manifest_value schema_version || true)" == "1" ]] || return 1
|
|
85
|
+
[[ "$(omd_shared_linuxbrew_manifest_value managed_by || true)" == "oh-my-devpod" ]] || return 1
|
|
86
|
+
[[ "$(omd_shared_linuxbrew_manifest_value mode || true)" == "shared-service-account" ]] || return 1
|
|
87
|
+
|
|
88
|
+
prefix="$(omd_shared_linuxbrew_prefix)"
|
|
89
|
+
recorded_prefix="$(omd_shared_linuxbrew_manifest_value prefix || true)"
|
|
90
|
+
[[ "${recorded_prefix}" == "${prefix}" && "${prefix}" == /* && ! -L "${prefix}" ]] || return 1
|
|
91
|
+
[[ -d "${prefix}" && -x "${prefix}/bin/brew" ]] || return 1
|
|
92
|
+
prefix="$(cd "${prefix}" 2>/dev/null && pwd -P)" || return 1
|
|
93
|
+
[[ "${prefix}" == "${recorded_prefix}" ]] || return 1
|
|
94
|
+
|
|
95
|
+
service_user="$(omd_shared_linuxbrew_manifest_value service_user || true)"
|
|
96
|
+
manager_group="$(omd_shared_linuxbrew_manifest_value manager_group || true)"
|
|
97
|
+
expected_uid="$(omd_shared_linuxbrew_manifest_value service_uid || true)"
|
|
98
|
+
expected_gid="$(omd_shared_linuxbrew_manifest_value service_gid || true)"
|
|
99
|
+
installation_id="$(omd_shared_linuxbrew_manifest_value installation_id || true)"
|
|
100
|
+
[[ "${service_user}" =~ ^[a-z_][a-z0-9_-]*[$]?$ ]] || return 1
|
|
101
|
+
[[ "${manager_group}" =~ ^[a-z_][a-z0-9_-]*[$]?$ ]] || return 1
|
|
102
|
+
[[ "${expected_uid}" =~ ^[0-9]+$ && "${expected_gid}" =~ ^[0-9]+$ ]] || return 1
|
|
103
|
+
[[ "${installation_id}" =~ ^[[:xdigit:]]{8}-[[:xdigit:]]{4}-[[:xdigit:]]{4}-[[:xdigit:]]{4}-[[:xdigit:]]{12}$ ]] || return 1
|
|
104
|
+
actual_uid="$(id -u "${service_user}" 2>/dev/null || true)"
|
|
105
|
+
if omd_shared_linuxbrew_test_mode && [[ -n "${OHMYDEVPOD_SHARED_BREW_TEST_SERVICE_GID:-}" ]]; then
|
|
106
|
+
actual_gid="${OHMYDEVPOD_SHARED_BREW_TEST_SERVICE_GID}"
|
|
107
|
+
else
|
|
108
|
+
actual_gid="$(omd_shared_linuxbrew_group_gid "${manager_group}" 2>/dev/null || true)"
|
|
109
|
+
fi
|
|
110
|
+
[[ "${actual_uid}" == "${expected_uid}" && "${actual_gid}" == "${expected_gid}" ]] || return 1
|
|
111
|
+
[[ "$(omd_shared_linuxbrew_stat_uid "${prefix}")" == "${expected_uid}" ]] || return 1
|
|
112
|
+
[[ "$(omd_shared_linuxbrew_stat_gid "${prefix}")" == "${expected_gid}" ]] || return 1
|
|
113
|
+
if ! omd_shared_linuxbrew_test_mode; then
|
|
114
|
+
[[ "$(omd_shared_linuxbrew_stat_uid "${manifest}")" == "0" ]] || return 1
|
|
115
|
+
[[ "$(omd_shared_linuxbrew_stat_gid "${manifest}")" == "0" ]] || return 1
|
|
116
|
+
(( (8#$(omd_shared_linuxbrew_stat_mode "${manifest}") & 8#022) == 0 )) || return 1
|
|
117
|
+
[[ "$(omd_shared_linuxbrew_stat_uid "$(omd_shared_linuxbrew_state_dir)")" == "0" ]] || return 1
|
|
118
|
+
[[ "$(omd_shared_linuxbrew_stat_uid "$(omd_shared_linuxbrew_libexec_dir)/brew-gateway")" == "0" ]] || return 1
|
|
119
|
+
[[ "$(omd_shared_linuxbrew_stat_uid "$(omd_shared_linuxbrew_libexec_dir)/brew-provisioner")" == "0" ]] || return 1
|
|
120
|
+
fi
|
|
121
|
+
[[ -d "$(omd_shared_linuxbrew_state_dir)/inventory" && ! -L "$(omd_shared_linuxbrew_state_dir)/inventory" ]] || return 1
|
|
122
|
+
[[ -f "$(omd_shared_linuxbrew_state_dir)/locks/mutation.lock" && ! -L "$(omd_shared_linuxbrew_state_dir)/locks/mutation.lock" ]] || return 1
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
omd_shared_linuxbrew_managed() {
|
|
126
|
+
omd_shared_linuxbrew_validate
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
omd_shared_linuxbrew_current_user_enrolled() {
|
|
130
|
+
local user uid record
|
|
131
|
+
omd_shared_linuxbrew_managed || return 1
|
|
132
|
+
if omd_shared_linuxbrew_test_mode && [[ -n "${OHMYDEVPOD_SHARED_BREW_TEST_CURRENT_USER:-}" ]]; then
|
|
133
|
+
user="${OHMYDEVPOD_SHARED_BREW_TEST_CURRENT_USER}"
|
|
134
|
+
uid="${OHMYDEVPOD_SHARED_BREW_TEST_CURRENT_UID:-$(id -u)}"
|
|
135
|
+
else
|
|
136
|
+
user="$(id -un)"
|
|
137
|
+
uid="$(id -u)"
|
|
138
|
+
fi
|
|
139
|
+
[[ "${user}" =~ ^[a-z_][a-z0-9_-]*[$]?$ ]] || return 1
|
|
140
|
+
record="$(omd_shared_linuxbrew_state_dir)/members/${user}"
|
|
141
|
+
[[ -f "${record}" && ! -L "${record}" ]] || return 1
|
|
142
|
+
grep -Fqx "managed_by=oh-my-devpod" "${record}" || return 1
|
|
143
|
+
grep -Fqx "user=${user}" "${record}" || return 1
|
|
144
|
+
grep -Fqx "uid=${uid}" "${record}"
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
omd_shared_linuxbrew_marker_path() {
|
|
148
|
+
local formula="$1"
|
|
149
|
+
[[ "${formula}" =~ ^[a-z0-9][a-z0-9@+_.-]*$ ]] || return 2
|
|
150
|
+
printf '%s/inventory/%s\n' "$(omd_shared_linuxbrew_state_dir)" "${formula}"
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
omd_shared_linuxbrew_formula_managed() {
|
|
154
|
+
local component="$1" formula="$2" marker prefix installation_id
|
|
155
|
+
omd_shared_linuxbrew_managed || return 1
|
|
156
|
+
omd_shared_linuxbrew_current_user_enrolled || return 1
|
|
157
|
+
[[ "${component}" == "${formula}" ]] || return 1
|
|
158
|
+
marker="$(omd_shared_linuxbrew_marker_path "${formula}")" || return
|
|
159
|
+
[[ -f "${marker}" && ! -L "${marker}" ]] || return 1
|
|
160
|
+
grep -qx 'managed_by=oh-my-devpod' "${marker}" || return 1
|
|
161
|
+
grep -Fqx "component=${component}" "${marker}" || return 1
|
|
162
|
+
grep -Fqx 'kind=brew-formula' "${marker}" || return 1
|
|
163
|
+
grep -Fqx "artifact=${formula}" "${marker}" || return 1
|
|
164
|
+
grep -Fqx 'state=managed' "${marker}" || return 1
|
|
165
|
+
prefix="$(omd_shared_linuxbrew_prefix)"
|
|
166
|
+
grep -Fqx "brew_prefix=${prefix}" "${marker}" || return 1
|
|
167
|
+
installation_id="$(omd_shared_linuxbrew_manifest_value installation_id || true)"
|
|
168
|
+
grep -Fqx "installation_id=${installation_id}" "${marker}" || return 1
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
omd_shared_linuxbrew_formula_prefix() {
|
|
172
|
+
local component="$1" formula="$2"
|
|
173
|
+
omd_shared_linuxbrew_formula_managed "${component}" "${formula}" || return 1
|
|
174
|
+
omd_shared_linuxbrew_prefix
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
omd_shared_linuxbrew_install_controller() {
|
|
178
|
+
local bundle_root="$1" source_controller source_gateway libexec_dir sudo_bin
|
|
179
|
+
source_controller="${bundle_root}/build/omd-brew-provisioner.sh"
|
|
180
|
+
source_gateway="${bundle_root}/build/omd-brew-gateway.sh"
|
|
181
|
+
libexec_dir="$(omd_shared_linuxbrew_libexec_dir)"
|
|
182
|
+
[[ -f "${source_controller}" && ! -L "${source_controller}" ]] || {
|
|
183
|
+
printf 'error: shared Linuxbrew provisioner is missing: %s\n' "${source_controller}" >&2
|
|
184
|
+
return 1
|
|
185
|
+
}
|
|
186
|
+
[[ -f "${source_gateway}" && ! -L "${source_gateway}" ]] || {
|
|
187
|
+
printf 'error: shared Linuxbrew gateway is missing: %s\n' "${source_gateway}" >&2
|
|
188
|
+
return 1
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
if omd_shared_linuxbrew_test_mode; then
|
|
192
|
+
mkdir -p "${libexec_dir}/bin"
|
|
193
|
+
install -m 0755 "${source_controller}" "${libexec_dir}/brew-provisioner"
|
|
194
|
+
install -m 0755 "${source_gateway}" "${libexec_dir}/brew-gateway"
|
|
195
|
+
return 0
|
|
196
|
+
fi
|
|
197
|
+
|
|
198
|
+
sudo_bin="${OHMYDEVPOD_SUDO_BIN:-sudo}"
|
|
199
|
+
command -v "${sudo_bin}" >/dev/null 2>&1 || {
|
|
200
|
+
printf 'error: sudo is required to initialize or join shared Linuxbrew\n' >&2
|
|
201
|
+
return 1
|
|
202
|
+
}
|
|
203
|
+
"${sudo_bin}" -- install -d -o root -g root -m 0755 "${libexec_dir}" "${libexec_dir}/bin"
|
|
204
|
+
"${sudo_bin}" -- install -o root -g root -m 0755 "${source_controller}" "${libexec_dir}/brew-provisioner"
|
|
205
|
+
"${sudo_bin}" -- install -o root -g root -m 0755 "${source_gateway}" "${libexec_dir}/brew-gateway"
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
omd_shared_linuxbrew_provision() {
|
|
209
|
+
local bundle_root="$1" mirror_profile="${2:-upstream}" controller sudo_bin
|
|
210
|
+
case "${mirror_profile}" in upstream|cn) ;; *) return 2 ;; esac
|
|
211
|
+
omd_shared_linuxbrew_install_controller "${bundle_root}" || return
|
|
212
|
+
controller="$(omd_shared_linuxbrew_libexec_dir)/brew-provisioner"
|
|
213
|
+
if omd_shared_linuxbrew_test_mode; then
|
|
214
|
+
"${controller}" ensure "${mirror_profile}"
|
|
215
|
+
return
|
|
216
|
+
fi
|
|
217
|
+
sudo_bin="${OHMYDEVPOD_SUDO_BIN:-sudo}"
|
|
218
|
+
"${sudo_bin}" -- "${controller}" ensure "${mirror_profile}"
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
omd_shared_linuxbrew_set_profile() {
|
|
222
|
+
local profile="$1" controller sudo_bin
|
|
223
|
+
case "${profile}" in upstream|cn) ;; *) return 2 ;; esac
|
|
224
|
+
omd_shared_linuxbrew_managed || return 1
|
|
225
|
+
controller="$(omd_shared_linuxbrew_libexec_dir)/brew-provisioner"
|
|
226
|
+
[[ -x "${controller}" && ! -L "${controller}" ]] || return 1
|
|
227
|
+
if omd_shared_linuxbrew_test_mode; then
|
|
228
|
+
"${controller}" source-profile "${profile}"
|
|
229
|
+
return
|
|
230
|
+
fi
|
|
231
|
+
sudo_bin="${OHMYDEVPOD_SUDO_BIN:-sudo}"
|
|
232
|
+
"${sudo_bin}" -n -- "${controller}" source-profile "${profile}"
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
omd_shared_linuxbrew_activate_if_present() {
|
|
236
|
+
local bundle_root="$1" mirror_profile="${2:-upstream}" prefix manifest
|
|
237
|
+
omd_shared_linuxbrew_enabled || return 0
|
|
238
|
+
prefix="$(omd_shared_linuxbrew_prefix)"
|
|
239
|
+
manifest="$(omd_shared_linuxbrew_manifest)"
|
|
240
|
+
[[ -e "${prefix}" || -L "${prefix}" || -e "${manifest}" || -L "${manifest}" ]] || return 0
|
|
241
|
+
omd_shared_linuxbrew_provision "${bundle_root}" "${mirror_profile}"
|
|
242
|
+
}
|
|
@@ -51,14 +51,19 @@ omd_source_config_formula_managed() {
|
|
|
51
51
|
}
|
|
52
52
|
|
|
53
53
|
omd_source_config_linuxbrew_prefix() {
|
|
54
|
-
local prefix kind
|
|
54
|
+
local prefix kind brew
|
|
55
55
|
omd_module_is_managed linuxbrew || return 1
|
|
56
56
|
prefix="$(omd_module_marker_value linuxbrew artifact || true)"
|
|
57
57
|
kind="$(omd_module_marker_value linuxbrew kind || true)"
|
|
58
58
|
[[ "${kind}" == "directory" && -n "${prefix}" && ! -L "${prefix}" && -x "${prefix}/bin/brew" ]] ||
|
|
59
59
|
return 1
|
|
60
60
|
prefix="$(cd "${prefix}" 2>/dev/null && pwd -P)" || return 1
|
|
61
|
-
|
|
61
|
+
if omd_shared_linuxbrew_managed; then
|
|
62
|
+
brew="$(omd_shared_linuxbrew_gateway)"
|
|
63
|
+
else
|
|
64
|
+
brew="${prefix}/bin/brew"
|
|
65
|
+
fi
|
|
66
|
+
omd_module_brew_cmd_matches_prefix "${brew}" "${prefix}" || return 1
|
|
62
67
|
printf '%s\n' "${prefix}"
|
|
63
68
|
}
|
|
64
69
|
|
|
@@ -132,7 +137,7 @@ omd_source_config_file_is_managed() {
|
|
|
132
137
|
|
|
133
138
|
omd_source_config_active_paths() {
|
|
134
139
|
local prefix need_pip=0
|
|
135
|
-
if prefix="$(omd_source_config_linuxbrew_prefix)"; then
|
|
140
|
+
if ! omd_shared_linuxbrew_managed && prefix="$(omd_source_config_linuxbrew_prefix)"; then
|
|
136
141
|
printf 'brew\t%s/etc/homebrew/brew.env\t%s\n' "${prefix}" "${prefix}"
|
|
137
142
|
fi
|
|
138
143
|
if omd_source_config_formula_managed uv uv; then
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
#!/usr/bin/env bash
|
|
2
|
+
set -euo pipefail
|
|
3
|
+
|
|
4
|
+
source "$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)/lib/common.sh"
|
|
5
|
+
|
|
6
|
+
component="witr"
|
|
7
|
+
formula="witr"
|
|
8
|
+
command_name="witr"
|
|
9
|
+
|
|
10
|
+
status() { omd_module_formula_status "${formula}" "${command_name}"; }
|
|
11
|
+
managed() { omd_module_formula_managed "${component}" "${formula}"; }
|
|
12
|
+
install_or_update() {
|
|
13
|
+
local action="$1"
|
|
14
|
+
shift
|
|
15
|
+
omd_module_formula_install_or_update "${component}" "${formula}" "${command_name}" "${action}" "$@"
|
|
16
|
+
}
|
|
17
|
+
uninstall() { omd_module_formula_uninstall "${component}" "${formula}" "$@"; }
|
|
18
|
+
|
|
19
|
+
case "${1:-}" in
|
|
20
|
+
status) status ;;
|
|
21
|
+
managed) managed ;;
|
|
22
|
+
install) shift; install_or_update install "$@" ;;
|
|
23
|
+
update) shift; install_or_update update "$@" ;;
|
|
24
|
+
uninstall) shift; uninstall "$@" ;;
|
|
25
|
+
*) omd_module_unknown_action "${1:-}" ;;
|
|
26
|
+
esac
|
|
@@ -51,11 +51,19 @@ if [[ -f "${OHMYDEVPOD_CONFIG_DIR}/env" ]]; then
|
|
|
51
51
|
source "${OHMYDEVPOD_CONFIG_DIR}/env"
|
|
52
52
|
set +a
|
|
53
53
|
fi
|
|
54
|
+
omd_brew_gateway_dir="/usr/local/libexec/oh-my-devpod/bin"
|
|
55
|
+
if [[ -x "${omd_brew_gateway_dir}/brew" ]]; then
|
|
56
|
+
export PATH="${omd_brew_gateway_dir}:${PATH}"
|
|
57
|
+
fi
|
|
54
58
|
if command -v brew >/dev/null 2>&1; then
|
|
55
59
|
eval "$(brew shellenv)"
|
|
56
60
|
elif [[ -x /home/linuxbrew/.linuxbrew/bin/brew ]]; then
|
|
57
61
|
eval "$(/home/linuxbrew/.linuxbrew/bin/brew shellenv)"
|
|
58
62
|
fi
|
|
63
|
+
if [[ -x "${omd_brew_gateway_dir}/brew" ]]; then
|
|
64
|
+
export PATH="${omd_brew_gateway_dir}:${PATH}"
|
|
65
|
+
fi
|
|
66
|
+
unset omd_brew_gateway_dir
|
|
59
67
|
export PATH="$HOME/.local/bin:$PATH"
|
|
60
68
|
omd_mamba_hook=""
|
|
61
69
|
if command -v mamba >/dev/null 2>&1; then
|