Last active
April 5, 2019 21:38
-
-
Save Sakib37/6558e884a2c61d147ae2664c40a9df9a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Maintainer: Mohammad Badruzzaman | |
#set -xe | |
# Environments | |
bold=$(tput bold) | |
red=$(tput setaf 1) | |
green=$(tput setaf 2) | |
normal=$(tput sgr0) | |
# Kubectl completion | |
################################### | |
echo "Installing and setting up kubectl ..." | |
sudo apt-get update > /dev/null 2>&1 && sudo apt-get install -y apt-transport-https > /dev/null 2>&1 | |
curl -s https://packages.cloud.google.com/apt/doc/apt-key.gpg | sudo apt-key add - > /dev/null 2>&1 | |
echo "deb https://apt.kubernetes.io/ kubernetes-xenial main" | sudo tee -a /etc/apt/sources.list.d/kubernetes.list > /dev/null 2>&1 | |
sudo apt-get update > /dev/null 2>&1 | |
sudo apt-get install -y kubectl > /dev/null 2>&1 | |
grep -q -F 'source <(kubectl completion bash)' ~/.bashrc || cat << FOE >> ~/.bashrc | |
# Kubectl Completion | |
source <(kubectl completion bash) | |
alias k=kubectl | |
complete -o default -F __start_kubectl k | |
FOE | |
echo "${green}Kubectl installation Successfull.${normal}" | |
KUBECTL_VERSION=$(kubectl version --client | awk '{print $5}' | awk -F ":" '{print $2}' | head -c -2 | xargs) | |
echo "${green}Kubectl version: ${KUBECTL_VERSION}${normal}" | |
# Setup kube-ps1 | |
echo "Setting up kube-ps1 ..." | |
mkdir -p ~/.kube-ps1 | |
# Source: https://github.com/jonmosco/kube-ps1 | |
wget -q https://raw.githubusercontent.com/jonmosco/kube-ps1/master/kube-ps1.sh -P ~/.kube-ps1/ > /dev/null 2>&1 | |
chmod +x ~/.kube-ps1/kube-ps1.sh | |
grep -q -F 'source ~/.kube-ps1/kube-ps1.sh' ~/.bashrc || echo -e \ | |
'\n# Configure kube-ps1\nsource ~/.kube-ps1/kube-ps1.sh\n' >> ~/.bashrc | |
echo "${green}Kube-ps1 setup Successfull.${normal}" | |
# Kubectx and kubens for bash shell | |
################################### | |
echo "Setting up kubectx and kubens ..." | |
rm -rf ~/.kubectx || true | |
# Source: https://github.com/ahmetb/kubectx | |
git clone https://github.com/ahmetb/kubectx.git ~/.kubectx > /dev/null 2>&1 | |
COMPDIR=$(pkg-config --variable=completionsdir bash-completion) | |
sudo ln -sf ~/.kubectx/completion/kubens.bash $COMPDIR/kubens | |
sudo ln -sf ~/.kubectx/completion/kubectx.bash $COMPDIR/kubectx | |
grep -q -F '# Kubectx and kubens' ~/.bashrc || cat << FOE >> ~/.bashrc | |
# Kubectx and kubens | |
export PATH=~/.kubectx:\$PATH | |
FOE | |
echo "${green}Kubectx and kubens setup Successfull.${normal}" | |
# Helm Completion | |
################################### | |
echo "Installing and setting up helm ..." | |
# Source: https://github.com/helm/helm/blob/master/docs/install.md | |
curl -s https://raw.githubusercontent.com/helm/helm/master/scripts/get | bash > /dev/null 2>&1 | |
# Source: https://github.com/helm/helm/blob/master/docs/helm/helm_completion.md | |
grep -q -F '<(helm completion bash)' ~/.bashrc || echo -e \ | |
'\n# Helm Completion\nsource <(helm completion bash)\n' >> ~/.bashrc | |
echo "${green}Helm installation successful.${normal}" | |
HELM_VERSION=$(helm version -c | awk '{print $2}' | awk -F ":" '{print $2}' | head -c -2 | xargs) | |
echo "${green}Helm version: ${HELM_VERSION}${normal}" | |
# AWS CLI Completion | |
################################### | |
grep -q -F 'complete -C `which aws_completer`' ~/.bashrc || echo -e \ | |
'\n# AWS CLI Completion\ncomplete -C `which aws_completer` aws\n' >> ~/.bashrc | |
# VAULT CLI Completion | |
################################### | |
# Uncomment if you want vault completion | |
grep -q -F 'complete -C /usr/local/bin/vault vault' ~/.bashrc || echo -e \ | |
'\n# Vault CLI Completion\ncomplete -C /usr/local/bin/vault vault\n' >> ~/.bashrc | |
################################# | |
##### NOTE ##### | |
################################# | |
#Git Bash Prompt should be alway the last configuration as it set PS1 variable for the terminal | |
# Git Bash Prompt | |
################################### | |
echo "Setting up bash-git-promt ..." | |
rm -rf ~/.bash-git-prompt | |
# source: https://github.com/magicmonty/bash-git-prompt | |
git clone https://github.com/magicmonty/bash-git-prompt.git ~/.bash-git-prompt --depth=1 > /dev/null 2>&1 | |
grep -q -F 'GIT_PROMPT_ONLY_IN_REPO' ~/.bashrc || cat << EOF >> ~/.bashrc | |
# Bash-git-prompt config | |
GIT_PROMPT_ONLY_IN_REPO=0 | |
source ~/.bash-git-prompt/gitprompt.sh | |
# The following variable value set the PS1 variable | |
GIT_PROMPT_START="\u@\h:\W\e[93m aws:\\\$AWS_PROFILE\e[39m \${ResetColor} \\\$(kube_ps1)" | |
EOF | |
echo "${green}Bash-git-promt setup successful.${normal}" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment