2023-04-11 10:20:06 +02:00
#!/bin/bash
# shellcheck disable=2045,2086
ZSHFOLDER=$HOME/.config/zsh
CONFIG="$HOME/.config"
# Colours
RED='\033[0;31m'
GREEN='\033[0;0;32m'
NC='\033[0m'
2023-11-02 00:22:05 +01:00
PIPEXT="--user --force --quiet --break-system-packages"
2023-09-04 11:10:17 +02:00
PIPEXTPRE="--pre $PIPEXT"
2023-11-23 14:30:32 +01:00
GENTOO="/etc/gentoo-release"
2023-09-04 11:10:17 +02:00
2023-11-02 00:22:05 +01:00
# if [[ "$(uname -r)" =~ "gentoo" || "$(uname -r)" =~ "WSL2" ]]; then
# PIPEXT="$PIPEXT --break-system-packages"
# PIPEXTPRE="$PIPEXTPRE --break-system-packages"
# 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
err "Command $* went wrong."
exit
fi
timestamp "Command $* has been ended."
}
function update_pip() {
# Update the pip
2023-09-04 11:10:51 +02:00
if [[ "$(uname)" == "Darwin" ]]; then
python3 -m pip install --upgrade pip --user
2023-11-23 14:30:32 +01:00
elif [[ -f $GENTOO ]]; then
2023-09-04 11:10:51 +02:00
sudo emerge dev-python/pip
fi
2023-04-11 10:20:06 +02:00
}
function install_neovim_module_for_python() {
# Python module in neovim
2023-09-04 11:10:17 +02:00
pip3 install neovim $PIPEXTPRE
2023-04-11 10:20:06 +02:00
}
function install_pyright() {
# Install pyright
sudo npm -s -g i pyright --force
}
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
}
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
brew install tflint -q
brew install tfenv -q
2023-10-27 15:33:11 +02:00
TFENV_ARCH=amd64 tfenv install 1.5.7
tfenv use 1.5.7
2023-10-19 10:17:02 +02:00
else
2023-10-27 15:33:11 +02:00
GO111MODULE=on go install github.com/hashicorp/terraform@v1.5.7
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
brew install tflint -q
brew install tfenv -q
2023-06-17 17:10:25 +02:00
TFENV_ARCH=amd64 tfenv install latest
2023-08-14 23:43:43 +02:00
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
brew install terragrunt -q
else
wget https://github.com/gruntwork-io/terragrunt/releases/latest/download/terragrunt_linux_amd64 -O $HOME/.local/bin/terragrunt
chmod +x $HOME/.local/bin/terragrunt
fi
}
function install_shellcheck() {
# Install shellcheck
if [[ "$(uname)" == "Darwin" ]]; then
brew install shellcheck -q
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() {
if [[ "$(uname)" == "Darwin" ]]; then
brew 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
}
2023-04-13 00:19:04 +02:00
function install_go() {
# Install the golang
if [[ "$(uname)" == "Darwin" ]]; then
brew install golang -q
2023-11-23 14:30:32 +01:00
elif [[ -f $GENTOO ]]; then
2023-04-17 23:13:12 +02:00
sudo emerge 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
2023-09-04 11:10:17 +02:00
pip3 install black $PIPEXTPRE
2023-04-11 10:20:06 +02:00
}
function install_ansible() {
# Install Ansible
2023-09-04 11:10:17 +02:00
pip3 install ansible ansible-lint ansible-core $PIPEXTPRE
pip3 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
2023-09-04 11:10:17 +02:00
pip3 install meraki $PIPEXT
2023-04-11 10:20:06 +02:00
}
function install_azure_cli() {
# Install azure_cli
2023-09-04 11:10:17 +02:00
pip3 install azure-cli $PIPEXTPRE
2023-04-11 10:20:06 +02:00
}
function install_awscli() {
# Install awscli
2023-09-04 11:10:17 +02:00
pip3 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
pip3 install aws-adfs $PIPEXTPRE
}
2023-08-28 10:10:05 +02:00
function install_ytdlp() {
# Install yt-dlp
2023-09-04 11:10:17 +02:00
pip3 install yt-dlp $PIPEXTPRE
2023-08-28 10:10:05 +02:00
}
function install_spotifydl() {
# Install spotify_dl
2023-09-04 11:10:17 +02:00
pip3 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
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
pip3 install speedtest-cli $PIPEXTPRE
}
2023-10-31 14:05:09 +01:00
function install_gh_cli() {
if [[ "$(uname)" == "Darwin" ]]; then
2023-11-23 09:23:19 +01:00
brew install gh
2023-11-23 14:30:32 +01:00
elif [[ -f $GENTOO ]]; then
2023-10-31 14:05:09 +01:00
sudo emerge dev-util/github-cli
fi
}
2023-11-23 09:23:19 +01:00
function install_kubernetes() {
2023-11-23 14:30:32 +01:00
echo -e "$(uname -r)"
2023-11-23 09:23:19 +01:00
if [[ "$(uname)" == "Darwin" ]]; then
wget "https://dl.k8s.io/release/$(curl -L -s https://dl.k8s.io/release/stable.txt)/bin/darwin/arm64/kubectl" -O $HOME/.local/bin/kubectl
chmod +x $HOME/.local/bin/kubectl
2023-11-23 14:30:32 +01:00
else
2023-11-23 09:23:19 +01:00
wget "https://dl.k8s.io/release/$(curl -L -s https://dl.k8s.io/release/stable.txt)/bin/linux/amd64/kubectl" -O $HOME/.local/bin/kubectl
chmod +x $HOME/.local/bin/kubectl
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
2023-04-13 00:19:04 +02:00
command_start install_go
2023-04-11 10:20:06 +02:00
command_start install_pyright
command_start install_lazy
command_start install_bash-language-server
command_start install_yaml-language-server
command_start install_ansible-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
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
2023-04-11 10:20:06 +02:00
command_start update
}
main