From 66f166efb3908b4a7c346ea64e90069ee6f20f7b Mon Sep 17 00:00:00 2001 From: Ilya Kogan Date: Wed, 3 Sep 2025 17:38:57 +0000 Subject: [PATCH 1/7] Attempt to fix MacOS - Reexec into zsh if available - Allow instructions to be used without `gum` - Fix version comparison so it works with RKE2 - Fix available namespace issues in ZSH --- adp-connect.sh | 166 ++++++++++++++++++++++++++++--------------------- 1 file changed, 95 insertions(+), 71 deletions(-) diff --git a/adp-connect.sh b/adp-connect.sh index 22fa901..432e3ee 100755 --- a/adp-connect.sh +++ b/adp-connect.sh @@ -1,4 +1,4 @@ -#!/bin/bash +#!/usr/bin/env bash HAVE_GUM="$(which gum 2>/dev/null && 'true')" TEMP_DIR=$(mktemp -d) SCRIPT_SOURCE_BRANCH="${SCRIPT_SOURCE_BRANCH:-main}" @@ -10,6 +10,7 @@ FORCE_ADD_MORE_RANCHERS="${FORCE_ADD_MORE_RANCHERS:-""}" FORCE_ADD_MORE_ARGOCD="${FORCE_ADD_MORE_ARGOCD:-""}" FORCE_ADD_MORE_GITHUB="${FORCE_ADD_MORE_GITHUB:-""}" FORCE_TRACE_MODE="${FORCE_TRACE_MODE:-"false"}" +FORCE_CURRENT_SHELL="${FORCE_CURRENT_SHELL:-"false"}" ONLY_DOWNLOAD="${ONLY_DOWNLOAD:-""}" ACCEPT_SUPPLY_CHAIN_SECURITY="${ACCEPT_SUPPLY_CHAIN_SECURITY:-""}" DEFAULT_RANCHER_HOSTNAME="rancher.oit.ohio.edu" @@ -84,13 +85,17 @@ info() { } instruction() { - gum style \ - --border-foreground=212 \ - --border=double \ - --align=center \ - --width=70 \ - --margin="1 2" \ - --padding="2 4 " "$1" + if [[ "${HAVE_GUM}" ]]; then + gum style \ + --border-foreground=212 \ + --border=double \ + --align=center \ + --width=70 \ + --margin="1 2" \ + --padding="2 4 " "$1" + else + echo -e "\e[35mℹ️ $1\e[0m" + fi } warn() { @@ -134,23 +139,26 @@ get_artifactory_token() { } compare_versions() { - # Copilot wrote this one and I'm too lazy to fully verify or grok it. - # Remove leading 'v' if present - ver1="${1#v}" - ver2="${2#v}" - - IFS='.' read -r -a ver1 <<< "$ver1" - IFS='.' read -r -a ver2 <<< "$ver2" - - for ((i=0; i<${#ver1[@]}; i++)); do - if [[ ${ver1[i]} -gt ${ver2[i]:-0} ]]; then - return 1 - elif [[ ${ver1[i]} -lt ${ver2[i]:-0} ]]; then - return 2 - fi - done + # Remove leading 'v' if present + local ver1="${1#v}" + local ver2="${2#v}" + + local IFS='.' + # shellcheck disable=SC2206 + local ver1_arr=($ver1) + # shellcheck disable=SC2206 + local ver2_arr=($ver2) + + local i + for ((i=0; i<${#ver1_arr[@]}; i++)); do + if [[ ${ver1_arr[i]} -gt ${ver2_arr[i]:-0} ]]; then + return 1 + elif [[ ${ver1_arr[i]} -lt ${ver2_arr[i]:-0} ]]; then + return 2 + fi + done - return 0 + return 0 } version_sort() { @@ -367,6 +375,7 @@ rancher_login() { rancher_token_credential=$(rancher token --server "${rancher_hostname}" --user="$(whoami)") fi + # shellcheck disable=SC2181 if [[ "$?" -ne 0 ]]; then error "❌ Error: Failed to login to Rancher." exit 1 @@ -374,6 +383,7 @@ rancher_login() { rancher_token=$(echo "${rancher_token_credential}" | yq -r '.status.token') + # shellcheck disable=SC2181 if [[ "$?" -ne 0 ]] || [[ -z "$rancher_token" ]]; then error "❌ Error: Failed to get parse token response from Rancher." exit 1 @@ -469,18 +479,19 @@ setup_kube_context() { RANCHER_CURRENT_CLUSTER=$(rancher context current | sed -n 's/.*Cluster:\([^ ]*\).*/\1/p') AVAILABLE_NAMESPACES=$(gum spin --show-error --title="Fetching namespaces you have access to..." -- rancher namespaces -q) + # shellcheck disable=SC2181 if [[ "$?" -ne 0 ]]; then warn "There was an error communicating with the ${RANCHER_CURRENT_CLUSTER} cluster. Please select a different cluster and project." AVAILABLE_NAMESPACES="" else - AVAILABLE_NAMESPACES=$(echo "${AVAILABLE_NAMESPACES}" | sort | tr '\n' ' ') + AVAILABLE_NAMESPACES=$(echo "${AVAILABLE_NAMESPACES}" | sort) if [[ -z "${AVAILABLE_NAMESPACES}" ]]; then warn "You don't seem to have access to any namespaces in the $(rancher context current) context. Please select a different cluster and project." DEFAULT_NAMESPACE="" else info "Select your default namespace:" - DEFAULT_NAMESPACE=$(gum choose --select-if-one --ordered ${AVAILABLE_NAMESPACES}) # Note, the variable is unquoted intentionally. + DEFAULT_NAMESPACE=$(echo "${AVAILABLE_NAMESPACES}" | gum choose --select-if-one --ordered) if ! [[ "$DEFAULT_NAMESPACE" =~ ^[a-z0-9]([-a-z0-9]*[a-z0-9])?$ ]]; then warn "The namespace you selected (${DEFAULT_NAMESPACE}) is not a valid Kubernetes namespace name. This should not happen, please let ADP know and select a differnt namespace." @@ -496,37 +507,6 @@ setup_kube_context() { KUBECONFIG="$HOME/.kube/config.incomplete" kubectl config use-context "${RANCHER_CURRENT_CLUSTER}" >/dev/null } -ALL_BINARIES_AVAILABLE="true" -for BINARY in curl tar awk sed grep git; do - if ! which "${BINARY}" &>/dev/null; then - error "❌ Error: ${BINARY} is required but not installed. Please contact ADP for assistance and let us know what operating system you're using." - ALL_BINARIES_AVAILABLE="false" - fi -done - -if [[ "${ALL_BINARIES_AVAILABLE}" = "false" ]]; then - exit 1 -fi - -git check-ref-format --branch "${SCRIPT_SOURCE_BRANCH}" >/dev/null || exit 1 - -if ! grep --help | grep -q 'extended-regexp'; then - error "❌ Error: Your version of grep does not support extended regular expressions. PPlease contact ADP for assistance and let us know what operating system you're using." - exit 1 -fi - -if ! bash -c 'help readarray' &>/dev/null; then - error "❌ Error: Your version of bash does not support readarray. Please contact ADP for assistance and let us know what operating system you're using." - exit 1 -fi - -if ! [[ -d "$HOME/.local/bin" ]]; then - if ! mkdir -p "${HOME}"/.local/bin 2>/dev/null; then - echo "❌ Error: Failed to create directory ${HOME}/.local/bin. Please check your permissions or available disk space." - exit 1 - fi -fi - while getopts "udThIRAGDKSac:s:r:g:" arg; do case $arg in h) echo "Usage: $0 [options]" @@ -571,6 +551,18 @@ while getopts "udThIRAGDKSac:s:r:g:" arg; do esac done +ALL_BINARIES_AVAILABLE="true" +for BINARY in curl tar awk sed grep git; do + if ! which "${BINARY}" &>/dev/null; then + error "❌ Error: ${BINARY} is required but not installed. Please contact ADP for assistance and let us know what operating system you're using." + ALL_BINARIES_AVAILABLE="false" + fi +done + +if [[ "${ALL_BINARIES_AVAILABLE}" = "false" ]]; then + exit 1 +fi + if ! [ -t 0 ] && [[ "${ONLY_DOWNLOAD}" != "true" ]]; then echo "Looks like you're running non-interactive, like from 'curl'." echo "Since this tool asks a lot of questions, it cannot be run this way. Installing to ${HOME}/.local/bin..." @@ -611,6 +603,31 @@ adp-connect, use `adp-connect -h` for help.' exit 1 fi +if ! [ "${FORCE_CURRENT_SHELL}" = "true" ]; then + if which zsh &>/dev/null && ! [ -z "${BASH}" ]; then + exec zsh "$0" "$@" + fi +fi + +if [ -n "${ZSH_NAME}" ]; then + debug "Running in ZSH!" +elif [ -z "${BASH}" ]; then + warn "Running in an unknown shell. This script has only been tested in bash and zsh, you may run into issues." +fi + +git check-ref-format --branch "${SCRIPT_SOURCE_BRANCH}" >/dev/null || exit 1 + +if ! (grep --help 2>/dev/null | grep -q 'extended-regexp') && ! (which sw_vers >/dev/null && [ "$(sw_vers | grep ProductName | awk '{print $2}' | tr '[:upper:]' '[:lower:]')" = "macos" ]); then + error "❌ Error: Your version of grep does not support extended regular expressions. Please contact ADP for assistance and let us know what operating system you're using." + exit 1 +fi + +if ! [[ -d "$HOME/.local/bin" ]]; then + if ! mkdir -p "${HOME}"/.local/bin 2>/dev/null; then + echo "❌ Error: Failed to create directory ${HOME}/.local/bin. Please check your permissions or available disk space." + exit 1 + fi +fi if [[ -z "${ACCEPT_SUPPLY_CHAIN_SECURITY}" ]]; then if ! confirm "⚠️ This script will utilize a series of resources from \ @@ -755,15 +772,21 @@ if [[ ! "${ONLY_DOWNLOAD}" = "true" ]]; then debug "Switching to Rancher server ${SERVER}..." rancher server switch "${SERVER}" 2> >(grep -v "Saving config" >&2) >/dev/null for CLUSTER in $(rancher cluster list | grep -v CURRENT | sed 's/^*//g' | awk '{ print $1 }'); do - if [[ -z "${SKIP_KUBECONFIG}" ]]; then - TEMP_KUBE_CONFIG=$(echo "${SERVER}-${CLUSTER}" | base64) - gum spin --show-error --title="Fetching kubeconfig for cluster ${CLUSTER}..." -- rancher cluster kf "${CLUSTER}" > "${TEMP_DIR}/${TEMP_KUBE_CONFIG}.yaml" - KUBE_CONFIGS+=("${TEMP_DIR}/${TEMP_KUBE_CONFIG}.yaml") - fi - KUBE_CLUSTER_VERSIONS+=("$(rancher inspect --type=cluster "${CLUSTER}" | yq -r '.version.gitVersion')") + if [[ -z "${SKIP_KUBECONFIG}" ]]; then + TEMP_KUBE_CONFIG=$(echo "${SERVER}-${CLUSTER}" | base64) + gum spin --show-error --title="Fetching kubeconfig for cluster ${CLUSTER}..." -- rancher cluster kf "${CLUSTER}" > "${TEMP_DIR}/${TEMP_KUBE_CONFIG}.yaml" + KUBE_CONFIGS+=("${TEMP_DIR}/${TEMP_KUBE_CONFIG}.yaml") + fi + KUBE_CLUSTER_VERSIONS+=("$(rancher inspect --type=cluster "${CLUSTER}" | yq -r '.version.gitVersion' | sed -E 's/^([vV]?[0-9]+\.[0-9]+\.[0-9]+).*/\1/')") done done - readarray -t KUBE_CLUSTER_VERSIONS < <(printf '%s\n' "${KUBE_CLUSTER_VERSIONS[@]}" | sort -u) + + # Deduplicate and sort KUBE_CLUSTER_VERSIONS + KUBE_CLUSTER_VERSIONS_UNIQUE=() + while IFS= read -r line; do + KUBE_CLUSTER_VERSIONS_UNIQUE+=("$line") + done < <(printf '%s\n' "${KUBE_CLUSTER_VERSIONS[@]}" | sort -u) + KUBE_CLUSTER_VERSIONS=("${KUBE_CLUSTER_VERSIONS_UNIQUE[@]}") debug "Found the following Kubernetes versions: ${KUBE_CLUSTER_VERSIONS[*]}" @@ -799,7 +822,6 @@ if [[ ! "${ONLY_DOWNLOAD}" = "true" ]]; then if [[ -f "$HOME/.kube/config.bak" ]]; then for CONTEXT in $(yq eval -o json -I=0 '.contexts[]' "$HOME/.kube/config.bak"); do - NAMESPACE=$(yq -r '.context.namespace' <<< "${CONTEXT}") NAME=$(yq -r '.name' <<< "${CONTEXT}") if [[ -z "$(yq -r '.contexts[] | select(.name == "'"${NAME}"'")' "$HOME/.kube/config" 2>/dev/null)" ]]; then @@ -811,10 +833,11 @@ if [[ ! "${ONLY_DOWNLOAD}" = "true" ]]; then if [[ -n "${KUBE_CURRENT_CONTEXT}" ]]; then KUBECONFIG="$HOME/.kube/config.incomplete" kubectl config use-context "${KUBE_CURRENT_CONTEXT}" >/dev/null - CURRENT_NAMESPACE=$(kubectl config view --minify --output 'jsonpath={.contexts[?(@.name=="'$(kubectl config current-context)'")].context.namespace}') - CURRENT_CLUSTER_URL=$(kubectl config view --minify --output 'jsonpath={.clusters[?(@.name=="'$(kubectl config current-context)'")].cluster.server}') + CURRENT_NAMESPACE=$(kubectl config view --minify --output 'jsonpath={.contexts[?(@.name=="'"$(kubectl config current-context)"'")].context.namespace}') + CURRENT_CLUSTER_URL=$(kubectl config view --minify --output 'jsonpath={.clusters[?(@.name=="'"$(kubectl config current-context)"'")].cluster.server}') + # shellcheck disable=SC2001 CURRENT_RANCHER_SERVER_URL=$(echo "${CURRENT_CLUSTER_URL}" | sed -e 's|^\([^:/]*://[^/]*\).*|\1|') - CURRENT_RANCHER_SERVER_NAME=$(rancher server ls | sed 's/^*//g' | grep -v CURRENT | awk '{ print $1 }' | grep "^${CURRENT_RANCHER_SERVER_URL}$") + CURRENT_RANCHER_SERVER_NAME=$(rancher server ls | sed 's/^*//g' | grep -v CURRENT | grep "${CURRENT_RANCHER_SERVER_URL}" | awk '{ print $1 }') debug "Current namespace: ${CURRENT_NAMESPACE}" debug "Current cluster URL: ${CURRENT_CLUSTER_URL}" @@ -834,10 +857,11 @@ if [[ ! "${ONLY_DOWNLOAD}" = "true" ]]; then setup_kube_context fi - NEW_NAMESPACE=$(KUBECONFIG="$HOME/.kube/config.incomplete" kubectl config view --minify --output 'jsonpath={.contexts[?(@.name=="'$(KUBECONFIG="$HOME/.kube/config.incomplete" kubectl config current-context)'")].context.namespace}') - NEW_CLUSTER_URL=$(KUBECONFIG="$HOME/.kube/config.incomplete" kubectl config view --minify --output 'jsonpath={.clusters[?(@.name=="'$(KUBECONFIG="$HOME/.kube/config.incomplete" kubectl config current-context)'")].cluster.server}') + NEW_NAMESPACE=$(KUBECONFIG="$HOME/.kube/config.incomplete" kubectl config view --minify --output 'jsonpath={.contexts[?(@.name=="'"$(KUBECONFIG="$HOME/.kube/config.incomplete" kubectl config current-context)"'")].context.namespace}') + NEW_CLUSTER_URL=$(KUBECONFIG="$HOME/.kube/config.incomplete" kubectl config view --minify --output 'jsonpath={.clusters[?(@.name=="'"$(KUBECONFIG="$HOME/.kube/config.incomplete" kubectl config current-context)"'")].cluster.server}') + # shellcheck disable=SC2001 NEW_RANCHER_SERVER_URL=$(echo "${NEW_CLUSTER_URL}" | sed -e 's|^\([^:/]*://[^/]*\).*|\1|') - NEW_RANCHER_SERVER_NAME=$(rancher server ls | sed 's/^*//g' | grep -v CURRENT | awk '{ print $2 }' | grep "^${NEW_RANCHER_SERVER_URL}$") + NEW_RANCHER_SERVER_NAME=$(rancher server ls | sed 's/^*//g' | grep -v CURRENT | grep "${NEW_RANCHER_SERVER_URL}" | awk '{ print $1 }') if [[ -z "${NEW_NAMESPACE}" ]] && [[ -n "${CURRENT_NAMESPACE}" ]]; then debug "New kubeconfig doesn't have a namespace set on the current context, this is likely a weirdness from merging. Reusing the old namespace." From f1ddec9230e339515ec7163e98e0fd8b9c056525 Mon Sep 17 00:00:00 2001 From: Ilya Kogan Date: Wed, 3 Sep 2025 18:26:54 +0000 Subject: [PATCH 2/7] Need to create bin directory before trying to install ourselves. --- adp-connect.sh | 32 +++++++++++++++++++------------- 1 file changed, 19 insertions(+), 13 deletions(-) diff --git a/adp-connect.sh b/adp-connect.sh index 432e3ee..4decb42 100755 --- a/adp-connect.sh +++ b/adp-connect.sh @@ -226,7 +226,7 @@ download_latest_release() { done if [[ -z "$binary_url" ]]; then - error "❌ Error: Could not find the binary $binary_name for $LOCAL_OS/$LOCAL_ARCH in the latest release." + error "❌ Error: Could not find the binary $binary_name for $LOCAL_OS/${LOCAL_ARCH[0]} in the latest release." if [[ "${ENABLE_DEBUG}" = "true" ]]; then if which yq &>/dev/null; then @@ -355,6 +355,7 @@ rancher_login() { fi # Remove protocol if present + # shellcheck disable=SC2001 rancher_hostname=$(echo "$rancher_hostname" | sed -e 's|^[a-zA-Z]*://||') if [[ -e "${HOME}/.rancher/cli2.json" ]] && [[ "$(rancher server ls | grep -c "${rancher_hostname}")" -gt 1 ]]; then @@ -462,6 +463,11 @@ setup_kube_context() { exit 1 fi + instruction "It's time to setup the default Kubernetes cluster, project, and namespace you'll be using. \ +You'll be presented with lists and asked to pick a number; pay attention to the columns. You'll first select \ +your default Rancher server (if you have multiple) and then your Cluster and Project. Look for the row with \ +the project you'll use most often and enter the number in the first column." + DEFAULT_NAMESPACE="" RANCHER_CURRENT_CLUSTER="" @@ -563,6 +569,13 @@ if [[ "${ALL_BINARIES_AVAILABLE}" = "false" ]]; then exit 1 fi +if ! [[ -d "$HOME/.local/bin" ]]; then + if ! mkdir -p "${HOME}"/.local/bin 2>/dev/null; then + echo "❌ Error: Failed to create directory ${HOME}/.local/bin. Please check your permissions or available disk space." + exit 1 + fi +fi + if ! [ -t 0 ] && [[ "${ONLY_DOWNLOAD}" != "true" ]]; then echo "Looks like you're running non-interactive, like from 'curl'." echo "Since this tool asks a lot of questions, it cannot be run this way. Installing to ${HOME}/.local/bin..." @@ -597,8 +610,8 @@ if ! [ -t 0 ] && [[ "${ONLY_DOWNLOAD}" != "true" ]]; then fi # shellcheck disable=SC2016 - echo 'adp-connect has been installed, please re-run it in a terminal with the command \ -adp-connect, use `adp-connect -h` for help.' + echo 'adp-connect has been installed, please re-run it in a terminal with the command + adp-connect, use `adp-connect -h` for help.' exit 1 fi @@ -622,13 +635,6 @@ if ! (grep --help 2>/dev/null | grep -q 'extended-regexp') && ! (which sw_vers > exit 1 fi -if ! [[ -d "$HOME/.local/bin" ]]; then - if ! mkdir -p "${HOME}"/.local/bin 2>/dev/null; then - echo "❌ Error: Failed to create directory ${HOME}/.local/bin. Please check your permissions or available disk space." - exit 1 - fi -fi - if [[ -z "${ACCEPT_SUPPLY_CHAIN_SECURITY}" ]]; then if ! confirm "⚠️ This script will utilize a series of resources from \ the internet. The integrity of these cannot be assured, are you sure you want to \ @@ -1166,7 +1172,7 @@ if [[ "${SETUP_INTERNAL_SERVICES}" = "true" ]]; then helm repo update fi - - info "🎉 Everything should now be setup. You should have the following tools installed and ready to use:" - ls -1 "${HOME}"/.local/bin fi + +info "🎉 Everything should now be setup. You should have the following tools installed and ready to use:" +ls -1 "${HOME}"/.local/bin From df4e3aff766a041b7a597bc0231b75280a73689c Mon Sep 17 00:00:00 2001 From: Ilya Kogan Date: Wed, 3 Sep 2025 20:00:10 +0000 Subject: [PATCH 3/7] Fix checking for gum in zsh. --- adp-connect.sh | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/adp-connect.sh b/adp-connect.sh index 4decb42..1ec2176 100755 --- a/adp-connect.sh +++ b/adp-connect.sh @@ -1,5 +1,5 @@ #!/usr/bin/env bash -HAVE_GUM="$(which gum 2>/dev/null && 'true')" +HAVE_GUM="$(which gum &>/dev/null && echo 'true')" TEMP_DIR=$(mktemp -d) SCRIPT_SOURCE_BRANCH="${SCRIPT_SOURCE_BRANCH:-main}" SCRIPT_SOURCE_URL="https://raw.githubusercontent.com/ohioit/vscode-devcontainer-base/refs/heads/${SCRIPT_SOURCE_BRANCH}/adp-connect.sh" @@ -116,9 +116,10 @@ error() { confirm() { if [[ "${HAVE_GUM}" ]]; then - gum confirm --default=No "$1" < /dev/tty + gum confirm --default=No "$1" else - read -p "$1 [y/N] " -n 1 -r < /dev/tty + echo -n "$1 [y/N] " + read -n 1 -r echo [[ $REPLY =~ ^[Yy]$ ]] fi From f788cdeda82f4f1953df01ebb6a543690e351bc4 Mon Sep 17 00:00:00 2001 From: Ilya Kogan Date: Wed, 3 Sep 2025 20:14:49 +0000 Subject: [PATCH 4/7] Don't use `-r` in read. --- adp-connect.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/adp-connect.sh b/adp-connect.sh index 1ec2176..287ddf2 100755 --- a/adp-connect.sh +++ b/adp-connect.sh @@ -119,7 +119,7 @@ confirm() { gum confirm --default=No "$1" else echo -n "$1 [y/N] " - read -n 1 -r + read -n 1 echo [[ $REPLY =~ ^[Yy]$ ]] fi From e8cb8ddc8e956dc4fc549552dd3231f0fd64b3ce Mon Sep 17 00:00:00 2001 From: Ilya Kogan Date: Wed, 3 Sep 2025 20:37:14 +0000 Subject: [PATCH 5/7] Rewrite confirm so iti mitigates read differences. --- adp-connect.sh | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/adp-connect.sh b/adp-connect.sh index 287ddf2..24b9d1b 100755 --- a/adp-connect.sh +++ b/adp-connect.sh @@ -1,5 +1,5 @@ #!/usr/bin/env bash -HAVE_GUM="$(which gum &>/dev/null && echo 'true')" +#HAVE_GUM="$(which gum &>/dev/null && echo 'true')" TEMP_DIR=$(mktemp -d) SCRIPT_SOURCE_BRANCH="${SCRIPT_SOURCE_BRANCH:-main}" SCRIPT_SOURCE_URL="https://raw.githubusercontent.com/ohioit/vscode-devcontainer-base/refs/heads/${SCRIPT_SOURCE_BRANCH}/adp-connect.sh" @@ -118,9 +118,25 @@ confirm() { if [[ "${HAVE_GUM}" ]]; then gum confirm --default=No "$1" else - echo -n "$1 [y/N] " - read -n 1 - echo + REPLY="" + + while true; do + echo -n "$1 [y/N] " + # shellcheck disable=SC2162 + read REPLY + echo + + if [[ -z "${REPLY}" ]]; then + REPLY="Y" + fi + + if [[ "${REPLY}" =~ ^[YyNn]$ ]]; then + break + fi + + echo "${REPLY} is not valid, please enter Y or N" + done + [[ $REPLY =~ ^[Yy]$ ]] fi } From aa212b3a14567385491cf9b326a51f8bb9f8612c Mon Sep 17 00:00:00 2001 From: Ilya Kogan Date: Wed, 3 Sep 2025 20:39:21 +0000 Subject: [PATCH 6/7] Don't use long options with install. --- adp-connect.sh | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/adp-connect.sh b/adp-connect.sh index 24b9d1b..42838f6 100755 --- a/adp-connect.sh +++ b/adp-connect.sh @@ -668,7 +668,7 @@ fi if should_install "gum"; then download_latest_release "charmbracelet/gum" "gum" "tar.gz" || exit 1 extract_download "gum" "tar.gz" || exit 1 - install --mode=0755 "${TEMP_DIR}/gum"*/"gum" "$HOME/.local/bin/gum" || exit 1 + install -m "0755" "${TEMP_DIR}/gum"*/"gum" "$HOME/.local/bin/gum" || exit 1 info "🎉 Successfully installed gum!" HAVE_GUM="true" @@ -678,7 +678,7 @@ fi # JSON and YAML. One tool, no interperters needed. if should_install "yq"; then INSANE_CHECKSUMS="true" download_latest_release "mikefarah/yq" "yq" || exit 1 - install --mode=0755 "${TEMP_DIR}/yq" "$HOME/.local/bin/yq" || exit 1 + install -m "0755" "${TEMP_DIR}/yq" "$HOME/.local/bin/yq" || exit 1 info "🎉 Successfully installed yq!" elif ! yq --version | grep -q mikefarah; then error "🚨 You have a version of 'yq' installed that is incompatible with this script." @@ -703,7 +703,7 @@ fi if [[ "${INSTALL_RANCHER}" = "0" ]]; then download_latest_release "rancher/cli" "rancher" "tar.gz" || exit 1 extract_download "rancher" "tar.gz" || exit 1 - install --mode=0755 "${TEMP_DIR}/rancher"*/"rancher" "$HOME/.local/bin/rancher" || exit 1 + install -m "0755" "${TEMP_DIR}/rancher"*/"rancher" "$HOME/.local/bin/rancher" || exit 1 info "🎉 Successfully installed rancher CLI!" fi @@ -928,7 +928,7 @@ fi if should_install "kubeseal"; then download_latest_release "bitnami-labs/sealed-secrets" "kubeseal" "tar.gz" || exit 1 extract_download "kubeseal" "tar.gz" || exit 1 - install --mode=0755 "${TEMP_DIR}/kubeseal" "$HOME/.local/bin/kubeseal" || exit 1 + install -m "0755" "${TEMP_DIR}/kubeseal" "$HOME/.local/bin/kubeseal" || exit 1 info "🎉 Successfully installed kubeseal!" fi @@ -976,13 +976,13 @@ fi if should_install "k9s"; then download_latest_release "derailed/k9s" "k9s" "tar.gz" || exit 1 extract_download "k9s" "tar.gz" || exit 1 - install --mode=0755 "${TEMP_DIR}/k9s" "$HOME/.local/bin/k9s" || exit 1 + install -m "0755" "${TEMP_DIR}/k9s" "$HOME/.local/bin/k9s" || exit 1 info "🎉 Successfully installed k9s!" fi if should_install "skaffold"; then download_latest_release "GoogleContainerTools/skaffold" "skaffold" || exit 1 - install --mode=0755 "${TEMP_DIR}/skaffold" "$HOME/.local/bin/skaffold" || exit 1 + install -m "0755" "${TEMP_DIR}/skaffold" "$HOME/.local/bin/skaffold" || exit 1 info "🎉 Successfully installed skaffold!" fi @@ -990,7 +990,7 @@ if should_install "gh"; then download_latest_release "cli/cli" "gh" "tar.gz" || exit 1 extract_download "gh" "tar.gz" || exit 1 mv "${TEMP_DIR}"/gh_* "${TEMP_DIR}/gh" - install --mode=0755 "${TEMP_DIR}/gh/bin/gh" "$HOME/.local/bin/gh" || exit 1 + install -m "0755" "${TEMP_DIR}/gh/bin/gh" "$HOME/.local/bin/gh" || exit 1 info "🎉 Successfully installed gh!" fi @@ -1102,7 +1102,7 @@ if [[ "${SETUP_INTERNAL_SERVICES}" = "true" ]]; then if should_install "argocd"; then download_latest_release "argoproj/argo-cd" "argocd" || exit 1 - install --mode=0755 "${TEMP_DIR}/argocd" "$HOME/.local/bin/argocd" || exit 1 + install -m "0755" "${TEMP_DIR}/argocd" "$HOME/.local/bin/argocd" || exit 1 info "🎉 Successfully installed ArgoCD!" fi From 248b99d31918e9f7977e2c65d5c61d238b7d9b92 Mon Sep 17 00:00:00 2001 From: Ilya Kogan Date: Wed, 3 Sep 2025 21:36:47 +0000 Subject: [PATCH 7/7] Fixes for Mac OS and cluster migration. - Attempt to fix downloads when a format isn't specified on Mac OS - When a project and cluster no longer exist, handle it gracefully by clearing the project. --- adp-connect.sh | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/adp-connect.sh b/adp-connect.sh index 42838f6..1662402 100755 --- a/adp-connect.sh +++ b/adp-connect.sh @@ -1,5 +1,5 @@ #!/usr/bin/env bash -#HAVE_GUM="$(which gum &>/dev/null && echo 'true')" +HAVE_GUM="$(which gum &>/dev/null && echo 'true')" TEMP_DIR=$(mktemp -d) SCRIPT_SOURCE_BRANCH="${SCRIPT_SOURCE_BRANCH:-main}" SCRIPT_SOURCE_URL="https://raw.githubusercontent.com/ohioit/vscode-devcontainer-base/refs/heads/${SCRIPT_SOURCE_BRANCH}/adp-connect.sh" @@ -235,7 +235,11 @@ download_latest_release() { latest_release=$(echo "${latest_release_json}" | grep -e '"tag_name"' | sed -E 's/.*"tag_name": "([^"]+)".*/\1/') for arch in "${LOCAL_ARCH[@]}"; do - binary_url=$(echo "$latest_release_json" | grep -Ei "browser_download_url.*$binary_name.*$LOCAL_OS.*$arch(.*$latest_release)?(\.|$format)\"" | cut -d '"' -f 4) + if [[ -n "$format" ]]; then + binary_url=$(echo "$latest_release_json" | grep -Ei "browser_download_url.*$binary_name.*$LOCAL_OS.*$arch(.*$latest_release)?(\.|$format)\"" | cut -d '"' -f 4) + else + binary_url=$(echo "$latest_release_json" | grep -Ei "browser_download_url.*$binary_name.*$LOCAL_OS.*$arch(.*$latest_release)?" | cut -d '"' -f 4) + fi if [[ -n "$binary_url" ]]; then break @@ -768,6 +772,7 @@ if [[ ! "${ONLY_DOWNLOAD}" = "true" ]]; then rancher server switch "${SERVER}" 2> >(grep -v "Saving config" >&2) >/dev/null if ! gum spin --show-error --title="Checking ${SERVER}..." rancher project list; then + yq -i '.Servers["'"${SERVER}"'"].project = ""' "$HOME/.rancher/cli2.json" rancher_login "${SERVER}" fi done