From 1035e70a4ad41860e03fda1bf73b7a09daaed58a Mon Sep 17 00:00:00 2001 From: rjshrjndrn Date: Fri, 2 Dec 2022 20:38:59 +0100 Subject: [PATCH] chore(init): update tools logic Signed-off-by: rjshrjndrn --- scripts/helmcharts/init.sh | 67 ++++++++++++++++++++++++-------------- 1 file changed, 42 insertions(+), 25 deletions(-) diff --git a/scripts/helmcharts/init.sh b/scripts/helmcharts/init.sh index b344d7bfa..546607f92 100644 --- a/scripts/helmcharts/init.sh +++ b/scripts/helmcharts/init.sh @@ -29,41 +29,51 @@ function install_k8s() { sleep 10 } +# Checking whether the app exists or we do have to upgade. +function exists() { + install_status=Upgrading + [[ UPGRADE_TOOLS -eq 1 ]] && { + install_status=Upgrading + return 100 + } + which $1 &> /dev/null + return $? +} + +# Instal the toolings needed for installation/maintaining k8s function install_tools() { ## installing kubectl - which kubectl &> /dev/null || { - info "kubectl not installed. Installing it..." + exists kubectl || { + info "$install_status kubectl" sudo curl -SsL https://dl.k8s.io/release/v1.20.0/bin/linux/amd64/kubectl -o /usr/local/bin/kubectl ; sudo chmod +x /usr/local/bin/kubectl } - ## Installing GH package manager - which eget &> /dev/null || { - local version="1.3.0" - info "eget not installed. Installing it..." - curl -SsL https://github.com/zyedidia/eget/releases/download/v$version/eget-1.3.0-linux_amd64.tar.gz -o /tmp/eget.tar.gz - cd /tmp - tar -xf eget.tar.gz - sudo mv eget-$version-linux_amd64/eget /usr/local/bin/eget + ## $install_status GH package manager + exists eget || { + info "$install_status eget" + download_url=`curl https://api.github.com/repos/zyedidia/eget/releases/latest -s | grep linux_amd64 | grep browser_download_url | cut -d '"' -f4` + curl -SsL ${download_url} -o /tmp/eget.tar.gz + tar -xf /tmp/eget.tar.gz --strip-components=1 -C /tmp/ + sudo mv /tmp/eget /usr/local/bin/eget sudo chmod +x /usr/local/bin/eget - cd - } - ## installing stern - which stern &> /dev/null || { - info "stern not installed. installing..." - sudo eget --to /usr/local/bin stern/stern + ## installing stern, log viewer for K8s + exists stern || { + info "$install_status Stern" + sudo eget -q --to /usr/local/bin stern/stern } - ## installing k9s - which k9s &> /dev/null || { - info "k9s not installed. Installing it..." - sudo eget --to /usr/local/bin derailed/k9s + ## installing k9s, TUI K8s + exists k9s || { + info "$install_status K9s" + sudo eget -q --to /usr/local/bin derailed/k9s } - ## installing helm - which helm &> /dev/null || { - info "helm not installed. Installing it..." - sudo eget --to /usr/local/bin https://get.helm.sh/helm-v3.10.2-linux-amd64.tar.gz -f helm + ## installing helm, package manager for K8s + exists helm || { + info "$install_status Helm" + sudo eget -q --to /usr/local/bin https://get.helm.sh/helm-v3.10.2-linux-amd64.tar.gz -f helm } } @@ -72,6 +82,11 @@ function install_tools() { # sudo apt install openssl -y &> /dev/null randomPass() { + ## Installing openssl + exists openssl || { + sudo apt update &> /dev/null + sudo apt install openssl -y &> /dev/null + } openssl rand -hex 10 } @@ -137,11 +152,13 @@ function main() { } || { install_tools } - create_passwords - set_permissions + [[ x$SKIP_ROTATE_SECRETS == "x1" ]] && { + create_passwords + } [[ x$SKIP_OR_INSTALL == "x1" ]] && { info "Skipping OpenReplay installation" } || { + set_permissions install_openreplay } }