oh-my-devpod 0.14.2 → 0.14.3

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.
@@ -7,6 +7,8 @@ export OHMYDEVPOD_BOOTSTRAP_LIB_ONLY=1
7
7
  source "${bundle_root}/install/bootstrap.sh"
8
8
  # shellcheck source=../modules/lib/common.sh
9
9
  source "${bundle_root}/modules/lib/common.sh"
10
+ # shellcheck source=../modules/lib/source-config.sh
11
+ source "${bundle_root}/modules/lib/source-config.sh"
10
12
 
11
13
  omd_update_normalize_version() {
12
14
  printf '%s\n' "${1#v}"
@@ -33,7 +35,7 @@ omd_update_archive_version() {
33
35
  omd_update_snapshot_source_config() {
34
36
  local config_dir="$1" snapshot_dir="$2" name
35
37
  mkdir -p "${snapshot_dir}" || return 1
36
- for name in source mirror-profile env uv.toml install-prefix bin-dir cache-dir; do
38
+ for name in source npm-source mirror-profile env uv.toml install-prefix bin-dir cache-dir; do
37
39
  if [[ -f "${config_dir}/${name}" ]]; then
38
40
  cp -p "${config_dir}/${name}" "${snapshot_dir}/${name}" || return 1
39
41
  else
@@ -45,7 +47,7 @@ omd_update_snapshot_source_config() {
45
47
  omd_update_restore_source_config() {
46
48
  local config_dir="$1" snapshot_dir="$2" name
47
49
  mkdir -p "${config_dir}" || return 1
48
- for name in source mirror-profile env uv.toml install-prefix bin-dir cache-dir; do
50
+ for name in source npm-source mirror-profile env uv.toml install-prefix bin-dir cache-dir; do
49
51
  if [[ -f "${snapshot_dir}/.missing-${name}" ]]; then
50
52
  rm -f "${config_dir}/${name}" || return 1
51
53
  else
@@ -61,12 +63,24 @@ OMD_UPDATE_BREW_REMOTE=""
61
63
  OMD_UPDATE_BREW_REMOTE_PRESENT=0
62
64
  OMD_UPDATE_BREW_REMOTE_CHANGED=0
63
65
  OMD_UPDATE_BREW_LEGACY=0
66
+ OMD_UPDATE_BREW_CORE_PREFIX=""
67
+ OMD_UPDATE_BREW_CORE_REMOTE=""
68
+ OMD_UPDATE_BREW_CORE_REMOTE_PRESENT=0
69
+ OMD_UPDATE_BREW_CORE_REMOTE_CHANGED=0
64
70
 
65
71
  omd_update_capture_brew_remote() {
66
- local marker_prefix
72
+ local marker_prefix core_prefix
67
73
  omd_module_is_managed linuxbrew || return 0
68
74
  marker_prefix="$(omd_module_marker_value linuxbrew artifact || true)"
69
- [[ -n "${marker_prefix}" && -d "${marker_prefix}" ]] || return 0
75
+ [[ -n "${marker_prefix}" && -d "${marker_prefix}" && -x "${marker_prefix}/bin/brew" ]] || {
76
+ omd_warn "Managed Homebrew prefix is missing or invalid: ${marker_prefix:-<empty>}"
77
+ return 1
78
+ }
79
+ marker_prefix="$(cd "${marker_prefix}" 2>/dev/null && pwd -P)" || return 1
80
+ omd_module_brew_cmd_matches_prefix "${marker_prefix}/bin/brew" "${marker_prefix}" || {
81
+ omd_warn "Managed Homebrew command does not belong to its recorded prefix"
82
+ return 1
83
+ }
70
84
  command -v git >/dev/null 2>&1 || {
71
85
  omd_warn "Git is required to switch the managed Homebrew remote"
72
86
  return 1
@@ -75,50 +89,91 @@ omd_update_capture_brew_remote() {
75
89
  OMD_UPDATE_BREW_PREFIX="${marker_prefix}"
76
90
  if [[ ! -d "${marker_prefix}/.git" ]]; then
77
91
  OMD_UPDATE_BREW_LEGACY=1
78
- return 0
79
- fi
80
- if OMD_UPDATE_BREW_REMOTE="$(git -C "${marker_prefix}" remote get-url origin 2>/dev/null)"; then
81
- OMD_UPDATE_BREW_REMOTE_PRESENT=1
82
92
  else
83
- OMD_UPDATE_BREW_REMOTE=""
84
- OMD_UPDATE_BREW_REMOTE_PRESENT=0
93
+ if OMD_UPDATE_BREW_REMOTE="$(git -C "${marker_prefix}" remote get-url origin 2>/dev/null)"; then
94
+ OMD_UPDATE_BREW_REMOTE_PRESENT=1
95
+ else
96
+ OMD_UPDATE_BREW_REMOTE=""
97
+ OMD_UPDATE_BREW_REMOTE_PRESENT=0
98
+ fi
99
+ fi
100
+
101
+ core_prefix="${marker_prefix}/Library/Taps/homebrew/homebrew-core"
102
+ if [[ -d "${core_prefix}/.git" ]]; then
103
+ OMD_UPDATE_BREW_CORE_PREFIX="${core_prefix}"
104
+ if OMD_UPDATE_BREW_CORE_REMOTE="$(git -C "${core_prefix}" remote get-url origin 2>/dev/null)"; then
105
+ OMD_UPDATE_BREW_CORE_REMOTE_PRESENT=1
106
+ else
107
+ OMD_UPDATE_BREW_CORE_REMOTE=""
108
+ OMD_UPDATE_BREW_CORE_REMOTE_PRESENT=0
109
+ fi
85
110
  fi
86
111
  }
87
112
 
88
113
  omd_update_apply_brew_remote() {
89
- local source="$1" target_remote
114
+ local source="$1" target_remote target_core_remote
90
115
  [[ -n "${OMD_UPDATE_BREW_PREFIX}" ]] || return 0
91
116
  target_remote="$(omd_source_brew_remote "${source}")" || return 1
92
117
  if [[ "${OMD_UPDATE_BREW_LEGACY}" == "1" ]]; then
93
118
  git -C "${OMD_UPDATE_BREW_PREFIX}" init -q || return 1
94
119
  OMD_UPDATE_BREW_REMOTE_CHANGED=1
95
120
  git -C "${OMD_UPDATE_BREW_PREFIX}" remote add origin "${target_remote}" || return 1
96
- return 0
121
+ else
122
+ if [[ "${OMD_UPDATE_BREW_REMOTE_PRESENT}" == "1" ]]; then
123
+ if [[ "${OMD_UPDATE_BREW_REMOTE}" != "${target_remote}" ]]; then
124
+ git -C "${OMD_UPDATE_BREW_PREFIX}" remote set-url origin "${target_remote}" ||
125
+ return 1
126
+ OMD_UPDATE_BREW_REMOTE_CHANGED=1
127
+ fi
128
+ else
129
+ git -C "${OMD_UPDATE_BREW_PREFIX}" remote add origin "${target_remote}" || return 1
130
+ OMD_UPDATE_BREW_REMOTE_CHANGED=1
131
+ fi
97
132
  fi
98
- if [[ "${OMD_UPDATE_BREW_REMOTE_PRESENT}" == "1" ]]; then
99
- [[ "${OMD_UPDATE_BREW_REMOTE}" == "${target_remote}" ]] && return 0
100
- git -C "${OMD_UPDATE_BREW_PREFIX}" remote set-url origin "${target_remote}" || return 1
133
+
134
+ [[ -n "${OMD_UPDATE_BREW_CORE_PREFIX}" ]] || return 0
135
+ target_core_remote="$(omd_source_brew_core_remote "${source}")" || return 1
136
+ if [[ "${OMD_UPDATE_BREW_CORE_REMOTE_PRESENT}" == "1" ]]; then
137
+ if [[ "${OMD_UPDATE_BREW_CORE_REMOTE}" != "${target_core_remote}" ]]; then
138
+ git -C "${OMD_UPDATE_BREW_CORE_PREFIX}" remote set-url origin "${target_core_remote}" ||
139
+ return 1
140
+ OMD_UPDATE_BREW_CORE_REMOTE_CHANGED=1
141
+ fi
101
142
  else
102
- git -C "${OMD_UPDATE_BREW_PREFIX}" remote add origin "${target_remote}" || return 1
143
+ git -C "${OMD_UPDATE_BREW_CORE_PREFIX}" remote add origin "${target_core_remote}" ||
144
+ return 1
145
+ OMD_UPDATE_BREW_CORE_REMOTE_CHANGED=1
103
146
  fi
104
- OMD_UPDATE_BREW_REMOTE_CHANGED=1
105
147
  }
106
148
 
107
149
  omd_update_restore_brew_remote() {
108
- [[ "${OMD_UPDATE_BREW_REMOTE_CHANGED}" == "1" ]] || return 0
109
- if [[ "${OMD_UPDATE_BREW_LEGACY}" == "1" ]]; then
110
- rm -rf "${OMD_UPDATE_BREW_PREFIX}/.git"
111
- return
150
+ local rollback_failed=0
151
+ if [[ "${OMD_UPDATE_BREW_CORE_REMOTE_CHANGED}" == "1" ]]; then
152
+ if [[ "${OMD_UPDATE_BREW_CORE_REMOTE_PRESENT}" == "1" ]]; then
153
+ git -C "${OMD_UPDATE_BREW_CORE_PREFIX}" remote set-url origin "${OMD_UPDATE_BREW_CORE_REMOTE}" ||
154
+ rollback_failed=1
155
+ else
156
+ git -C "${OMD_UPDATE_BREW_CORE_PREFIX}" remote remove origin ||
157
+ rollback_failed=1
158
+ fi
112
159
  fi
113
- if [[ "${OMD_UPDATE_BREW_REMOTE_PRESENT}" == "1" ]]; then
114
- git -C "${OMD_UPDATE_BREW_PREFIX}" remote set-url origin "${OMD_UPDATE_BREW_REMOTE}"
115
- else
116
- git -C "${OMD_UPDATE_BREW_PREFIX}" remote remove origin
160
+ if [[ "${OMD_UPDATE_BREW_REMOTE_CHANGED}" == "1" ]]; then
161
+ if [[ "${OMD_UPDATE_BREW_LEGACY}" == "1" ]]; then
162
+ rm -rf "${OMD_UPDATE_BREW_PREFIX}/.git" || rollback_failed=1
163
+ elif [[ "${OMD_UPDATE_BREW_REMOTE_PRESENT}" == "1" ]]; then
164
+ git -C "${OMD_UPDATE_BREW_PREFIX}" remote set-url origin "${OMD_UPDATE_BREW_REMOTE}" ||
165
+ rollback_failed=1
166
+ else
167
+ git -C "${OMD_UPDATE_BREW_PREFIX}" remote remove origin ||
168
+ rollback_failed=1
169
+ fi
117
170
  fi
171
+ return "${rollback_failed}"
118
172
  }
119
173
 
120
174
  omd_update_abort_with_rollback() {
121
175
  local message="$1" config_dir="$2" snapshot_dir="$3" rollback_failed=0
176
+ omd_source_config_restore "${snapshot_dir}" || rollback_failed=1
122
177
  omd_update_restore_brew_remote || rollback_failed=1
123
178
  omd_update_restore_source_config "${config_dir}" "${snapshot_dir}" || rollback_failed=1
124
179
  if [[ "${rollback_failed}" == "0" ]]; then
@@ -128,10 +183,45 @@ omd_update_abort_with_rollback() {
128
183
  omd_error "${message}; automatic rollback was incomplete; recovery snapshot: ${snapshot_dir}"
129
184
  }
130
185
 
186
+ omd_update_current_source() {
187
+ local config_dir="$1" install_channel="$2" source
188
+ if [[ "${install_channel}" == "npm" ]]; then
189
+ source="${OHMYDEVPOD_NPM_SOURCE:-}"
190
+ if [[ -z "${source}" && -f "${config_dir}/npm-source" ]]; then
191
+ source="$(tr -d '[:space:]' < "${config_dir}/npm-source")"
192
+ fi
193
+ case "${source}" in
194
+ github|gitee)
195
+ printf '%s\n' "${source}"
196
+ return 0
197
+ ;;
198
+ *)
199
+ omd_warn "Invalid npm source '${source:-<empty>}'; falling back to GitHub"
200
+ printf 'github\n'
201
+ return 0
202
+ ;;
203
+ esac
204
+ fi
205
+ omd_read_saved_source "${config_dir}"
206
+ }
207
+
208
+ omd_update_persist_selected_source() {
209
+ local source="$1" config_dir="$2" configure_source="$3" install_channel="$4"
210
+ if [[ "${install_channel}" == "npm" ]]; then
211
+ omd_persist_source "${source}" "${config_dir}" 0 || return 1
212
+ printf '%s\n' "${source}" |
213
+ omd_atomic_write "${config_dir}/npm-source" ||
214
+ return 1
215
+ return 0
216
+ fi
217
+ omd_persist_source "${source}" "${config_dir}" "${configure_source}"
218
+ }
219
+
131
220
  omd_update_main() {
132
221
  local requested_source="" current_source update_source current_version latest_tag latest_version
133
222
  local target prefix bin_dir cache_dir config_dir archive checksum archive_version installed_version
134
- local snapshot_dir="" source_changed=0 configure_source=0 manage_source=0
223
+ local snapshot_dir="" source_changed=0 configure_source=0 manage_source=0 source_only=0
224
+ local install_channel="${OHMYDEVPOD_INSTALL_CHANNEL:-bootstrap}"
135
225
 
136
226
  case "$#" in
137
227
  0) ;;
@@ -148,21 +238,33 @@ omd_update_main() {
148
238
  *) omd_error "Unknown self-update option: $1" ;;
149
239
  esac
150
240
  ;;
241
+ 2)
242
+ [[ "$1" == "--source-only" ]] ||
243
+ omd_error "Use only one of --github or --gitee"
244
+ source_only=1
245
+ configure_source=1
246
+ case "$2" in
247
+ --github) requested_source="github" ;;
248
+ --gitee) requested_source="gitee" ;;
249
+ *) omd_error "Source-only switching requires --github or --gitee" ;;
250
+ esac
251
+ ;;
151
252
  *) omd_error "Use only one of --github or --gitee" ;;
152
253
  esac
153
254
 
154
255
  omd_require_linux
155
- omd_require_command curl
156
- omd_require_command tar
157
- omd_require_command sha256sum
256
+ if [[ "${source_only}" != "1" ]]; then
257
+ omd_require_command curl
258
+ omd_require_command tar
259
+ omd_require_command sha256sum
260
+ fi
158
261
 
159
- target="$(omd_target_triple)"
160
262
  prefix="${OHMYDEVPOD_PREFIX:-${OMD_DEFAULT_PREFIX}}"
161
263
  bin_dir="${OHMYDEVPOD_BIN_DIR:-${OMD_DEFAULT_BIN_DIR}}"
162
264
  cache_dir="${OHMYDEVPOD_CACHE_DIR:-${OMD_DEFAULT_CACHE_DIR}}"
163
265
  config_dir="${OHMYDEVPOD_CONFIG_DIR:-${OMD_DEFAULT_CONFIG_DIR}}"
164
266
  current_version="${OHMYDEVPOD_CURRENT_VERSION:-$(tr -d '[:space:]' < "${bundle_root}/VERSION")}"
165
- current_source="$(omd_read_saved_source "${config_dir}")"
267
+ current_source="$(omd_update_current_source "${config_dir}" "${install_channel}")"
166
268
  update_source="${requested_source:-${current_source}}"
167
269
  [[ "${current_source}" == "${update_source}" ]] || source_changed=1
168
270
  if [[ "${configure_source}" == "1" ]]; then
@@ -174,40 +276,47 @@ omd_update_main() {
174
276
 
175
277
  mkdir -p "${cache_dir}" "$(dirname "${config_dir}")"
176
278
 
177
- if [[ -n "${OHMYDEVPOD_OMD_ARCHIVE:-}" ]]; then
178
- archive="${OHMYDEVPOD_OMD_ARCHIVE}"
179
- checksum="${OHMYDEVPOD_OMD_CHECKSUM:-${archive}.sha256}"
180
- [[ -f "${checksum}" ]] ||
181
- omd_error "Local archive override requires a checksum file: ${checksum}"
182
- omd_verify_checksum "${archive}" "${checksum}" ||
183
- omd_error "Self-update checksum verification failed; current installation and source were preserved"
184
- latest_tag="$(omd_update_archive_version "${archive}" "${cache_dir}")" ||
185
- omd_error "Self-update archive validation failed; current installation and source were preserved"
279
+ if [[ "${source_only}" == "1" ]]; then
280
+ archive=""
281
+ printf 'Current source: %s\n' "${current_source}"
282
+ printf 'New source: %s\n' "${update_source}"
186
283
  else
187
- latest_tag="$(omd_resolve_version "${update_source}" "${OHMYDEVPOD_VERSION:-latest}")" ||
188
- omd_error "Failed to query the latest ${update_source} release; current installation and source were preserved"
189
- fi
190
- latest_version="$(omd_update_normalize_version "${latest_tag}")"
284
+ target="$(omd_target_triple)"
285
+ if [[ -n "${OHMYDEVPOD_OMD_ARCHIVE:-}" ]]; then
286
+ archive="${OHMYDEVPOD_OMD_ARCHIVE}"
287
+ checksum="${OHMYDEVPOD_OMD_CHECKSUM:-${archive}.sha256}"
288
+ [[ -f "${checksum}" ]] ||
289
+ omd_error "Local archive override requires a checksum file: ${checksum}"
290
+ omd_verify_checksum "${archive}" "${checksum}" ||
291
+ omd_error "Self-update checksum verification failed; current installation and source were preserved"
292
+ latest_tag="$(omd_update_archive_version "${archive}" "${cache_dir}")" ||
293
+ omd_error "Self-update archive validation failed; current installation and source were preserved"
294
+ else
295
+ latest_tag="$(omd_resolve_version "${update_source}" "${OHMYDEVPOD_VERSION:-latest}")" ||
296
+ omd_error "Failed to query the latest ${update_source} release; current installation and source were preserved"
297
+ fi
298
+ latest_version="$(omd_update_normalize_version "${latest_tag}")"
191
299
 
192
- printf 'Current version: %s\n' "${current_version}"
193
- printf 'Current source: %s\n' "${current_source}"
194
- printf 'Update source: %s\n' "${update_source}"
195
- printf 'Latest version: %s\n' "${latest_version}"
300
+ printf 'Current version: %s\n' "${current_version}"
301
+ printf 'Current source: %s\n' "${current_source}"
302
+ printf 'Update source: %s\n' "${update_source}"
303
+ printf 'Latest version: %s\n' "${latest_version}"
196
304
 
197
- if [[ "$(omd_update_normalize_version "${current_version}")" != "${latest_version}" ]]; then
198
- if [[ -z "${OHMYDEVPOD_OMD_ARCHIVE:-}" ]]; then
199
- OMD_DOWNLOADED_ARCHIVE=""
200
- OMD_SELECTED_SOURCE=""
201
- omd_download_release "${update_source}" "${latest_tag}" "${target}" "${cache_dir}" ||
202
- omd_error "Self-update download or checksum verification failed; current installation and source were preserved"
203
- archive="${OMD_DOWNLOADED_ARCHIVE}"
204
- archive_version="$(omd_update_archive_version "${archive}" "${cache_dir}")" ||
205
- omd_error "Self-update archive validation failed; current installation and source were preserved"
206
- [[ "$(omd_update_normalize_version "${archive_version}")" == "${latest_version}" ]] ||
207
- omd_error "Release archive version ${archive_version} does not match ${latest_tag}; current installation and source were preserved"
305
+ if [[ "$(omd_update_normalize_version "${current_version}")" != "${latest_version}" ]]; then
306
+ if [[ -z "${OHMYDEVPOD_OMD_ARCHIVE:-}" ]]; then
307
+ OMD_DOWNLOADED_ARCHIVE=""
308
+ OMD_SELECTED_SOURCE=""
309
+ omd_download_release "${update_source}" "${latest_tag}" "${target}" "${cache_dir}" ||
310
+ omd_error "Self-update download or checksum verification failed; current installation and source were preserved"
311
+ archive="${OMD_DOWNLOADED_ARCHIVE}"
312
+ archive_version="$(omd_update_archive_version "${archive}" "${cache_dir}")" ||
313
+ omd_error "Self-update archive validation failed; current installation and source were preserved"
314
+ [[ "$(omd_update_normalize_version "${archive_version}")" == "${latest_version}" ]] ||
315
+ omd_error "Release archive version ${archive_version} does not match ${latest_tag}; current installation and source were preserved"
316
+ fi
317
+ else
318
+ archive=""
208
319
  fi
209
- else
210
- archive=""
211
320
  fi
212
321
 
213
322
  if [[ -n "${archive}" ]]; then
@@ -228,11 +337,23 @@ omd_update_main() {
228
337
  rm -rf "${snapshot_dir}"
229
338
  omd_error "Could not snapshot source configuration"
230
339
  }
340
+ omd_source_config_validate "${update_source}" || {
341
+ rm -rf "${snapshot_dir}"
342
+ omd_error "Installed managed software has user-modified source configuration; current source was preserved"
343
+ }
344
+ omd_source_config_snapshot "${snapshot_dir}" || {
345
+ rm -rf "${snapshot_dir}"
346
+ omd_error "Could not snapshot installed software source configuration"
347
+ }
231
348
  omd_update_capture_brew_remote || {
232
349
  rm -rf "${snapshot_dir}"
233
350
  omd_error "Could not inspect the managed Homebrew remote"
234
351
  }
235
- if ! omd_persist_source "${update_source}" "${config_dir}" "${configure_source}"; then
352
+ if ! omd_update_persist_selected_source \
353
+ "${update_source}" \
354
+ "${config_dir}" \
355
+ "${configure_source}" \
356
+ "${install_channel}"; then
236
357
  omd_update_abort_with_rollback "Could not update source configuration" "${config_dir}" "${snapshot_dir}"
237
358
  fi
238
359
  if ! omd_persist_install_paths "${prefix}" "${bin_dir}" "${cache_dir}" "${config_dir}"; then
@@ -241,6 +362,15 @@ omd_update_main() {
241
362
  if ! omd_update_apply_brew_remote "${update_source}"; then
242
363
  omd_update_abort_with_rollback "Could not switch the managed Homebrew remote" "${config_dir}" "${snapshot_dir}"
243
364
  fi
365
+ if ! omd_source_config_apply "${update_source}"; then
366
+ omd_update_abort_with_rollback "Could not switch installed software source configuration" "${config_dir}" "${snapshot_dir}"
367
+ fi
368
+ fi
369
+
370
+ if [[ "${source_only}" == "1" ]]; then
371
+ [[ -z "${snapshot_dir}" ]] || rm -rf "${snapshot_dir}"
372
+ printf 'Source configuration updated successfully.\n'
373
+ return 0
244
374
  fi
245
375
 
246
376
  if [[ -n "${archive}" ]]; then
@@ -2,6 +2,8 @@
2
2
  set -euo pipefail
3
3
 
4
4
  source "$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)/lib/common.sh"
5
+ # shellcheck source=../lib/source-config.sh
6
+ source "$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)/lib/source-config.sh"
5
7
 
6
8
  component="micromamba"
7
9
  formula="micromamba"
@@ -14,7 +16,15 @@ install_or_update() {
14
16
  shift
15
17
  omd_module_formula_install_or_update "${component}" "${formula}" "${command_name}" "${action}" "$@"
16
18
  }
17
- uninstall() { omd_module_formula_uninstall "${component}" "${formula}" "$@"; }
19
+ uninstall() {
20
+ if omd_module_dry_run "$@"; then
21
+ omd_module_formula_uninstall "${component}" "${formula}" "$@"
22
+ return
23
+ fi
24
+ omd_module_formula_uninstall_keep_marker "${component}" "${formula}" "$@" || return
25
+ omd_source_config_remove_component "${component}" || return
26
+ omd_module_unmark_managed "${component}"
27
+ }
18
28
 
19
29
  case "${1:-}" in
20
30
  status) status ;;
@@ -2,6 +2,8 @@
2
2
  set -euo pipefail
3
3
 
4
4
  source "$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)/lib/common.sh"
5
+ # shellcheck source=../lib/source-config.sh
6
+ source "$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)/lib/source-config.sh"
5
7
 
6
8
  component="uv"
7
9
  formula="uv"
@@ -14,7 +16,15 @@ install_or_update() {
14
16
  shift
15
17
  omd_module_formula_install_or_update "${component}" "${formula}" "${command_name}" "${action}" "$@"
16
18
  }
17
- uninstall() { omd_module_formula_uninstall "${component}" "${formula}" "$@"; }
19
+ uninstall() {
20
+ if omd_module_dry_run "$@"; then
21
+ omd_module_formula_uninstall "${component}" "${formula}" "$@"
22
+ return
23
+ fi
24
+ omd_module_formula_uninstall_keep_marker "${component}" "${formula}" "$@" || return
25
+ omd_source_config_remove_component "${component}" || return
26
+ omd_module_unmark_managed "${component}"
27
+ }
18
28
 
19
29
  case "${1:-}" in
20
30
  status) status ;;
@@ -188,9 +188,8 @@ omd_module_brew_cmd() {
188
188
  return 1
189
189
  }
190
190
 
191
- omd_module_brew_formula_installed() {
192
- local formula="$1" formula_name prefix cellar version
193
- prefix="$(omd_module_brew_prefix)" || return 1
191
+ omd_module_brew_formula_installed_at() {
192
+ local prefix="$1" formula="$2" formula_name cellar version
194
193
  formula_name="${formula##*/}"
195
194
  cellar="${prefix}/Cellar/${formula_name}"
196
195
  [[ -d "${cellar}" ]] || return 1
@@ -200,16 +199,40 @@ omd_module_brew_formula_installed() {
200
199
  return 1
201
200
  }
202
201
 
202
+ omd_module_brew_formula_installed() {
203
+ local formula="$1" prefix
204
+ prefix="$(omd_module_brew_prefix)" || return 1
205
+ omd_module_brew_formula_installed_at "${prefix}" "${formula}"
206
+ }
207
+
208
+ omd_module_brew_prefix_for_cmd() {
209
+ local brew="$1" prefix
210
+ prefix="$(omd_module_brew_exec "${brew}" --prefix 2>/dev/null || true)"
211
+ if [[ "${prefix}" == /* && -d "${prefix}" ]]; then
212
+ cd "${prefix}" 2>/dev/null && pwd -P
213
+ return
214
+ fi
215
+ [[ "${brew}" == */bin/brew ]] || return 1
216
+ cd "$(dirname "${brew}")/.." 2>/dev/null && pwd -P
217
+ }
218
+
219
+ omd_module_brew_cmd_matches_prefix() {
220
+ local brew="$1" expected_prefix="$2" resolved_brew reported_prefix
221
+ expected_prefix="$(cd "${expected_prefix}" 2>/dev/null && pwd -P)" || return 1
222
+ if [[ -L "${brew}" ]]; then
223
+ command -v readlink >/dev/null 2>&1 || return 1
224
+ resolved_brew="$(readlink -f "${brew}" 2>/dev/null || true)"
225
+ [[ "${resolved_brew}" == "${expected_prefix}"/* ]] || return 1
226
+ fi
227
+ reported_prefix="$(omd_module_brew_prefix_for_cmd "${brew}")" || return 1
228
+ [[ "${reported_prefix}" == "${expected_prefix}" ]]
229
+ }
230
+
203
231
  omd_module_brew_prefix() {
204
- local brew resolved
232
+ local brew
205
233
  brew="$(omd_module_brew_cmd)" || return 1
206
- if command -v readlink >/dev/null 2>&1; then
207
- resolved="$(readlink -f "${brew}" 2>/dev/null || true)"
208
- [[ -z "${resolved}" ]] || brew="${resolved}"
209
- fi
210
- if [[ "${brew}" == */bin/brew ]]; then
211
- cd "$(dirname "${brew}")/.." 2>/dev/null && pwd -P
212
- return
234
+ if omd_module_brew_prefix_for_cmd "${brew}"; then
235
+ return 0
213
236
  fi
214
237
  if [[ -n "${HOMEBREW_PREFIX:-}" && -d "${HOMEBREW_PREFIX}" ]]; then
215
238
  printf '%s\n' "${HOMEBREW_PREFIX}"
@@ -231,9 +254,10 @@ omd_module_brew_exec() {
231
254
  }
232
255
 
233
256
  omd_module_formula_status() {
234
- local formula="$1" command_name="$2"
257
+ local formula="$1" command_name="$2" prefix
235
258
  if [[ -n "${component:-}" ]] && omd_module_formula_managed "${component}" "${formula}"; then
236
- omd_module_brew_formula_installed "${formula}"
259
+ prefix="$(omd_module_formula_marker_prefix "${component}" "${formula}")" || return 1
260
+ omd_module_brew_formula_installed_at "${prefix}" "${formula}"
237
261
  return
238
262
  fi
239
263
  command -v "${command_name}" >/dev/null 2>&1 ||
@@ -241,12 +265,40 @@ omd_module_formula_status() {
241
265
  }
242
266
 
243
267
  omd_module_formula_managed() {
244
- local component="$1" formula="$2"
245
- omd_module_marker_matches "${component}" "${formula}"
268
+ local component="$1" formula="$2" kind
269
+ omd_module_marker_matches "${component}" "${formula}" || return 1
270
+ kind="$(omd_module_marker_value "${component}" kind || true)"
271
+ [[ "${kind}" == "brew-formula" ]]
272
+ }
273
+
274
+ omd_module_formula_marker_prefix() {
275
+ local component="$1" formula="$2" prefix linuxbrew_kind
276
+ omd_module_formula_managed "${component}" "${formula}" || return 1
277
+ prefix="$(omd_module_marker_value "${component}" brew_prefix || true)"
278
+ if [[ -z "${prefix}" ]] && omd_module_is_managed linuxbrew; then
279
+ linuxbrew_kind="$(omd_module_marker_value linuxbrew kind || true)"
280
+ if [[ "${linuxbrew_kind}" == "directory" ]]; then
281
+ prefix="$(omd_module_marker_value linuxbrew artifact || true)"
282
+ if ! omd_module_brew_formula_installed_at "${prefix}" "${formula}"; then
283
+ prefix=""
284
+ fi
285
+ fi
286
+ fi
287
+ [[ -n "${prefix}" && "${prefix}" == /* && ! -L "${prefix}" && -x "${prefix}/bin/brew" ]] ||
288
+ return 1
289
+ prefix="$(cd "${prefix}" 2>/dev/null && pwd -P)" || return 1
290
+ omd_module_brew_cmd_matches_prefix "${prefix}/bin/brew" "${prefix}" || return 1
291
+ printf '%s\n' "${prefix}"
292
+ }
293
+
294
+ omd_module_formula_brew_cmd() {
295
+ local component="$1" formula="$2" prefix
296
+ prefix="$(omd_module_formula_marker_prefix "${component}" "${formula}")" || return 1
297
+ printf '%s/bin/brew\n' "${prefix}"
246
298
  }
247
299
 
248
300
  omd_module_formula_install_or_update() {
249
- local component="$1" formula="$2" command_name="$3" action="$4"
301
+ local component="$1" formula="$2" command_name="$3" action="$4" brew brew_prefix
250
302
  shift 4
251
303
  omd_module_reject_unknown_flags "$@" || return
252
304
 
@@ -261,24 +313,38 @@ omd_module_formula_install_or_update() {
261
313
  return 0
262
314
  fi
263
315
 
264
- local brew
265
- brew="$(omd_module_brew_cmd)" || {
266
- omd_module_info error "Linuxbrew is required before ${component}"
316
+ if omd_module_formula_managed "${component}" "${formula}"; then
317
+ brew="$(omd_module_formula_brew_cmd "${component}" "${formula}")" || {
318
+ omd_module_info error "managed ${component} has no valid owning Homebrew prefix"
319
+ return 1
320
+ }
321
+ else
322
+ brew="$(omd_module_brew_cmd)" || {
323
+ omd_module_info error "Linuxbrew is required before ${component}"
324
+ return 1
325
+ }
326
+ fi
327
+ brew_prefix="$(omd_module_brew_prefix_for_cmd "${brew}")" || {
328
+ omd_module_info error "could not determine Homebrew prefix for ${component}"
267
329
  return 1
268
330
  }
269
331
 
270
332
  if [[ "${action}" == "update" ]] &&
271
- omd_module_brew_exec "${brew}" list --formula "${formula}" >/dev/null 2>&1; then
333
+ omd_module_brew_formula_installed_at "${brew_prefix}" "${formula}"; then
272
334
  omd_module_brew_exec "${brew}" upgrade "${formula}"
273
335
  else
274
336
  omd_module_brew_exec "${brew}" install "${formula}"
275
337
  fi
276
- omd_module_mark_managed "${component}" brew-formula "${formula}"
338
+ omd_module_mark_managed \
339
+ "${component}" \
340
+ brew-formula \
341
+ "${formula}" \
342
+ "brew_prefix=${brew_prefix}"
277
343
  }
278
344
 
279
- omd_module_formula_uninstall() {
280
- local component="$1" formula="$2"
281
- shift 2
345
+ omd_module_formula_uninstall_impl() {
346
+ local component="$1" formula="$2" remove_marker="$3"
347
+ shift 3
282
348
  omd_module_reject_unknown_flags "$@" || return
283
349
 
284
350
  if omd_module_dry_run "$@"; then
@@ -289,11 +355,18 @@ omd_module_formula_uninstall() {
289
355
  omd_module_formula_managed "${component}" "${formula}" ||
290
356
  omd_module_refuse_unmanaged "${component}" || return
291
357
 
292
- local brew dependants
293
- brew="$(omd_module_brew_cmd)" || {
294
- omd_module_info error "Linuxbrew is required to uninstall ${component}"
358
+ local brew brew_prefix dependants
359
+ brew="$(omd_module_formula_brew_cmd "${component}" "${formula}")" || {
360
+ omd_module_info error "managed ${component} has no valid owning Homebrew prefix"
295
361
  return 1
296
362
  }
363
+ brew_prefix="$(omd_module_brew_prefix_for_cmd "${brew}")" || return 1
364
+ if ! omd_module_brew_formula_installed_at "${brew_prefix}" "${formula}"; then
365
+ if [[ "${remove_marker}" == "1" ]]; then
366
+ omd_module_unmark_managed "${component}"
367
+ fi
368
+ return 0
369
+ fi
297
370
  if ! dependants="$(omd_module_brew_exec "${brew}" uses --installed "${formula}" 2>&1)"; then
298
371
  omd_module_info error "failed to inspect Homebrew dependants for ${component}: ${dependants}"
299
372
  return 1
@@ -303,7 +376,21 @@ omd_module_formula_uninstall() {
303
376
  return 1
304
377
  fi
305
378
  omd_module_brew_exec "${brew}" uninstall "${formula}"
306
- omd_module_unmark_managed "${component}"
379
+ if [[ "${remove_marker}" == "1" ]]; then
380
+ omd_module_unmark_managed "${component}"
381
+ fi
382
+ }
383
+
384
+ omd_module_formula_uninstall() {
385
+ local component="$1" formula="$2"
386
+ shift 2
387
+ omd_module_formula_uninstall_impl "${component}" "${formula}" 1 "$@"
388
+ }
389
+
390
+ omd_module_formula_uninstall_keep_marker() {
391
+ local component="$1" formula="$2"
392
+ shift 2
393
+ omd_module_formula_uninstall_impl "${component}" "${formula}" 0 "$@"
307
394
  }
308
395
 
309
396
  omd_module_zsh_path() {
@@ -2,12 +2,28 @@
2
2
  set -euo pipefail
3
3
 
4
4
  source "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/common.sh"
5
+ # shellcheck source=source-config.sh
6
+ source "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/source-config.sh"
5
7
 
6
8
  case "${1:-}" in
7
9
  install|update) ;;
8
10
  *) omd_module_unknown_action "${1:-}" ;;
9
11
  esac
10
12
 
13
+ case "${OHMYDEVPOD_MIRROR_PROFILE:-upstream}" in
14
+ cn) source_name="gitee" ;;
15
+ upstream) source_name="github" ;;
16
+ *)
17
+ omd_module_info notice "unknown mirror profile; native source configuration was not changed"
18
+ source_name=""
19
+ ;;
20
+ esac
21
+ if [[ -n "${source_name}" ]] &&
22
+ ! omd_source_config_apply_transactional "${source_name}"; then
23
+ omd_module_info error "failed to apply native source configuration"
24
+ exit 1
25
+ fi
26
+
11
27
  if ! omd_module_is_managed zsh && ! omd_module_is_managed zsh-config; then
12
28
  exit 0
13
29
  fi