Skip to content

Instantly share code, notes, and snippets.

@hugobrilhante
Last active April 14, 2024 03:13
Show Gist options
  • Select an option

  • Save hugobrilhante/ab56d5ace1e338be50d65342dc9355ae to your computer and use it in GitHub Desktop.

Select an option

Save hugobrilhante/ab56d5ace1e338be50d65342dc9355ae to your computer and use it in GitHub Desktop.
#!/bin/sh
set -e
# Function to display progress
show_progress() {
echo "$1 ... "
}
# Function to display success
show_success() {
echo "OK"
}
# Function to display error and exit
show_error_and_exit() {
echo "ERROR: $1"
exit 1
}
# Function to check if a program is installed
check_installed() {
command -v "$1" >/dev/null 2>&1
}
# Function to install pyenv dependencies
install_pyenv_dependencies() {
local dependencies="build-essential libssl-dev zlib1g-dev libbz2-dev libreadline-dev libsqlite3-dev curl libncursesw5-dev xz-utils tk-dev libxml2-dev libxmlsec1-dev libffi-dev liblzma-dev"
sudo apt-get update >/dev/null || show_error_and_exit "Failed to update apt"
sudo apt-get install -y $dependencies >/dev/null || show_error_and_exit "Failed to install pyenv dependencies"
}
# Function to add Pyenv configurations to a file
add_pyenv_config() {
echo "" >> "$1"
echo "# Pyenv config" >> "$1"
echo 'export PYENV_ROOT="$HOME/.pyenv"' >> "$1"
echo 'command -v pyenv >/dev/null || export PATH="$PYENV_ROOT/bin:$PATH"' >> "$1"
echo 'eval "$(pyenv init --path)"' >> "$1"
}
# Function to install Docker
install_docker() {
printf "Do you want to install Docker? (Y/n): "
read choice
choice=${choice:-Y} # Set choice to Y if input is empty
if [ "$choice" = "Y" ] || [ "$choice" = "y" ]; then
show_progress "Installing Docker"
sudo apt-get update >/dev/null || show_error_and_exit "Failed to update apt"
sudo apt-get install -y ca-certificates >/dev/null || show_error_and_exit "Failed to install CA certificates"
sudo install -m 0755 -d /etc/apt/keyrings >/dev/null || show_error_and_exit "Failed to create apt keyring directory"
sudo curl -fsSL https://download.docker.com/linux/ubuntu/gpg -o /etc/apt/keyrings/docker.asc >/dev/null || show_error_and_exit "Failed to download Docker GPG key"
sudo chmod a+r /etc/apt/keyrings/docker.asc >/dev/null || show_error_and_exit "Failed to set permissions for Docker GPG key"
echo "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.asc] https://download.docker.com/linux/ubuntu $(. /etc/os-release && echo "$VERSION_CODENAME") stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null || show_error_and_exit "Failed to add Docker repository to apt sources file"
sudo apt-get update >/dev/null || show_error_and_exit "Failed to update package index"
sudo apt-get install -y docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin >/dev/null || show_error_and_exit "Failed to install Docker"
if ! grep -q "^docker:" /etc/group; then
sudo groupadd docker >/dev/null || show_error_and_exit "Failed to create 'docker' group"
fi
sudo usermod -aG docker $USER >/dev/null || show_error_and_exit "Failed to add user to 'docker' group"
show_success
else
echo "Skipping Docker installation."
fi
}
# Function to install Pyenv
install_pyenv() {
printf "Do you want to install Pyenv? (Y/n): "
read choice
choice=${choice:-Y} # Set choice to Y if input is empty
if [ "$choice" = "Y" ] || [ "$choice" = "y" ]; then
show_progress "Installing Pyenv"
install_pyenv_dependencies
curl -sL https://github.com/pyenv/pyenv-installer/raw/master/bin/pyenv-installer | bash 2>/dev/null || show_error_and_exit "Failed to install pyenv"
add_pyenv_config ~/.bashrc
add_pyenv_config ~/.profile
show_success
else
echo "Skipping Pyenv installation."
fi
}
# Function to install Zsh
install_zsh() {
printf "Do you want to install Zsh? (Y/n): "
read choice
choice=${choice:-Y} # Set choice to Y if input is empty
if [ "$choice" = "Y" ] || [ "$choice" = "y" ]; then
show_progress "Installing Oh My Zsh"
sudo apt-get update >/dev/null || show_error_and_exit "Failed to update apt"
sudo apt-get install -y zsh >/dev/null || show_error_and_exit "Failed to install Zsh"
sh -c "$(curl -fsSL https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh)" || show_error_and_exit "Failed to install Oh My Zsh"
if check_installed "pyenv"; then
add_pyenv_config ~/.zshrc # Add Pyenv config to .zshrc
fi
show_success
else
echo "Skipping Zsh installation."
fi
}
# Function to install Curl
install_curl() {
printf "Do you want to install Curl? (Y/n): "
read choice
choice=${choice:-Y} # Set choice to Y if input is empty
if [ "$choice" = "Y" ] || [ "$choice" = "y" ]; then
show_progress "Installing Curl"
sudo apt-get update >/dev/null || show_error_and_exit "Failed to update apt"
sudo apt-get install -y curl >/dev/null || show_error_and_exit "Failed to install Curl"
show_success
else
echo "Skipping Curl installation."
fi
}
# Function to install Git
install_git() {
printf "Do you want to install Git? (Y/n): "
read choice
choice=${choice:-Y} # Set choice to Y if input is empty
if [ "$choice" = "Y" ] || [ "$choice" = "y" ]; then
show_progress "Installing Git"
sudo apt-get update >/dev/null || show_error_and_exit "Failed to update apt"
sudo apt-get install -y git >/dev/null || show_error_and_exit "Failed to install Git"
show_success
else
echo "Skipping Git installation."
fi
}
# Function to install Vim
install_vim() {
printf "Do you want to install Vim? (Y/n): "
read choice
choice=${choice:-Y} # Set choice to Y if input is empty
if [ "$choice" = "Y" ] || [ "$choice" = "y" ]; then
show_progress "Installing Vim"
sudo apt-get update >/dev/null || show_error_and_exit "Failed to update apt"
sudo apt-get install -y vim >/dev/null || show_error_and_exit "Failed to install Vim"
show_success
else
echo "Skipping Vim installation."
fi
}
# Install Curl
install_curl
# Install Git
install_git
# Install Vim
install_vim
# Install Docker
install_docker
# Install Pyenv
install_pyenv
# Install Zsh
install_zsh
# Ask the user if they want to reboot the machine
printf "Do you want to reboot the machine now? (Y/n): "
read choice
choice=${choice:-Y} # Set choice to Y if input is empty
case "$choice" in
y|Y ) sudo reboot ;;
n|N ) echo "The machine will not be rebooted." ;;
* ) echo "Invalid option. The machine will not be rebooted." ;;
esac
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment