0
0
mirror of https://github.com/tj/n.git synced 2024-11-21 18:48:57 +01:00

mask download url when there is a password (#815)

This commit is contained in:
jinxiao 2024-10-04 06:07:21 +08:00 committed by GitHub
parent 6051073a6a
commit cf40ac5e0a
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

14
bin/n
View File

@ -197,6 +197,10 @@ display_major_version() {
echo "${version}" echo "${version}"
} }
display_masked_url() {
echo "$1" | sed -r 's/(https?:\/\/[^:]+):([^@]+)@/\1:****@/'
}
# #
# Synopsis: update_mirror_settings_for_version version # Synopsis: update_mirror_settings_for_version version
# e.g. <nightly/latest> means using download mirror and folder is nightly # e.g. <nightly/latest> means using download mirror and folder is nightly
@ -793,7 +797,7 @@ install() {
log installing "${g_mirror_folder_name}-v$version" log installing "${g_mirror_folder_name}-v$version"
local url="$(tarball_url "$version")" local url="$(tarball_url "$version")"
is_ok "${url}" || abort "download preflight failed for '$version' (${url})" is_ok "${url}" || abort "download preflight failed for '$version' ($(display_masked_url "${url}"))"
log mkdir "$dir" log mkdir "$dir"
mkdir -p "$dir" || abort "sudo required (or change ownership, or define N_PREFIX)" mkdir -p "$dir" || abort "sudo required (or change ownership, or define N_PREFIX)"
@ -801,7 +805,7 @@ install() {
cd "${dir}" || abort "Failed to cd to ${dir}" cd "${dir}" || abort "Failed to cd to ${dir}"
log fetch "$url" log fetch "$(display_masked_url "${url}")"
do_get "${url}" | tar "$tarflag" --strip-components=1 --no-same-owner -f - do_get "${url}" | tar "$tarflag" --strip-components=1 --no-same-owner -f -
pipe_results=( "${PIPESTATUS[@]}" ) pipe_results=( "${PIPESTATUS[@]}" )
if [[ "${pipe_results[0]}" -ne 0 ]]; then if [[ "${pipe_results[0]}" -ne 0 ]]; then
@ -1241,7 +1245,7 @@ display_remote_index() {
do_get_index "${index_url}" | tail -n +2 | cut -f 1,3,10 do_get_index "${index_url}" | tail -n +2 | cut -f 1,3,10
if [[ "${PIPESTATUS[0]}" -ne 0 ]]; then if [[ "${PIPESTATUS[0]}" -ne 0 ]]; then
# Reminder: abort will only exit subshell, but consistent error display # Reminder: abort will only exit subshell, but consistent error display
abort "failed to download version index (${index_url})" abort "failed to download version index ($(display_masked_url "${index_url}"))"
fi fi
} }
@ -1494,8 +1498,8 @@ function show_diagnostics() {
printf "\n\nSETTINGS\n" printf "\n\nSETTINGS\n"
printf "\nn\n" printf "\nn\n"
echo "node mirror: ${N_NODE_MIRROR}" echo "node mirror: $(display_masked_url "${N_NODE_MIRROR}")"
echo "node downloads mirror: ${N_NODE_DOWNLOAD_MIRROR}" echo "node downloads mirror: $(display_masked_url "${N_NODE_DOWNLOAD_MIRROR}")"
echo "install destination: ${N_PREFIX}" echo "install destination: ${N_PREFIX}"
[[ -n "${N_PREFIX}" ]] && echo "PATH: ${PATH}" [[ -n "${N_PREFIX}" ]] && echo "PATH: ${PATH}"
echo "ls-remote max matches: ${N_MAX_REMOTE_MATCHES}" echo "ls-remote max matches: ${N_MAX_REMOTE_MATCHES}"