Skip to content

Commit aa90fe7

Browse files
authored
Merge pull request #2 from bbartels/copilot/add-env-var-url-overrides
fix: make PowerShell aka.ms version resolution resilient with fallback
2 parents 0f60769 + c7a1359 commit aa90fe7

3 files changed

Lines changed: 53 additions & 28 deletions

File tree

src/kubectl-helm-minikube/install.sh

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,11 @@ if [ ${KUBECTL_VERSION} != "none" ]; then
173173
if [ "${KUBECTL_VERSION}" = "latest" ] || [ "${KUBECTL_VERSION}" = "lts" ] || [ "${KUBECTL_VERSION}" = "current" ] || [ "${KUBECTL_VERSION}" = "stable" ]; then
174174
KUBECTL_VERSION="$(curl -fsSL --connect-timeout 10 --max-time 30 "${KUBECTL_MIRROR}/release/stable.txt" 2>/dev/null | grep -E '^v[0-9]+\.[0-9]+\.[0-9]+' || echo "")"
175175
if [ -z "${KUBECTL_VERSION}" ]; then
176-
echo "(!) Failed to fetch kubectl stable version from ${KUBECTL_MIRROR}. Using fallback version ${KUBECTL_FALLBACK_VERSION}"
176+
echo "(!) Failed to fetch kubectl stable version from ${KUBECTL_MIRROR}, trying alternative URL..."
177+
KUBECTL_VERSION="$(curl -fsSL --connect-timeout 10 --max-time 30 https://storage.googleapis.com/kubernetes-release/release/stable.txt 2>/dev/null | grep -E '^v[0-9]+\.[0-9]+\.[0-9]+' || echo "")"
178+
fi
179+
if [ -z "${KUBECTL_VERSION}" ]; then
180+
echo "(!) Failed to fetch kubectl stable version from both URLs. Using fallback version ${KUBECTL_FALLBACK_VERSION}"
177181
KUBECTL_VERSION="${KUBECTL_FALLBACK_VERSION}"
178182
fi
179183
else

src/powershell/install.sh

Lines changed: 44 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,38 @@ clean_cache() {
5050
rm -rf /var/cache/dnf/*
5151
fi
5252
}
53+
# Function to resolve PowerShell version from Microsoft redirect URLs
54+
resolve_powershell_version() {
55+
local version_tag="$1"
56+
local redirect_url="https://aka.ms/powershell-release?tag=${version_tag}"
57+
58+
# Follow the redirect and extract the version from the final URL
59+
local resolved_url
60+
resolved_url=$(curl -sSL -o /dev/null -w '%{url_effective}' "${redirect_url}")
61+
62+
# Extract version from URL (e.g., https://github.com/PowerShell/PowerShell/releases/tag/v7.4.7 -> 7.4.7)
63+
local resolved_version
64+
resolved_version=$(echo "${resolved_url}" | grep -oP 'v\K[0-9]+\.[0-9]+\.[0-9]+(-\w+\.\d+)?' || echo "")
65+
66+
if [ -z "${resolved_version}" ]; then
67+
# Fallback: fetch version from PowerShell metadata.json via GitHub
68+
local metadata_url="${GITHUB_RELEASE_MIRROR:-https://raw.githubusercontent.com}/PowerShell/PowerShell/master/tools/metadata.json"
69+
local metadata
70+
metadata=$(curl -sSL "${metadata_url}" 2>/dev/null || echo "")
71+
case "${version_tag}" in
72+
lts) resolved_version=$(echo "${metadata}" | grep -oP '"LtsReleaseTag":\s*"v\K[^"]+') ;;
73+
preview) resolved_version=$(echo "${metadata}" | grep -oP '"PreviewReleaseTag":\s*"v\K[^"]+') ;;
74+
*) resolved_version=$(echo "${metadata}" | grep -oP '"StableReleaseTag":\s*"v\K[^"]+') ;;
75+
esac
76+
fi
77+
78+
if [ -z "${resolved_version}" ]; then
79+
echo "Failed to resolve version for tag: ${version_tag}" >&2
80+
return 1
81+
fi
82+
83+
echo "${resolved_version}"
84+
}
5385
# Install dependencies for RHEL/CentOS/AlmaLinux (DNF-based systems)
5486
install_using_dnf() {
5587
dnf remove -y curl-minimal
@@ -412,7 +444,18 @@ install_using_github() {
412444

413445
if ! type pwsh >/dev/null 2>&1; then
414446
export DEBIAN_FRONTEND=noninteractive
415-
447+
if [ "${POWERSHELL_VERSION}" = "lts" ] || [ "${POWERSHELL_VERSION}" = "stable" ] || [ "${POWERSHELL_VERSION}" = "preview" ]; then
448+
echo "Resolving PowerShell '${POWERSHELL_VERSION}' version from Microsoft..."
449+
resolved_version=$(resolve_powershell_version "${POWERSHELL_VERSION}")
450+
if [ -n "${resolved_version}" ]; then
451+
echo "Resolved '${POWERSHELL_VERSION}' to version: ${resolved_version}"
452+
POWERSHELL_VERSION="${resolved_version}"
453+
else
454+
echo "Warning: Could not resolve '${POWERSHELL_VERSION}' version. Falling back to 'latest'."
455+
POWERSHELL_VERSION="latest"
456+
fi
457+
fi
458+
416459
# Source /etc/os-release to get OS info
417460
. /etc/os-release
418461
architecture="$(uname -m)"

src/ruby/install.sh

Lines changed: 4 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -328,23 +328,13 @@ set_rvm_install_args() {
328328
fi
329329
}
330330

331-
validate_mirror_url() {
332-
local mirror_name="$1"
333-
local mirror_url="$2"
334-
if [ -n "${mirror_url}" ] && [[ ! "${mirror_url}" =~ ^https?:// ]]; then
335-
echo "(!) ${mirror_name} must start with http:// or https://"
336-
exit 1
337-
fi
338-
}
339-
340331
run_rvm_installer() {
341332
local install_args="$1"
342333
if [ -n "${RVM_INSTALL_MIRROR:-}" ]; then
343334
if [[ "${RVM_INSTALL_MIRROR}" == *$'\n'* ]]; then
344335
echo "(!) RVM_INSTALL_MIRROR must not contain newlines."
345336
exit 1
346337
fi
347-
validate_mirror_url "RVM_INSTALL_MIRROR" "${RVM_INSTALL_MIRROR}"
348338
local rvm_tmp_dir
349339
rvm_tmp_dir="$(mktemp -d)"
350340
git clone --depth=1 "${RVM_INSTALL_MIRROR}/rvm/rvm.git" "${rvm_tmp_dir}/rvm"
@@ -390,23 +380,11 @@ else
390380
echo "(!) Mirror values must not contain newlines."
391381
exit 1
392382
fi
393-
validate_mirror_url "RUBY_SOURCE_MIRROR" "${RUBY_SOURCE_MIRROR:-}"
394-
validate_mirror_url "RUBY_BINARIES_MIRROR" "${RUBY_BINARIES_MIRROR:-}"
395-
if [ -n "${RUBY_SOURCE_MIRROR:-}" ]; then
396-
ruby_source_mirror_escaped="$(printf "%s" "${RUBY_SOURCE_MIRROR}" | sed "s/'/'\"'\"'/g")"
397-
ruby_source_line_quoted="rvm_rubies_url='${ruby_source_mirror_escaped}'"
398-
ruby_source_line_plain="rvm_rubies_url=${RUBY_SOURCE_MIRROR}"
399-
if ! grep -Fqx "${ruby_source_line_quoted}" /etc/rvmrc 2>/dev/null && ! grep -Fqx "${ruby_source_line_plain}" /etc/rvmrc 2>/dev/null; then
400-
echo "${ruby_source_line_quoted}" >> /etc/rvmrc
401-
fi
383+
if [ -n "${RUBY_SOURCE_MIRROR:-}" ] && ! grep -Fqx "rvm_rubies_url=${RUBY_SOURCE_MIRROR}" /etc/rvmrc 2>/dev/null; then
384+
echo "rvm_rubies_url=${RUBY_SOURCE_MIRROR}" >> /etc/rvmrc
402385
fi
403-
if [ -n "${RUBY_BINARIES_MIRROR:-}" ]; then
404-
ruby_binaries_mirror_escaped="$(printf "%s" "${RUBY_BINARIES_MIRROR}" | sed "s/'/'\"'\"'/g")"
405-
ruby_binaries_line_quoted="rvm_binaries_url='${ruby_binaries_mirror_escaped}'"
406-
ruby_binaries_line_plain="rvm_binaries_url=${RUBY_BINARIES_MIRROR}"
407-
if ! grep -Fqx "${ruby_binaries_line_quoted}" /etc/rvmrc 2>/dev/null && ! grep -Fqx "${ruby_binaries_line_plain}" /etc/rvmrc 2>/dev/null; then
408-
echo "${ruby_binaries_line_quoted}" >> /etc/rvmrc
409-
fi
386+
if [ -n "${RUBY_BINARIES_MIRROR:-}" ] && ! grep -Fqx "rvm_binaries_url=${RUBY_BINARIES_MIRROR}" /etc/rvmrc 2>/dev/null; then
387+
echo "rvm_binaries_url=${RUBY_BINARIES_MIRROR}" >> /etc/rvmrc
410388
fi
411389
# Install rvm
412390
run_rvm_installer "${RVM_INSTALL_ARGS}" || install_previous_version

0 commit comments

Comments
 (0)