myhome/.local/bin/Update-pkg

454 lines
14 KiB
Bash
Executable File

#!/bin/bash
# shellcheck disable=2010,2045,2086,2155
# Path to the zsh folder
ZSHFOLDER=$HOME/.config/zsh
CONFIG="$HOME/.config"
OHMYZSH="$HOME/.oh-my-zsh"
mkdir -p $ZSHFOLDER $CONFIG $OHMYZSH
# Colours
RED='\033[0;31m'
GREEN='\033[0;0;32m'
NC='\033[0m'
# Stable version
TERRAFORM_VERSION="1.5.7"
# Python
if which python3 > /dev/null 2>&1; then
python="python3"
pip="pip3"
else
export PYTHONVERSION=$(ls -la /opt/homebrew/opt/ |
grep -iEo 'python@.* ->' |
sed 's/ ->//g' |
sort |
tail -n1 |
sed 's/python@//g')
python="/opt/homebrew/bin/python$PYTHONVERSION"
pip="/opt/homebrew/bin/pip$PYTHONVERSION"
fi
PIPEXT="--user --force --quiet --break-system-packages --no-warn-script-location"
PIPEXTPRE="--pre $PIPEXT"
# Gentoo release
GENTOO="/etc/gentoo-release"
# Function for basic install
install=""
if [[ "$(uname)" == "Darwin" ]]; then
install="brew install"
elif [[ -f $GENTOO ]]; then
install="sudo emerge --update"
elif [[ -f /etc/debian_version ]]; then
sudo apt update
install="sudo apt install -y"
elif [[ -f /etc/redhat-release ]]; then
install="sudo dnf install"
fi
function timestamp() {
echo -e "${GREEN}[+]${NC} $(date +'%F %T') [INFO] $*"
}
function err() {
echo -e "${RED}[-] $(date +'%F %T') [ERROR] $*${NC}" >&2
}
function command_start() {
timestamp "Command $* has been started."
if ! "$*"; then
err "---------"
err "Command $* went wrong."
err "---------"
# exit
fi
timestamp "Command $* has been ended."
}
function command_exists() {
if command -v "$1" > /dev/null 2>&1; then
timestamp "Command $1 has been found"
else
err "Command $1 has been NOT found"
# Return false
return 1
fi
}
function update_pip() {
# Update the pip
if [[ "$(uname)" == "Darwin" ]]; then
$python -m pip install --upgrade pip --user --no-warn-script-location --break
elif [[ -f $GENTOO ]]; then
$install dev-python/pip
fi
}
function install_neovim_module_for_python() {
# Python module in neovim
$pip install pynvim neovim imps $PIPEXTPRE
}
function install_node(){
if command_exists npm; then
timestamp "Node has been found"
else
if [[ "$(uname)" == "Darwin" ]]; then
sudo brew uninstall node
sudo rm -rf /opt/homebrew/lib/node_modules/npm/
$install node
elif [[ -f $GENTOO ]]; then
$install dev-lang/nodejs
fi
fi
}
function install_pyright() {
# Install pyright
sudo npm -s -g i pyright --force
$pip install black $PIPEXTPRE
}
function install_bash-language-server() {
# Install bash-language-server
sudo npm -s -g i bash-language-server --force
}
function install_yaml-language-server() {
# Install yaml-language-server
sudo npm -s -g i yaml-language-server --force
}
function install_shfmt() {
# Install shfmt
GO111MODULE=on go install mvdan.cc/sh/v3/cmd/shfmt@latest
}
function install_lazy() {
# Install shfmt
GO111MODULE=on go install github.com/jesseduffield/lazygit@latest
GO111MODULE=on go install github.com/jesseduffield/lazydocker@latest
}
function install_dlv() {
GO111MODULE=on go install github.com/go-delve/delve/cmd/dlv@latest
}
function install_terraform_stable() {
# Install terraform and terraform-ls
GO111MODULE=on go install github.com/hashicorp/terraform-ls@latest
if [[ "$(uname)" == "Darwin" ]]; then
$install tflint -q
$install tfenv -q
TFENV_ARCH=amd64 tfenv install "$TERRAFORM_VERSION"
tfenv use "$TERRAFORM_VERSION"
else
GO111MODULE=on go install github.com/hashicorp/terraform@v"$TERRAFORM_VERSION"
curl -s https://raw.githubusercontent.com/terraform-linters/tflint/master/install_linux.sh | bash
fi
}
function install_terraform() {
# Install terraform and terraform-ls
GO111MODULE=on go install github.com/hashicorp/terraform-ls@latest
if [[ "$(uname)" == "Darwin" ]]; then
$install tflint -q
$install tfenv -q
TFENV_ARCH=amd64 tfenv install latest
mapfile -t TFENV_VER_ARRAY < <(tfenv list | grep -ioE ' [0-9.]+' | sed -e '1,1d')
if [ "${#TFENV_VER_ARRAY[@]}" -gt "2" ]; then
for i in "${TFENV_VER_ARRAY[@]}"; do
tfenv uninstall "$i" && timestamp "Removed - terraform '$i' version"
done
fi
else
GO111MODULE=on go install github.com/hashicorp/terraform@latest
curl -s https://raw.githubusercontent.com/terraform-linters/tflint/master/install_linux.sh | bash
fi
}
function install_terragrunt() {
# Install terragrunt
if [[ "$(uname)" == "Darwin" ]]; then
$install terragrunt -q
else
TERRAGRUNT=$HOME/.local/bin/terragrunt
REMOTE_VERSION=$(curl -s https://api.github.com/repos/gruntwork-io/terragrunt/releases/latest | grep -iEo '"tag_name":.*' | sed 's/"tag_name"://g;s/"//g;s/,//g;s/ //g')
CURRENT_VERSION="0.0.0"
[ -f $TERRAGRUNT ] && CURRENT_VERSION=$($TERRAGRUNT version)
if [ "$REMOTE_VERSION" == "$CURRENT_VERSION" ]; then
timestamp "The current version of the TSS-SDK is the same as the newest version"
return 0
else
wget https://github.com/gruntwork-io/terragrunt/releases/latest/download/terragrunt_linux_amd64 -O $TERRAGRUNT
chmod +x "$TERRAGRUNT"
fi
fi
}
function install_shellcheck() {
# Install shellcheck
if [[ "$(uname)" == "Darwin" ]]; then
$install shellcheck -q
else
curl -s https://raw.githubusercontent.com/terraform-linters/tflint/master/install_linux.sh | bash
fi
}
function install_marksman() {
# Install marksman
if [[ "$(uname)" == "Darwin" ]]; then
$install marksman -q
else
wget https://github.com/artempyanykh/marksman/releases/latest/download/marksman-linux-x64 -O $HOME/.local/bin/marksman
chmod +x $HOME/.local/bin/marksman
fi
}
function install_go() {
# Install the golang
if [[ "$(uname)" == "Darwin" ]]; then
$install golang -q
elif [[ -f $GENTOO ]]; then
$install dev-lang/go
fi
}
function install_gopls() {
# Install gopls
GO111MODULE=on go install golang.org/x/tools/gopls@latest
}
function install_black() {
# Install black
$pip install black $PIPEXTPRE
}
function install_ansible() {
# Install Ansible
$pip install ansible ansible-lint ansible-core $PIPEXTPRE
$pip install ansible-parallel $PIPEXTPRE
}
function install_ansible-language-server() {
# Install ansible-language-server
sudo npm -s -g i @ansible/ansible-language-server --force
sudo npm -s -g i yaml-language-server --force
}
function install_meraki_ansible() {
# Install python, ansible module for meraki
ansible-galaxy collection install cisco.meraki --force
$pip install meraki $PIPEXT
}
function install_azure_cli() {
# Install azure_cli
$pip install azure-cli $PIPEXTPRE
}
function install_awscli() {
# Install awscli
$pip install awscli $PIPEXTPRE
}
function install_aws_adfs() {
# Install aws-adfs
$pip install aws-adfs $PIPEXTPRE
}
function install_ytdlp() {
# Install yt-dlp
$pip install yt-dlp $PIPEXTPRE
}
function install_spotifydl() {
# Install spotify_dl
$pip install spotify_dl $PIPEXTPRE
}
function update() {
if [ -d $CONFIG/fzf ]; then
FOLDER="$CONFIG/fzf"
cd $FOLDER || err "Folder $FOLDER has been NOT found"
git pull -q && timestamp "Pulling the $FOLDER configuration"
else
FOLDER="$CONFIG/fzf"
git clone https://github.com/junegunn/fzf.git $FOLDER && timestamp "Cloning the FZF"
git pull -q && timestamp "Pulling the $FOLDER configuration"
fi
if [ ! -d $ZSHFOLDER/aws ]; then
curl -s https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/plugins/aws/aws.plugin.zsh \
-o "$ZSHFOLDER"/aws/aws.plugin.zsh &&
timestamp "Downloaded the newest version of aws plugin for zsh"
curl -s https://raw.githubusercontent.com/Azure/azure-cli/dev/az.completion \
-o "$ZSHFOLDER"/azure-cli/az.completion &&
timestamp "Downloaded the newest version of az plugin for zsh"
mkdir -p "$ZSHFOLDER/azure-cli" "$ZSHFOLDER/aws"
cd $ZSHFOLDER || err "Folder $ZSHFOLDER has been NOT found"
git clone https://github.com/popstas/zsh-command-time.git &&
timestamp "Cloning the zsh-command-time"
git clone https://github.com/zsh-users/zsh-syntax-highlighting.git &&
timestamp "Cloning the zsh-syntax-highlighting"
git clone https://github.com/zsh-users/zsh-autosuggestions.git &&
timestamp "Cloning the zsh-autosuggestions"
fi
for i in $(ls $ZSHFOLDER); do
FOLDER="$ZSHFOLDER/$i"
if [ -d "$FOLDER/.git" ]; then
cd "$FOLDER" || err "Folder $FOLDER has been NOT found"
git pull -q && timestamp "Pulling the $FOLDER configuration"
fi
done
if [ ! -d $OHMYZSH ]; then
cd $OHMYZSH || err "Folder $OHMYZSH has been NOT found"
git pull -q && timestamp "Pulling the $OHMYZSH configuration"
fi
curl -s https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/plugins/aws/aws.plugin.zsh -o "$ZSHFOLDER"/aws/aws.plugin.zsh && timestamp "Downloaded the newest version of aws plugin for zsh"
curl -s https://raw.githubusercontent.com/Azure/azure-cli/dev/az.completion -o "$ZSHFOLDER"/azure-cli/az.completion && timestamp "Downloaded the newest version of az plugin for zsh"
}
function install_speedtest() {
# Install speedtest-cli
$pip install speedtest-cli $PIPEXTPRE
}
function install_gh_cli() {
# Install gh-cli
if [[ "$(uname)" == "Darwin" ]]; then
$install gh
elif [[ -f $GENTOO ]]; then
$install dev-util/github-cli
fi
}
function install_kubernetes() {
# Install kubectl
LINK=""
CURRENT_VERSION=""
REMOTE_VERSION=$(curl -L -s https://dl.k8s.io/release/stable.txt)
KUBECTL_LOCATION="$HOME/.local/bin/kubectl"
[ -f $HOME/.local/bin/kubectl ] && CURRENT_VERSION=$($KUBECTL_LOCATION version --client | grep --color=no -iEo 'Client Version: v[0-9\.]+' | grep -ioE --color=no 'v[0-9\.]+')
if [ "$REMOTE_VERSION" == "$CURRENT_VERSION" ]; then
timestamp "The current version of the kubectl is the same as the newest version"
return 0
fi
if [[ "$(uname)" == "Darwin" ]]; then
LINK="http://dl.k8s.io/release/$(curl -L -s https://dl.k8s.io/release/stable.txt)/bin/darwin/amd64/kubectl"
else
LINK="http://dl.k8s.io/release/$(curl -L -s https://dl.k8s.io/release/stable.txt)/bin/linux/amd64/kubectl"
fi
wget "https://dl.k8s.io/release/$(curl -L -s https://dl.k8s.io/release/stable.txt)/bin/linux/amd64/kubectl" -O $KUBECTL_LOCATION
chmod +x $KUBECTL_LOCATION
}
function install_rust() {
# Install rust
if command_exists rustc; then
rustup update
rustup component add rust-analyzer
else
curl --proto '=https' --tlsv1.2 https://sh.rustup.rs -sSf | sh
fi
}
function install_tss_client() {
# Install tss
CURRENT_VERSION="1.5.7"
# Example link: https://downloads.ss.thycotic.com/secretserversdk/1.5.7/secretserver-sdk-1.5.7-linux-x64.zip
TSSDOCS="https://docs.delinea.com/online-help/secret-server/api-scripting/sdk-devops/sdk-downloads/index.htm"
LINK=""
REMOTE_VERSION=""
if [ "$(uname)" == "Darwin" ]; then
LINK=$(curl -s -L $TSSDOCS | grep -iEo 'href=".*-osx-x64.zip"' | sed 's/href\=//g;s/"//g' | sort -r | head -n1)
REMOTE_VERSION=$(echo $LINK | grep -iEo '[0-9.]+-osx' | sed 's/-osx//g')
else
LINK=$(curl -s -L $TSSDOCS | grep -iEo 'href=".*-linux-x64.zip"' | sed 's/href\=//g;s/"//g' | sort -r | head -n1)
REMOTE_VERSION=$(echo $LINK | grep -iEo '[0-9.]+-linux' | sed 's/-linux//g')
fi
TSSFOLDER="$HOME/.local/tss-sdk"
TSSLINK="$HOME/.local/bin/tss"
[ -f $TSSLINK ] && CURRENT_VERSION=$($TSSLINK version)
timestamp "Current version of the TSS-SDK: $CURRENT_VERSION"
timestamp "Remote version of the TSS-SDK: $REMOTE_VERSION"
if [ "$REMOTE_VERSION" == "$CURRENT_VERSION" ]; then
timestamp "The current version of the TSS-SDK is the same as the newest version"
return 0
else
rm -rfv $TSSFOLDER $TSSLINK
mkdir $TSSFOLDER
timestamp "Downloading the newest version of the TSS-SDK"
timestamp "Link: $LINK"
wget $LINK -P $TSSFOLDER
unzip $TSSFOLDER/secretserver-sdk-*.zip -d $TSSFOLDER
rm -rfv $TSSFOLDER/secretserver-sdk-*.zip
ln -s $TSSFOLDER/tss $TSSLINK
chmod +x $TSSLINK
fi
}
function main() {
command_start update_pip
command_start install_neovim_module_for_python
command_start install_node
command_start install_go
command_start install_pyright
command_start install_lazy
command_start install_dlv
command_start install_bash-language-server
command_start install_yaml-language-server
command_start install_marksman
command_start install_shfmt
command_start install_shellcheck
command_start install_gopls
# command_start install_terraform
command_start install_terraform_stable
command_start install_terragrunt
command_start install_azure_cli
command_start install_black
command_start install_ansible
command_start install_meraki_ansible
command_start install_ansible-language-server
command_start install_ytdlp
command_start install_spotifydl
command_start install_awscli
command_start install_aws_adfs
command_start install_speedtest
command_start install_gh_cli
command_start install_kubernetes
command_start install_rust
command_start install_tss_client
command_start update
}
main