#!/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}" OS="unknown" if [ -f /etc/os-release ]; then . /etc/os-release OS=$ID fi if [ "$OS" = "unknown" ] || [ -z "$OS" ]; then echo -e "${RED} ERROR:${NC} Could not detect operating system. /etc/os-release not found or ID not set." exit 1 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 rclone ) 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 # Check if we are running in WSL if grep -qEi "(Microsoft|WSL)" /proc/version &> /dev/null; then echo -e "${RED} LOG: WSL Detected! Skipping Native Docker installation.${NC}" echo -e "${RED} >>> ACTION REQUIRED: Please install Docker Desktop for Windows.${NC}" echo -e "${RED} >>> Ensure 'Use WSL 2 based engine' is enabled in Docker settings.${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 sudo systemctl enable --now docker 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 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 # Go and GVM wget https://go.dev/dl/go1.25.4.linux-amd64.tar.gz -O /tmp/go1.25.4.linux-amd64.tar.gz sudo rm -rf /usr/local/go sudo tar -C /usr/local -xzf /tmp/go1.25.4.linux-amd64.tar.gz rm -f /tmp/go1.25.4.linux-amd64.tar.gz 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 # --------------------------------------------------------------------- # GIT CREDENTIAL CONFIGURATION # --------------------------------------------------------------------- echo -e "${BLUE} LOG:${YELLOW} Configuring Git Credentials...${NC}" if grep -qEi "(Microsoft|WSL)" /proc/version &> /dev/null; then # Linux Server: Cache credentials for 12 hours if [ -f "$GCM_WIN" ]; then git config --global credential.helper "! \"$GCM_WIN\"" fi else # Linux Server: Cache credentials for 12 hour git config --global credential.helper 'cache --timeout=43200' --replace-all 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" --ignore="provision.sh" --ignore="storagebox.sh" # Language Setup echo -e "${BLUE} LOG:${YELLOW} Finalizing Language Setup...${NC}" set +e # 1. Setup Node (NVM) export NVM_DIR="$HOME/.nvm" [ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" if command -v nvm &> /dev/null; then echo -e "${BLUE} LOG:${YELLOW} Installing Node LTS...${NC}" nvm install --lts nvm use --lts echo -e "${BLUE} LOG:${YELLOW} Installing Global Tools (pnpm, yarn)...${NC}" npm install -g pnpm yarn || true fi # 2. Setup Go (GVM) unalias cd 2>/dev/null || true [[ -s "$HOME/.gvm/scripts/gvm" ]] && source "$HOME/.gvm/scripts/gvm" if command -v gvm &> /dev/null; then echo -e "${BLUE} LOG:${YELLOW} Installing Go 1.24.11...${NC}" gvm install go1.24.11 -B gvm use go1.24.11 --default if [ $? -eq 0 ]; then echo -e "${BLUE} LOG:${YELLOW} Go version: $(go version)${NC}" else echo -e "${RED} ERROR:${NC} GVM failed to install Go 1.24.11" fi fi # 3. Setup Rust [ -f "$HOME/.cargo/env" ] && source "$HOME/.cargo/env" if command -v rustup &> /dev/null; then echo -e "${BLUE} LOG:${YELLOW} Updating Rust to stable...${NC}" rustup default stable rustup update fi set -e # Finish echo -e "${GREEN} LOG: Setup Complete! Please restart your terminal to apply all changes. ${NC} "