Last active
October 25, 2019 06:16
-
-
Save akram/f9c20d694472ca0727652e610f237f06 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# This script takes 1 mandatory parameter: the short gist url and 1 optionnal: the destination | |
# directory for the donwloaded kubeconfig | |
# It downloads the kubeconfig file from gist and sets KUBECONFIG variable pointing to it locally | |
# url is in the form of: https://gist.github.com/287f2ccee282c01e8ffb532763c20a86 | |
# full_url will be : https://gist.githubusercontent.com/<user>/287f2ccee282c01e8ffb532763c20a86/raw/kubeconfig | |
url=$1 | |
dest_dir=${2:-$HOME} | |
dest_file=$( realpath $dest_dir/kubeconfig ) | |
github_content_url=https://gist.githubusercontent.com | |
kubeconfig_raw_path=raw/kubeconfig | |
redirect_url=$( curl -o /dev/null -s -w "%{redirect_url}" $url ) | |
user=$(echo $redirect_url | cut -f 4 -d/ ) | |
token=$(echo $redirect_url | cut -f 5 -d/ ) | |
full_url="$github_content_url/$user/$token/$kubeconfig_raw_path" | |
curl -ks $full_url -o $dest_file | |
echo "Setting KUBECONFIG to $dest_file after getting it from $full_url" | |
export KUBECONFIG=$dest_file | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment