Skip to content

Commit

Permalink
update: kubectl&helm install script
Browse files Browse the repository at this point in the history
  • Loading branch information
horseinthesky committed Jan 27, 2024
1 parent c933800 commit e42e289
Show file tree
Hide file tree
Showing 5 changed files with 123 additions and 93 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ targets = \
js \
nvim \
docker \
terraform \
cloud \

.PHONY: all $(targets)

Expand Down
18 changes: 9 additions & 9 deletions files/zsh/tools.zsh
Original file line number Diff line number Diff line change
Expand Up @@ -59,13 +59,13 @@ fi
[[ -z $(whence z) ]] && eval "$(zoxide init zsh)"

# ==== Yandex ====
if [[ $(cat /proc/sys/kernel/hostname) == 'carbon9' ]] ; then
# export PSSH_AUTH_SOCK="/mnt/c/Users/$USER/AppData/Local/Temp/pssh-agent.sock"
# export SSH_AUTH_SOCK="${PSSH_AUTH_SOCK}"
# [[ $(ssh-add -l) =~ "$HOME/.ssh/id_rsa" ]] || ssh-add
# if [[ $(cat /proc/sys/kernel/hostname) == 'carbon9' ]] ; then
# fi
# export PSSH_AUTH_SOCK="/mnt/c/Users/$USER/AppData/Local/Temp/pssh-agent.sock"
# export SSH_AUTH_SOCK="${PSSH_AUTH_SOCK}"
# [[ $(ssh-add -l) =~ "$HOME/.ssh/id_rsa" ]] || ssh-add

# yc & ycp
[[ -d $HOME/yandex-cloud && ! $PATH == *$HOME/yandex-cloud/bin* ]] && export PATH=$HOME/yandex-cloud/bin:$PATH
[[ -d $HOME/ycp && ! $PATH == *$HOME/ycp/bin* ]] && export PATH=$HOME/ycp/bin:$PATH
[[ -f $HOME/yandex-cloud/completion.zsh.inc ]] && source $HOME/yandex-cloud/completion.zsh.inc
fi
# yc & ycp
[[ -d $HOME/yandex-cloud && ! $PATH == *$HOME/yandex-cloud/bin* ]] && export PATH=$HOME/yandex-cloud/bin:$PATH
[[ -d $HOME/ycp && ! $PATH == *$HOME/ycp/bin* ]] && export PATH=$HOME/ycp/bin:$PATH
[[ -f $HOME/yandex-cloud/completion.zsh.inc ]] && source $HOME/yandex-cloud/completion.zsh.inc
101 changes: 101 additions & 0 deletions scripts/cloud.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
#!/usr/bin/env bash

source scripts/helper.sh

setup_env () {
[[ ! -d $HOME/.local/bin ]] && mkdir -p "$HOME"/.local/bin
[[ ! $PATH == *$HOME/.local/bin* ]] && export PATH=$HOME/.local/bin:$PATH
}

download_package () {
local url=$1
local path=$2
local package=$(echo "$1" | awk -F/ '{print $NF}')

download "$url"
[[ $? -ne 0 ]] && return 1

info "Extracting archive..."
unzip -o "$HOME/$package" -d "$path"
rm "$HOME/$package"

success
}

terraform_install () {
local name=$1

header "Installing $name..."

local latest_version=$(
curl -s https://api.github.com/repos/hashicorp/"$name"/releases/latest | \
grep tag_name | grep -Po "\d+\.\d+\.\d+"
)
local package_name=${name}_${latest_version}_linux_amd64.zip

if [[ -z $(which "$name") ]]; then
download_package https://releases.hashicorp.com/"$name/$latest_version/$package_name" "$HOME"/.local/bin
return
fi

local current_version=$("$name" -v | head -n 1 | grep -Po "\d+\.\d+\.\d+")

if [[ $current_version == $latest_version ]]; then
success "Latest ($latest_version) version is already installed"
return
fi

info "Newer version found. Updating $current_version -> $latest_version..."
download_package https://releases.hashicorp.com/"$name/$latest_version/$package_name" "$HOME"/.local/bin
[[ $? -ne 0 ]] && return

success "Updated to the latest ($latest_version) version"
}

install_terraform_packages () {
packages=(
terraform
terraform-ls
)

for tool in "${packages[@]}"; do
terraform_install "$tool"
done
}

install_kubelet () {
header "Installing kubectl..."

if [[ -n $(which kubectl) ]]; then
success "kubectl is already installed."
return
fi

curl -LO "https://dl.k8s.io/release/$(curl -L -s https://dl.k8s.io/release/stable.txt)/bin/linux/amd64/kubectl"
chmod +x "$HOME"/kubectl
mv "$HOME"/kubectl "$HOME"/.local/bin/kubectl

success
}

install_helm () {
header "Installing helm..."

if [[ -n $(which helm) ]]; then
success "helm is already installed."
return
fi

curl https://raw.githubusercontent.com/helm/helm/main/scripts/get-helm-3 | USE_SUDO=false HELM_INSTALL_DIR=~/.local/bin bash

success
}

main () {
setup_env
install_terraform_packages
install_kubelet
install_helm
}

main
24 changes: 12 additions & 12 deletions scripts/go.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ source scripts/helper.sh

go_install () {
local path=$1
local tool=$(echo ${path} | awk -F/ '{print $(NF-1)"/"$NF}')
local tool=$(echo "$path" | awk -F/ '{print $(NF-1)"/"$NF}')

PATH=$HOME/.local/bin:$PATH

Expand All @@ -14,7 +14,7 @@ go_install () {
fi

info "Installing $tool..."
go install ${path}@latest
go install "$path"@latest
success "$tool installed"
}

Expand All @@ -24,8 +24,8 @@ install_go () {
local version=1.21.3
local tarball=go${version}.linux-amd64.tar.gz

[[ ! -d $HOME/.local/bin ]] && mkdir -p $HOME/.local/bin
[[ ! -d $HOME/.local/lib ]] && mkdir -p $HOME/.local/lib
[[ ! -d $HOME/.local/bin ]] && mkdir -p "$HOME"/.local/bin
[[ ! -d $HOME/.local/lib ]] && mkdir -p "$HOME"/.local/lib
[[ ! $PATH == *$HOME/.local/bin* ]] && export PATH=$HOME/.local/bin:$PATH

if [[ -n $(which go) ]] && [[ $(go version | awk '{print $3}' | cut -c3-) == $version ]]; then
Expand All @@ -34,25 +34,25 @@ install_go () {
fi

# Remove old ersion
[[ -d $HOME/.local/lib/go ]] && rm -rf $HOME/.local/lib/go
[[ -d $HOME/.local/lib/go ]] && rm -rf "$HOME"/.local/lib/go

# Install a new one
download https://dl.google.com/go/$tarball
download https://dl.google.com/go/"$tarball"
[[ $? -ne 0 ]] && exit

info "Extracting archive..."
tar -C $HOME/.local/lib -xzf $HOME/$tarball
tar -C "$HOME"/.local/lib -xzf "$HOME/$tarball"

# Remove tarball
rm $HOME/$tarball
rm "$HOME/$tarball"

success
}

symlink_go () {
header "Symlink go"
symlink $HOME/.local/lib/go/bin/go $HOME/.local/bin/go
symlink $HOME/.local/lib/go/bin/gofmt $HOME/.local/bin/gofmt
symlink "$HOME"/.local/lib/go/bin/go "$HOME"/.local/bin/go
symlink "$HOME"/.local/lib/go/bin/gofmt "$HOME"/.local/bin/gofmt
}

install_go_tools () {
Expand All @@ -67,8 +67,8 @@ install_go_tools () {
github.com/natesales/q
)

for tool in ${tools[@]}; do
go_install $tool
for tool in "${tools[@]}"; do
go_install "$tool"
done
}

Expand Down
71 changes: 0 additions & 71 deletions scripts/terraform.sh

This file was deleted.

0 comments on commit e42e289

Please sign in to comment.