|
3 | 3 | # Version: v0.59.0 |
4 | 4 |
|
5 | 5 | __wrap__() { |
| 6 | + # Function to mask username and password in URLs for safe printing |
| 7 | + # Usage: mask_credentials "url" |
| 8 | + # Returns the URL with credentials replaced by ***:***@ |
| 9 | + # |
| 10 | + # [^:@/]+ - This matches the username part: |
| 11 | + # - [^:@/] means "any character EXCEPT :, @, or /" |
| 12 | + # - + means "one or more of these characters" |
| 13 | + # - So it captures everything up until it hits a colon, at-sign, or slash |
| 14 | + # - : - Matches the literal colon that separates username from password |
| 15 | + # |
| 16 | + # [^@/]+ - This matches the password part: |
| 17 | + # - [^@/] means "any character EXCEPT @ or /" |
| 18 | + # - + means "one or more of these characters" |
| 19 | + # - So it captures everything after the colon until it hits an at-sign or slash |
| 20 | + # - @ - Matches the literal at-sign that |
| 21 | + mask_credentials() { |
| 22 | + URL="$1" |
| 23 | + # Use sed to replace username:password@ pattern with ***:***@ |
| 24 | + echo "$URL" | sed -E 's|://[^:@/]+:[^@/]+@|://***:***@|g' |
| 25 | + } |
| 26 | + |
6 | 27 | VERSION="${PIXI_VERSION:-latest}" |
7 | 28 | PIXI_HOME="${PIXI_HOME:-$HOME/.pixi}" |
8 | 29 | case "$PIXI_HOME" in |
@@ -44,7 +65,7 @@ __wrap__() { |
44 | 65 | DOWNLOAD_URL="${PIXI_DOWNLOAD_URL:-${REPOURL%/}/releases/download/v${VERSION#v}/${BINARY}${EXTENSION-}}" |
45 | 66 | fi |
46 | 67 |
|
47 | | - printf "This script will automatically download and install Pixi (%s) for you.\nGetting it from this url: %s\n" "$VERSION" "$DOWNLOAD_URL" |
| 68 | + printf "This script will automatically download and install Pixi (%s) for you.\nGetting it from this url: %s\n" "$VERSION" "$(mask_credentials "$DOWNLOAD_URL")" |
48 | 69 |
|
49 | 70 | HAVE_CURL=false |
50 | 71 | HAVE_CURL_8_8_0=false |
@@ -93,33 +114,46 @@ __wrap__() { |
93 | 114 | WGET_OPTIONS="--show-progress" |
94 | 115 | fi |
95 | 116 |
|
| 117 | + # Use .netrc for authentication - prioritize NETRC env var over default location |
| 118 | + if [ -n "${NETRC:-}" ]; then |
| 119 | + CURL_OPTIONS="$CURL_OPTIONS --netrc-file $NETRC" |
| 120 | + WGET_OPTIONS="$WGET_OPTIONS --netrc-file=$NETRC" |
| 121 | + elif [ -f "$HOME/.netrc" ]; then |
| 122 | + CURL_OPTIONS="$CURL_OPTIONS --netrc" |
| 123 | + WGET_OPTIONS="$WGET_OPTIONS --netrc" |
| 124 | + fi |
| 125 | + |
96 | 126 | if $HAVE_CURL; then |
97 | 127 | CURL_ERR=0 |
98 | 128 | HTTP_CODE="$(curl -SL $CURL_OPTIONS "$DOWNLOAD_URL" --output "$TEMP_FILE" --write-out "%{http_code}")" || CURL_ERR=$? |
99 | 129 | case "$CURL_ERR" in |
100 | 130 | 35 | 53 | 54 | 59 | 66 | 77) |
101 | 131 | if ! $HAVE_WGET; then |
102 | | - echo "error: when download '${DOWNLOAD_URL}', curl has some local ssl problems with error $CURL_ERR" >&2 |
| 132 | + echo "error: when download '$(mask_credentials "$DOWNLOAD_URL")', curl has some local ssl problems with error $CURL_ERR" >&2 |
103 | 133 | exit 1 |
104 | 134 | fi |
105 | 135 | # fallback to wget |
106 | 136 | ;; |
107 | 137 | 0) |
108 | | - if [ "${HTTP_CODE}" -lt 200 ] || [ "${HTTP_CODE}" -gt 299 ]; then |
109 | | - echo "error: '${DOWNLOAD_URL}' is not available" >&2 |
| 138 | + if [ "${HTTP_CODE}" -eq 401 ]; then |
| 139 | + echo "error: authentication failed when downloading '$(mask_credentials "$DOWNLOAD_URL")'" >&2 |
| 140 | + echo " Check your .netrc file, NETRC environment variable, or the hardcoded credentials in PIXI_DOWNLOAD_URL." >&2 |
| 141 | + exit 1 |
| 142 | + elif [ "${HTTP_CODE}" -lt 200 ] || [ "${HTTP_CODE}" -gt 299 ]; then |
| 143 | + echo "error: '$(mask_credentials "$DOWNLOAD_URL")' is not available (HTTP ${HTTP_CODE})" >&2 |
110 | 144 | exit 1 |
111 | 145 | fi |
112 | 146 | HAVE_WGET=false # download success, skip wget |
113 | 147 | ;; |
114 | 148 | *) |
115 | | - echo "error: when download '${DOWNLOAD_URL}', curl fails with with error $CURL_ERR" >&2 |
| 149 | + echo "error: when download '$(mask_credentials "$DOWNLOAD_URL")', curl fails with error $CURL_ERR" >&2 |
116 | 150 | exit 1 |
117 | 151 | ;; |
118 | 152 | esac |
119 | 153 | fi |
120 | 154 |
|
121 | 155 | if $HAVE_WGET && ! wget $WGET_OPTIONS --output-document="$TEMP_FILE" "$DOWNLOAD_URL"; then |
122 | | - echo "error: '${DOWNLOAD_URL}' is not available" >&2 |
| 156 | + echo "error: '$(mask_credentials "$DOWNLOAD_URL")' is not available" >&2 |
123 | 157 | exit 1 |
124 | 158 | fi |
125 | 159 |
|
|
0 commit comments