From e97d09e7d913b72f893f92154be2e005f683d6f0 Mon Sep 17 00:00:00 2001 From: Jonas Forsberg Date: Thu, 7 Jul 2022 19:09:57 +0200 Subject: [PATCH] added tools and common --- .functions/common.sh | 16 ++++++++++ .functions/tools.sh | 76 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 92 insertions(+) create mode 100644 .functions/common.sh create mode 100644 .functions/tools.sh diff --git a/.functions/common.sh b/.functions/common.sh new file mode 100644 index 0000000..15500f9 --- /dev/null +++ b/.functions/common.sh @@ -0,0 +1,16 @@ +function asktobreak(){ + if [[ "$ANSWER_YES" == true ]];then + printf "\n" + return 1 + fi + printf "Do you want to run this step (y/n)" + while read -r -n 1 -s answer; do + if [[ $answer == [YyNn] ]];then + [[ $answer == [Yy] ]] && return_value=1 + [[ $answer == [Nn] ]] && return_value=0 + printf "\n" + break; + fi + done + return $return_value +} diff --git a/.functions/tools.sh b/.functions/tools.sh new file mode 100644 index 0000000..03f65ef --- /dev/null +++ b/.functions/tools.sh @@ -0,0 +1,76 @@ +function upgrade_tools(){ + new_log "Install client tools" + echo "- kubectl" + echo "- helm" + echo "- stern" + echo "- virtctl" + if asktobreak; then + return + fi + + set +e + echo "---- kubectl ----" + cd $HOME/bin + if [[ -f kubectl ]]; then + KUBECTL_CURRENT=$(./kubectl version --client 2> /dev/null| sed -n 's/.* GitVersion:"\(v[0-9]*\.[0-9]*\.[0-9]*\)".*/\1/p') + else + KUBECTL_CURRENT="N/A" + fi + KUBECTL_STABLE="$(curl -L -s https://dl.k8s.io/release/stable.txt)" + echo "Installed version: $KUBECTL_CURRENT" + echo "Latest stable version: $KUBECTL_STABLE" + if [[ "$KUBECTL_CURRENT" != "$KUBECTL_STABLE" ]]; then + echo "updating to $KUBECTL_STABLE" + curl -LO https://dl.k8s.io/release/$KUBECTL_STABLE/bin/linux/amd64/kubectl + chmod +x kubectl + fi + echo "" + echo "---- helm ----" + if [[ -f helm ]]; then + HELM_CURRENT=$(./helm version | sed -n 's/.*Version:"\(v[0-9]*\.[0-9]*\.[0-9]*\)".*/\1/p') + else + HELM_CURRENT="N/A" + fi + HELM_STABLE="$(curl -Ls https://github.com/helm/helm/releases | egrep 'href="/helm/helm/releases/tag/v[0-9]+.[0-9]+.[0-9]+\"' | head -n 1 | sed -n 's/.*tag\/\(v.*\)" data.*/\1/p')" + echo "Installed version: $HELM_CURRENT" + echo "Latest stable version: $HELM_STABLE" + if [[ "$HELM_CURRENT" != "$HELM_STABLE" ]]; then + echo "updating to $HELM_STABLE" + curl -LO https://get.helm.sh/helm-$HELM_STABLE-linux-amd64.tar.gz + tar xvzf helm-$HELM_STABLE-linux-amd64.tar.gz --strip-components=1 linux-amd64/helm + rm helm-$HELM_STABLE-linux-amd64.tar.gz + fi + echo "" + echo "---- stern ----" + if [[ -f stern ]]; then + STERN_CURRENT="v$(./stern -v | head -n1 | cut -d " " -f2)" + else + STERN_CURRENT="N/A" + fi + STERN_STABLE="$(curl -Ls https://github.com/stern/stern/releases | egrep 'href="/stern/stern/releases/tag/v[0-9]+.[0-9]+.[0-9]+*\"' | head -n 1 | sed -n 's/.*tag\/\(v.*\)" data.*/\1/p')" + echo "Installed version: $STERN_CURRENT" + echo "Latest stable version: $STERN_STABLE" + if [[ "$STERN_CURRENT" != "$STERN_STABLE" ]]; then + echo "updating to $STERN_STABLE" + curl -LO https://github.com/stern/stern/releases/download/$STERN_STABLE/stern_${STERN_STABLE:1}_linux_amd64.tar.gz + tar xvzf stern_${STERN_STABLE:1}_linux_amd64.tar.gz --strip-components=1 stern_${STERN_STABLE:1}_linux_amd64/stern + rm stern_${STERN_STABLE:1}_linux_amd64.tar.gz + fi + echo "" + echo "---- virtctl ----" + if [[ -f stern ]]; then + VIRTCTL_CURRENT="$(./virtctl version --client 2> /dev/null| sed -n 's/.*GitVersion:"\(v[0-9]*\.[0-9]*\.[0-9]*\)".*/\1/p')" + else + VIRTCTL_CURRENT="N/A" + fi + VIRTCTL_STABLE="$(curl -Ls https://github.com/kubevirt/kubevirt/releases | egrep 'href="/kubevirt/kubevirt/releases/tag/v[0-9]+.[0-9]+.[0-9]+*\"' | head -n 1 | sed -n 's/.*tag\/\(v.*\)" data.*/\1/p')" + echo "Installed version: $VIRTCTL_CURRENT" + echo "Latest stable version: $VIRTCTL_STABLE" + if [[ "$VIRTCTL_CURRENT" != "$VIRTCTL_STABLE" ]]; then + echo "updating to $VIRTCTL_STABLE" + curl -Lo virtctl https://github.com/kubevirt/kubevirt/releases/download/$VIRTCTL_STABLE/virtctl-$VIRTCTL_STABLE-linux-amd64 + chmod +x ./virtctl + fi + echo "" + set -e +}