2023-04-11 10:20:06 +02:00
#!/bin/bash
2024-01-13 12:48:24 +01:00
# shellcheck disable=2010,2045,2086,2155
2023-04-11 10:20:06 +02:00
2024-01-13 12:48:24 +01:00
# Path to the zsh folder
2023-04-11 10:20:06 +02:00
ZSHFOLDER=$HOME/.config/zsh
CONFIG="$HOME/.config"
2024-10-03 12:55:46 +02:00
OHMYZSH="$HOME/.oh-my-zsh"
2023-04-11 10:20:06 +02:00
2024-10-06 01:48:22 +02:00
mkdir -p $ZSHFOLDER $CONFIG $OHMYZSH
2023-04-11 10:20:06 +02:00
# Colours
RED='\033[0;31m'
GREEN='\033[0;0;32m'
NC='\033[0m'
2024-01-13 12:48:24 +01:00
# Stable version
TERRAFORM_VERSION="1.5.7"
# Python
2024-09-10 09:38:56 +02:00
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
2024-01-13 12:48:24 +01:00
PIPEXT="--user --force --quiet --break-system-packages --no-warn-script-location"
2023-09-04 11:10:17 +02:00
PIPEXTPRE="--pre $PIPEXT"
2024-01-13 12:48:24 +01:00
# Gentoo release
2023-11-23 14:30:32 +01:00
GENTOO="/etc/gentoo-release"
2023-09-04 11:10:17 +02:00
2024-10-03 12:55:46 +02:00
# 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
2023-09-04 11:10:17 +02:00
2023-04-11 10:20:06 +02:00
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
2024-10-30 21:22:52 +01:00
err "---------"
2023-04-11 10:20:06 +02:00
err "Command $* went wrong."
2024-10-30 21:22:52 +01:00
err "---------"
# exit
2023-04-11 10:20:06 +02:00
fi
timestamp "Command $* has been ended."
}
2024-04-13 22:19:47 +02:00
function command_exists() {
2024-10-06 01:48:22 +02:00
if command -v "$1" > /dev/null 2>&1; then
2024-04-13 22:19:47 +02:00
timestamp "Command $1 has been found"
else
err "Command $1 has been NOT found"
2024-10-06 01:48:22 +02:00
# Return false
return 1
2024-04-13 22:19:47 +02:00
fi
}
2023-04-11 10:20:06 +02:00
function update_pip() {
# Update the pip
2023-09-04 11:10:51 +02:00
if [[ "$(uname)" == "Darwin" ]]; then
2024-10-30 21:22:52 +01:00
$python -m pip install --upgrade pip --user --no-warn-script-location --break
2023-11-23 14:30:32 +01:00
elif [[ -f $GENTOO ]]; then
2024-10-03 12:55:46 +02:00
$install dev-python/pip
2023-09-04 11:10:51 +02:00
fi
2023-04-11 10:20:06 +02:00
}
function install_neovim_module_for_python() {
# Python module in neovim
2024-01-13 12:48:24 +01:00
$pip install pynvim neovim imps $PIPEXTPRE
2023-04-11 10:20:06 +02:00
}
2024-10-30 21:22:52 +01:00
function install_node(){
if command_exists npm; then
timestamp "Node has been found"
else
if [[ "$(uname)" == "Darwin" ]]; then
2024-11-14 07:59:36 +01:00
brew uninstall node --ignore-dependencies
2024-10-30 21:22:52 +01:00
sudo rm -rf /opt/homebrew/lib/node_modules/npm/
$install node
elif [[ -f $GENTOO ]]; then
$install dev-lang/nodejs
fi
fi
}
2023-04-11 10:20:06 +02:00
function install_pyright() {
# Install pyright
sudo npm -s -g i pyright --force
2024-01-13 12:48:24 +01:00
$pip install black $PIPEXTPRE
2023-04-11 10:20:06 +02:00
}
2024-12-01 23:27:27 +01:00
function install_ruff() {
# Install ruff
$pip install ruff $PIPEXTPRE
}
2023-04-11 10:20:06 +02:00
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
}
2024-10-03 12:55:46 +02:00
function install_dlv() {
GO111MODULE=on go install github.com/go-delve/delve/cmd/dlv@latest
}
2023-10-19 10:17:02 +02:00
function install_terraform_stable() {
# Install terraform and terraform-ls
GO111MODULE=on go install github.com/hashicorp/terraform-ls@latest
if [[ "$(uname)" == "Darwin" ]]; then
2024-10-03 12:55:46 +02:00
$install tflint -q
$install tfenv -q
2024-01-13 12:48:24 +01:00
TFENV_ARCH=amd64 tfenv install "$TERRAFORM_VERSION"
tfenv use "$TERRAFORM_VERSION"
2023-10-19 10:17:02 +02:00
else
2024-01-13 12:48:24 +01:00
GO111MODULE=on go install github.com/hashicorp/terraform@v"$TERRAFORM_VERSION"
2023-10-19 10:17:02 +02:00
curl -s https://raw.githubusercontent.com/terraform-linters/tflint/master/install_linux.sh | bash
fi
}
2023-04-11 10:20:06 +02:00
function install_terraform() {
# Install terraform and terraform-ls
GO111MODULE=on go install github.com/hashicorp/terraform-ls@latest
if [[ "$(uname)" == "Darwin" ]]; then
2024-10-03 12:55:46 +02:00
$install tflint -q
$install tfenv -q
2023-06-17 17:10:25 +02:00
TFENV_ARCH=amd64 tfenv install latest
2024-01-13 12:48:24 +01:00
mapfile -t TFENV_VER_ARRAY < <(tfenv list | grep -ioE ' [0-9.]+' | sed -e '1,1d')
2023-07-19 00:51:44 +02:00
if [ "${#TFENV_VER_ARRAY[@]}" -gt "2" ]; then
for i in "${TFENV_VER_ARRAY[@]}"; do
tfenv uninstall "$i" && timestamp "Removed - terraform '$i' version"
done
fi
2023-04-11 10:20:06 +02:00
else
2023-06-20 21:25:15 +02:00
GO111MODULE=on go install github.com/hashicorp/terraform@latest
2023-04-11 10:20:06 +02:00
curl -s https://raw.githubusercontent.com/terraform-linters/tflint/master/install_linux.sh | bash
fi
}
function install_terragrunt() {
# Install terragrunt
if [[ "$(uname)" == "Darwin" ]]; then
2024-10-03 12:55:46 +02:00
$install terragrunt -q
2023-04-11 10:20:06 +02:00
else
2024-09-10 09:38:56 +02:00
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
2023-04-11 10:20:06 +02:00
fi
}
function install_shellcheck() {
# Install shellcheck
if [[ "$(uname)" == "Darwin" ]]; then
2024-10-03 12:55:46 +02:00
$install shellcheck -q
2023-04-11 10:20:06 +02:00
else
curl -s https://raw.githubusercontent.com/terraform-linters/tflint/master/install_linux.sh | bash
fi
}
2023-09-04 11:11:19 +02:00
function install_marksman() {
2024-09-10 09:38:56 +02:00
# Install marksman
2023-09-04 11:11:19 +02:00
if [[ "$(uname)" == "Darwin" ]]; then
2024-10-03 12:55:46 +02:00
$install marksman -q
2023-09-04 11:11:19 +02:00
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
}
2023-04-13 00:19:04 +02:00
function install_go() {
# Install the golang
if [[ "$(uname)" == "Darwin" ]]; then
2024-10-03 12:55:46 +02:00
$install golang -q
2023-11-23 14:30:32 +01:00
elif [[ -f $GENTOO ]]; then
2024-10-03 12:55:46 +02:00
$install dev-lang/go
2023-04-13 00:19:04 +02:00
fi
}
2023-04-11 10:20:06 +02:00
function install_gopls() {
# Install gopls
GO111MODULE=on go install golang.org/x/tools/gopls@latest
}
function install_black() {
# Install black
2024-01-13 12:48:24 +01:00
$pip install black $PIPEXTPRE
2023-04-11 10:20:06 +02:00
}
function install_ansible() {
# Install Ansible
2024-01-13 12:48:24 +01:00
$pip install ansible ansible-lint ansible-core $PIPEXTPRE
$pip install ansible-parallel $PIPEXTPRE
2023-04-11 10:20:06 +02:00
}
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
2024-01-13 12:48:24 +01:00
$pip install meraki $PIPEXT
2023-04-11 10:20:06 +02:00
}
function install_azure_cli() {
# Install azure_cli
2024-01-13 12:48:24 +01:00
$pip install azure-cli $PIPEXTPRE
2023-04-11 10:20:06 +02:00
}
function install_awscli() {
# Install awscli
2024-01-13 12:48:24 +01:00
$pip install awscli $PIPEXTPRE
2023-04-11 10:20:06 +02:00
}
2023-11-23 09:23:19 +01:00
function install_aws_adfs() {
# Install aws-adfs
2024-01-13 12:48:24 +01:00
$pip install aws-adfs $PIPEXTPRE
2023-11-23 09:23:19 +01:00
}
2023-08-28 10:10:05 +02:00
function install_ytdlp() {
# Install yt-dlp
2024-01-13 12:48:24 +01:00
$pip install yt-dlp $PIPEXTPRE
2023-08-28 10:10:05 +02:00
}
function install_spotifydl() {
# Install spotify_dl
2024-01-13 12:48:24 +01:00
$pip install spotify_dl $PIPEXTPRE
2023-08-28 10:10:05 +02:00
}
2023-04-11 10:20:06 +02:00
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
2024-10-03 12:55:46 +02:00
if [ ! -d $OHMYZSH ]; then
cd $OHMYZSH || err "Folder $OHMYZSH has been NOT found"
git pull -q && timestamp "Pulling the $OHMYZSH configuration"
fi
2023-04-11 10:20:06 +02:00
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"
}
2023-10-05 09:19:06 +02:00
function install_speedtest() {
# Install speedtest-cli
2024-01-13 12:48:24 +01:00
$pip install speedtest-cli $PIPEXTPRE
2023-10-05 09:19:06 +02:00
}
2023-10-31 14:05:09 +01:00
function install_gh_cli() {
2024-09-10 09:38:56 +02:00
# Install gh-cli
2023-10-31 14:05:09 +01:00
if [[ "$(uname)" == "Darwin" ]]; then
2024-10-03 12:55:46 +02:00
$install gh
2023-11-23 14:30:32 +01:00
elif [[ -f $GENTOO ]]; then
2024-10-03 12:55:46 +02:00
$install dev-util/github-cli
2023-10-31 14:05:09 +01:00
fi
}
2023-11-23 09:23:19 +01:00
function install_kubernetes() {
2024-09-10 09:38:56 +02:00
# Install kubectl
2024-10-30 21:22:52 +01:00
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
2023-11-23 09:23:19 +01:00
if [[ "$(uname)" == "Darwin" ]]; then
2024-10-30 21:22:52 +01:00
LINK="http://dl.k8s.io/release/$(curl -L -s https://dl.k8s.io/release/stable.txt)/bin/darwin/amd64/kubectl"
2023-11-23 14:30:32 +01:00
else
2024-10-30 21:22:52 +01:00
LINK="http://dl.k8s.io/release/$(curl -L -s https://dl.k8s.io/release/stable.txt)/bin/linux/amd64/kubectl"
2023-11-23 09:23:19 +01:00
fi
2024-10-30 21:22:52 +01:00
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
2023-11-23 09:23:19 +01:00
}
2024-04-13 22:21:25 +02:00
function install_rust() {
2024-09-10 09:38:56 +02:00
# Install rust
2024-04-13 22:21:25 +02:00
if command_exists rustc; then
rustup update
2024-04-28 21:14:48 +02:00
rustup component add rust-analyzer
2024-04-13 22:21:25 +02:00
else
curl --proto '=https' --tlsv1.2 https://sh.rustup.rs -sSf | sh
fi
}
2024-09-10 09:38:56 +02:00
function install_tss_client() {
# Install tss
2024-10-30 21:22:52 +01:00
CURRENT_VERSION="1.5.7"
2024-09-10 09:38:56 +02:00
# Example link: https://downloads.ss.thycotic.com/secretserversdk/1.5.7/secretserver-sdk-1.5.7-linux-x64.zip
2024-10-30 21:22:52 +01:00
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
2024-09-10 09:38:56 +02:00
2024-10-30 21:22:52 +01:00
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"
2024-09-10 09:38:56 +02:00
if [ "$REMOTE_VERSION" == "$CURRENT_VERSION" ]; then
timestamp "The current version of the TSS-SDK is the same as the newest version"
return 0
else
2024-10-30 21:22:52 +01:00
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
2024-09-10 09:38:56 +02:00
fi
}
2023-04-11 10:20:06 +02:00
function main() {
command_start update_pip
2023-09-04 11:10:17 +02:00
command_start install_neovim_module_for_python
2024-10-30 21:22:52 +01:00
command_start install_node
2023-04-13 00:19:04 +02:00
command_start install_go
2024-12-01 23:27:27 +01:00
# command_start install_pyright
command_start install_ruff
2023-04-11 10:20:06 +02:00
command_start install_lazy
2024-10-03 12:55:46 +02:00
command_start install_dlv
2023-04-11 10:20:06 +02:00
command_start install_bash-language-server
command_start install_yaml-language-server
2023-09-04 11:11:19 +02:00
command_start install_marksman
2023-04-11 10:20:06 +02:00
command_start install_shfmt
command_start install_shellcheck
command_start install_gopls
2023-10-19 10:17:02 +02:00
# command_start install_terraform
command_start install_terraform_stable
2023-04-11 10:20:06 +02:00
command_start install_terragrunt
command_start install_azure_cli
command_start install_black
command_start install_ansible
command_start install_meraki_ansible
2024-10-30 21:22:52 +01:00
command_start install_ansible-language-server
2023-08-28 10:10:05 +02:00
command_start install_ytdlp
command_start install_spotifydl
2023-09-20 13:51:38 +02:00
command_start install_awscli
2023-11-23 09:23:19 +01:00
command_start install_aws_adfs
2023-10-05 09:19:06 +02:00
command_start install_speedtest
2023-10-31 14:05:09 +01:00
command_start install_gh_cli
2023-11-23 09:23:19 +01:00
command_start install_kubernetes
2024-04-13 22:21:25 +02:00
command_start install_rust
2024-10-30 21:22:52 +01:00
command_start install_tss_client
2023-04-11 10:20:06 +02:00
command_start update
}
main