Dot-Zsh/setup.sh
2025-12-03 02:34:09 +00:00

195 lines
6.5 KiB
Bash
Executable File

#!/bin/bash
set -e
# Variables
ZSH_CUSTOM="${ZSH_CUSTOM:-$HOME/.oh-my-zsh/custom}"
DOTFILES_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
# Bold Colors
YELLOW='\033[1;33m'
BLUE='\033[1;34m'
RED='\033[1;31m'
GREEN='\033[1;32m'
NC='\033[0m'
# OS Detection
echo -e "${BLUE} LOG:${YELLOW} Checking System...${NC}"
if [ -f /etc/os-release ]; then
. /etc/os-release
OS=$ID
fi
# Package Installation
PACKAGES=(
curl wget git sudo
zsh tmux
unzip tar gzip
build-essential
openssl
python bison mercurial
ripgrep fd bat fzf jq
btop httpie gnupg
zoxide stow
bind nmap socat tcpdump net-tools
strace gdb hexyl
)
FINAL_LIST=""
for pkg in "${PACKAGES[@]}"; do
case "$pkg" in
"build-essential")
[ "$OS" == "arch" ] && pkg="base-devel"
[ "$OS" == "ubuntu" ] && pkg="build-essential"
;;
"python")
[ "$OS" == "arch" ] && pkg="python"
[ "$OS" == "ubuntu" ] && pkg="python3 python3-pip python3-venv"
;;
"fd")
[ "$OS" == "arch" ] && pkg="fd"
[ "$OS" == "ubuntu" ] && pkg="fd-find"
;;
"bat")
[ "$OS" == "arch" ] && pkg="bat"
[ "$OS" == "ubuntu" ] && pkg="bat"
;;
"openssl")
[ "$OS" == "arch" ] && pkg="openssl"
[ "$OS" == "ubuntu" ] && pkg="libssl-dev"
;;
"bind")
[ "$OS" == "arch" ] && pkg="bind"
[ "$OS" == "ubuntu" ] && pkg="dnsutils"
;;
*)
esac
FINAL_LIST="$FINAL_LIST $pkg"
done
# Extra packages for specific distros
if [ "$OS" == "arch" ] || [ "$OS" == "manjaro" ]; then
FINAL_LIST="$FINAL_LIST eza"
fi
if [ "$OS" == "ubuntu" ] || [ "$OS" == "debian" ]; then
FINAL_LIST="$FINAL_LIST ca-certificates bsdmainutils pkg-config cmake"
fi
echo -e "${BLUE} LOG:${YELLOW} Installing: ${NC}$FINAL_LIST"
if [ "$OS" == "arch" ] || [ "$OS" == "manjaro" ]; then
sudo pacman -S --noconfirm --needed $FINAL_LIST
elif [ "$OS" == "ubuntu" ] || [ "$OS" == "debian" ]; then
sudo DEBIAN_FRONTEND=noninteractive apt-get update
sudo DEBIAN_FRONTEND=noninteractive apt-get install -y $FINAL_LIST
fi
if [ "$OS" == "ubuntu" ] || [ "$OS" == "debian" ]; then
echo -e "${BLUE} LOG:${YELLOW} Fixing Ubuntu binary names...${NC}"
[ -f /usr/bin/fdfind ] && sudo ln -sf /usr/bin/fdfind /usr/local/bin/fd
[ -f /usr/bin/batcat ] && sudo ln -sf /usr/bin/batcat /usr/local/bin/bat
fi
# Docker Installation
if command -v docker &> /dev/null; then
echo -e "${GREEN} LOG: Docker is already installed. Skipping...${NC}"
else
echo -e "${BLUE} LOG:${YELLOW} Docker not found. Installing Native Docker Engine...${NC}"
# ARCH LINUX
if [ "$OS" == "arch" ] || [ "$OS" == "manjaro" ]; then
sudo pacman -S --noconfirm --needed docker docker-compose
fi
# UBUNTU / DEBIAN
if [ "$OS" == "ubuntu" ] || [ "$OS" == "debian" ]; then
echo -e "${BLUE} LOG:${YELLOW} Setting up Official Docker Repository...${NC}"
sudo install -m 0755 -d /etc/apt/keyrings
sudo curl -fsSL https://download.docker.com/linux/ubuntu/gpg -o /etc/apt/keyrings/docker.asc
sudo chmod a+r /etc/apt/keyrings/docker.asc
echo \
"deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.asc] https://download.docker.com/linux/ubuntu \
$(. /etc/os-release && echo "${UBUNTU_CODENAME:-$VERSION_CODENAME}") stable" | \
sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
sudo DEBIAN_FRONTEND=noninteractive apt-get update
sudo DEBIAN_FRONTEND=noninteractive apt-get install -y docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin
fi
fi
# Install NVM, GVM, Rustup
echo -e "${BLUE} LOG:${YELLOW} Installing NVM, GVM and Rustup...${NC}"
# NVM
if [ ! -d "$HOME/.nvm" ]; then
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.40.3/install.sh | bash
fi
# GVM
if [ ! -d "$HOME/.gvm" ]; then
bash < <(curl -s -S -L https://raw.githubusercontent.com/moovweb/gvm/master/binscripts/gvm-installer)
fi
# Rustup
if ! command -v rustup &> /dev/null; then
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y
fi
# Install Eza with Cargo
echo -e "${BLUE} LOG:${YELLOW} Installing Eza via Cargo...${NC}"
if ! command -v eza &> /dev/null; then
source "$HOME/.cargo/env"
cargo install eza
fi
# Docker Group
echo -e "${BLUE} LOG:${YELLOW} Setting up Docker group...${NC}"
if ! getent group docker > /dev/null 2>&1; then
sudo groupadd docker
fi
sudo usermod -aG docker $(whoami)
# Zsh and Oh My Zsh Setup
echo -e "${BLUE} LOG:${YELLOW} Setting up Oh My Zsh...${NC}"
if [ ! -d "$HOME/.oh-my-zsh" ]; then
sh -c "$(curl -fsSL https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh)" "" --unattended
fi
echo -e "${BLUE} LOG:${YELLOW} Installing Zsh plugins...${NC}"
if [ ! -d "$ZSH_CUSTOM/plugins/zsh-syntax-highlighting" ]; then
git clone https://github.com/zsh-users/zsh-syntax-highlighting.git "$ZSH_CUSTOM/plugins/zsh-syntax-highlighting"
fi
if [ ! -d "$ZSH_CUSTOM/plugins/zsh-autosuggestions" ]; then
git clone https://github.com/zsh-users/zsh-autosuggestions "$ZSH_CUSTOM/plugins/zsh-autosuggestions"
fi
# Making Zsh the default shell
echo -e "${BLUE} LOG:${YELLOW} Setting Zsh as the default shell...${NC}"
if [ "$SHELL" != "$(which zsh)" ]; then
sudo chsh -s "$(which zsh)" $(whoami)
fi
# File Cleanup
echo -e "${BLUE} LOG:${YELLOW} Cleaning up old configs...${NC}"
rm -f "$HOME/.zshrc" "$HOME/.zsh_aliases"
# Ensure secrets file exists
echo -e "${BLUE} LOG:${YELLOW} Ensuring secrets file exists...${NC}"
touch "$HOME/.zsh_secrets"
# Stow Dotfiles
echo -e "${BLUE} LOG:${YELLOW} Stowing dotfiles...${NC}"
cd "$DOTFILES_DIR"
stow . --target="$HOME" --ignore="setup.sh" --ignore=".git" --ignore=".gitignore" --ignore="README.md" --ignore=".zsh_secrets" --ignore=".zsh_secrets.example" --ignore="LICENSE" --ignore="Makefile"
# Finish
echo -e "${GREEN} LOG: Setup Complete! Please restart your terminal to apply all changes.${NC}"
echo -e "${GREEN} You may need to log out and back in for Docker group changes to take effect.${NC}"
echo -e "${GREEN} Setup GVM by running 'go listall' and 'gvm use [version] --default'.${NC}"
echo -e "${GREEN} Setup NVM by running 'nvm install --lts' and 'nvm use --lts'${NC}"
echo -e "${GREEN} Setup Rust by running 'rustup default stable'${NC}"