Skip to content

Commit 6d30dac

Browse files
authored
Pass resolved install dir to PATH profile
1 parent eb1c24e commit 6d30dac

1 file changed

Lines changed: 13 additions & 10 deletions

File tree

scripts/install.sh

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -257,37 +257,40 @@ install_binary() {
257257
}
258258

259259
path_update_script() {
260+
local install_dir="$1"
261+
260262
printf '%s\n' \
261263
'# Surround PATH with colons so case matching guards against partial directory names,' \
262264
'# such as treating /usr/local/binary as a match for /usr/local/bin.' \
263265
'case ":${PATH:-}:" in' \
264-
" *:\"$INSTALL_DIR\":*) ;;" \
265-
" *) export PATH=\"$INSTALL_DIR\${PATH:+:\$PATH}\" ;;" \
266+
" *:\"$install_dir\":*) ;;" \
267+
" *) export PATH=\"$install_dir\${PATH:+:\$PATH}\" ;;" \
266268
'esac'
267269
}
268270

269271
configure_install_dir_path() {
270-
local expected_profile install_dir_was_in_path profile_dir
272+
local expected_profile install_dir install_dir_was_in_path profile_dir
273+
install_dir="$INSTALL_DIR"
271274
profile_dir=$(dirname "$PATH_PROFILE")
272275
install_dir_was_in_path=false
273276

274277
case ":${PATH:-}:" in
275-
*:"$INSTALL_DIR":*) install_dir_was_in_path=true ;;
278+
*:"$install_dir":*) install_dir_was_in_path=true ;;
276279
esac
277280

278281
if ! mkdir -p "$profile_dir"; then
279282
log_error "Failed to create PATH profile directory: $profile_dir"
280283
return 1
281284
fi
282285

283-
expected_profile=$(path_update_script)
286+
expected_profile=$(path_update_script "$install_dir")
284287
if ! printf '%s\n' "$expected_profile" > "$PATH_PROFILE"; then
285288
log_error "Failed to write PATH profile to: $PATH_PROFILE. Check permissions and available disk space."
286289
return 1
287290
fi
288291

289292
if ! printf '%s\n' "$expected_profile" | cmp -s - "$PATH_PROFILE"; then
290-
log_error "Content verification failed for PATH profile: $PATH_PROFILE. The file may have been modified by another process or the disk write may have failed."
293+
log_error "Content verification failed for PATH profile: $PATH_PROFILE. The disk write may not have completed successfully."
291294
return 1
292295
fi
293296

@@ -298,18 +301,18 @@ configure_install_dir_path() {
298301

299302
# Source only after verifying the profile so this session uses the same logic as future shells.
300303
if ! . "$PATH_PROFILE"; then
301-
log_error "Failed to apply PATH profile: $PATH_PROFILE"
304+
log_error "Failed to source PATH profile: $PATH_PROFILE. The profile may contain shell syntax errors."
302305
return 1
303306
fi
304307

305308
case ":${PATH:-}:" in
306-
*:"$INSTALL_DIR":*)
309+
*:"$install_dir":*)
307310
if [[ "$install_dir_was_in_path" != "true" ]]; then
308-
log_info "Added $INSTALL_DIR to PATH for this installer session"
311+
log_info "Added $install_dir to PATH for this installer session"
309312
fi
310313
;;
311314
*)
312-
log_error "Failed to add $INSTALL_DIR to PATH after sourcing $PATH_PROFILE. The PATH profile may not have executed correctly."
315+
log_error "Failed to add $install_dir to PATH after sourcing $PATH_PROFILE. Verify the profile logic matches the current shell environment."
313316
return 1
314317
;;
315318
esac

0 commit comments

Comments
 (0)