Ubuntu Setup

Ubuntu Install:

This is a bash script that is intended to automate the process of setting up a DevOps environment on a Ubuntu-based operating system. It can be used to set up a development environment on a new machine, ensuring that all the necessary tools and configurations are in place. This can be particularly useful for developers working on a team, as it ensures that everyone is using the same tools and configurations.

#!/bin/bash

# Update package index
echo -e -e "\e[93mUpdate package index...\e[0m"
sudo apt-get update
sudo apt-get install -y zsh
echo

# Install Terraform
echo -e -e "\e[93mInstall Terraform and add to PATH...\e[0m"
sudo snap install terraform --classic

# Add Terraform to PATH
echo'export PATH="$PATH:/usr/local/bin/terraform"' >> ~/.zshrc
source ~/.zshrc
echo

# Install Ansible
echo -e "\e[93mInstall Ansible and add to PATH...\e[0m"
sudo apt-get install -y ansible

# Add Ansible to PATH
echo 'export PATH="$PATH:/usr/bin/ansible"' >> ~/.zshrc
source ~/.zshrc
echo

# Install Git
sudo apt-get install -y git

# Add Git to Path
echo 'export PATH="$PATH:/usr/bin/git"' >> ~/.zshrc
source ~/.zshrc
echo

# Install Docker
sudo snap install docker

# Add Docker to PATH
echo 'export PATH="$PATH:/usr/bin/docker"' >> ~/.zshrc
source ~/.zshrc
echo

# Install Kubernetes
echo -e "\e[93mInstall Kubernetes and add to PATH...\e[0m"
snap install kubectl


# Add Kubernetes to PATH
echo 'export PATH="$PATH:/usr/local/bin/kubectl"' >> ~/.zshrc
source ~/.zshrc
echo

# Install Helm
echo -e "\e[93mInstall Helm and add to PATH...\e[0m"
curl https://raw.githubusercontent.com/helm/helm/master/scripts/get-helm-3 | bash

# Add Helm to PATH
echo 'export PATH="$PATH:/usr/local/bin/helm"' >> ~/.zshrc
source ~/.zshrc
echo

# Install AWS CLI
echo -e "\e[93mInstall AWS CLI and add to PATH...\e[0m"
sudo apt-get install -y awscli

# Add AWS CLI to PATH
echo 'export PATH="$PATH:/usr/local/bin/aws"' >> ~/.zshrc
source ~/.zshrc
echo

# Add kubie to PATH
echo 'export PATH="$PATH:~/.kubie"' >> ~/.zshrc
source ~/.zshrc
echo

# Add kubectl aliases to zshrc file
## Generate a secure password and copy it to clipboard
echo -e "\e[93mAdd kubectl aliases to zshrc file...\e[0m"
cat > ~/.zshrc <<- EOS
alias ll="ls -lah"
alias vissh="vi ~/.ssh/config"
alias kgp="k get pods -o wide"
alias kgn="k get nodes -o wide"
alias kgs="k get service"
alias kgpv="k get pv"
alias kgpvc="k get pvc"
alias kd="k describe"
alias kns="kubie ns"
alias kcx="kubie ctx"
alias pod-check="kgp -A -o wide | grep -v Running | grep -v Comp"
alias pod-count="kgp -A | wc -l"

## SSL
alias certexp="openssl x509 -enddate -noout -in"
alias certcheck="openssl x509 -noout -text -in"
alias caverify="openssl verify -CAfile"

## Networking
alias mtr="sudo /usr/local/sbin/mtr"
alias nlp="nslookup"

## Git
alias gcm="git commit -m"
alias gp="git push"
alias gpt="git push --tags"

## Ansible
alias ansible="/usr/local/opt/ansible@2.8/bin/ansible"
alias ansible-playbook="/usr/local/opt/ansible@2.8/bin/ansible-playbook"
alias ansible2="/usr/local/opt/ansible@2.9/bin/ansible"
alias ansible2-playbook="/usr/local/opt/ansible@2.9/bin/ansible-playbook"
alias ansible4="/usr/local/opt/ansible/bin/ansible"
alias ansible4-galaxy="/usr/local/opt/ansible/bin/ansible-galaxy"
alias ansible4-playbook="/usr/local/opt/ansible/bin/ansible-playbook"

## Helm
alias helm="/usr/local/opt/helm/bin/helm"

## Zsh Auto Complete
autoload -U up-line-or-beginning-search
autoload -U down-line-or-beginning-search
zle -N up-line-or-beginning-search
zle -N down-line-or-beginning-search
bindkey "^[[A" up-line-or-beginning-search
bindkey "^[[B" down-line-or-beginning-search
EOS

source ~/.zshrc

The script starts by updating the package index, which is necessary to ensure that the system is aware of the latest versions of packages that are available for installation.

After updating the package index, the script installs the Zsh shell, which is a popular alternative to the default Bash shell on Linux systems. The script then proceeds to install and configure a number of other tools that are commonly used in DevOps workflows:

  • Terraform, infrastructure as code tool for provisioning and managing cloud infrastructure.

  • Ansible, a configuration management and automation tool.

  • Git, a distributed version control system that is used for managing the source code of software projects

  • Docker, a platform that allows developers to easily create, deploy, and run applications in containers.

  • Kubernetes, an open-source container orchestration system.

  • Helm, a package manager for Kubernetes.

  • AWS CLI, command line interface for Amazon Web Services.

  • Python 3, a popular programming language.

  • kubie, a tool that makes it easier to switch between different Kubernetes contexts and namespaces.

Once the tools have been installed, the script adds them to the PATH environment variable, which allows them to be easily executed from anywhere on the system.

The script also creates aliases for these tools, which are shortcuts that can be used to run the tools with certain options or arguments. For example, the script creates an alias “k” for kubectl, which allows the user to run kubectl commands by typing “k” instead of “kubectl”.

In addition, the script adds a number of other useful alias commands for different tasks. for example,

  • “kg” for “kubectl get”

  • “kgp” for “kubectl get pods -o wide”

  • “kgs” for “kubectl get service”

  • “kgpv” for “kubectl get pv”

  • “kgpvc” for “kubectl get pvc”

Finally, the script sets up Zsh autocomplete, which allows the user to press the TAB key to automatically complete commands and options as they are typed.

Overall, this script is intended to automate the process of setting up a development and operations environment on Ubuntu and make the user more efficient by providing a set of useful alias commands.

Last updated