#!/usr/bin/env bash set -euo pipefail # ANSI colors RED="\033[31m" RESET="\033[0m" echo -e "🔧 Starting dotfiles bootstrap...\n" UNAME=$(uname -s) if [[ $UNAME == "Darwin" ]]; then echo -e "✅ Detected supported system: 󰀵 macOS" elif [[ $UNAME == "Linux" ]]; then LINUX_DISTRO=$(grep '^NAME=' /etc/os-release | cut -d= -f2 | tr -d '"') if [[ $LINUX_DISTRO == "Ubuntu" ]]; then echo -e "✅ Detected supported system: ${RED}󰕈${RESET} Ubuntu" elif [[ $LINUX_DISTRO =~ "Debian" ]]; then echo -e "✅ Detected supported system: ${RED}󰣚${RESET} Debian" fi else echo -e "⚠️ Unsupported system detected. This dotfiles currently supports only macOS, Debian and Ubuntu." fi echo "" # --- Load GitHub token securely --- if [ -z "${GITHUB_DOTFILES_TOKEN:-}" ]; then if [ -f "$HOME/.zshenv.local" ]; then echo "🔄 Loading environment from $HOME/.zshenv.local ..." set -a . "$HOME/.zshenv.local" set +a else echo "🚫 ERROR: No GITHUB_DOTFILES_TOKEN found in environment or $HOME/.zshenv.local" echo " Please export it or create $HOME/.zshenv.local with:" echo " GITHUB_DOTFILES_TOKEN=github_pat_XXXX" exit 1 fi fi # Confirm token loaded if [ -z "${GITHUB_DOTFILES_TOKEN:-}" ]; then echo "🚫 ERROR: GITHUB_DOTFILES_TOKEN still not set after loading." exit 1 fi echo "🔑 GitHub token loaded successfully." # --- Install chezmoi if needed --- if ! command -v chezmoi >/dev/null 2>&1; then echo "🔄 Installing chezmoi..." bash -c "$(curl -fsSL https://chezmoi.io/get)" -- -b "$HOME/.local/bin" else echo "✅ Chezmoi already installed." fi # --- Run chezmoi init or update --- echo "🚀 Initializing chezmoi from private GitHub repo..." CHEZMOI_SOURCE="$HOME/.local/share/chezmoi" if [ -d "$CHEZMOI_SOURCE/.git" ]; then echo "🔄 Existing chezmoi repo found, updating..." chezmoi update --init else echo "🆕 No existing chezmoi repo found, initializing..." chezmoi init --apply "https://radekkozak:${GITHUB_DOTFILES_TOKEN}@github.com/radekkozak/dotfiles.git" ( cd "$CHEZMOI_SOURCE" && git remote set-url origin git@github.com:radekkozak/dotfiles.git ) fi echo "" echo "✅ Dotfiles applied successfully." echo -e "❗${RED}Please open a new terminal or re-login to fully load updated environment${RESET}❗"