scripts/bootstrap.sh
2025-06-30 21:59:02 -05:00

158 lines
3.2 KiB
Bash
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#!/usr/bin/env bash
set -euo pipefail
# ------------------------------
# Common Packages (install these on ALL systems)
# ------------------------------
COMMON_PACKAGES=(
wget
curl
git
neovim
tmux
fzf
)
# ------------------------------
# Privilege Detection
# ------------------------------
if [[ "$EUID" -eq 0 ]]; then
SUDO=""
echo "✅ Running as root — no sudo needed."
else
if command -v sudo >/dev/null 2>&1; then
SUDO="sudo"
echo "⚠ Not running as root — using sudo where needed."
else
echo "❌ This script requires root privileges to install packages."
echo "Please either:"
echo " - Run this script as root"
echo " - Or install sudo and add your user to the sudo group"
exit 1
fi
fi
# ------------------------------
# Detect Distro
# ------------------------------
detect_os() {
if [[ -f /etc/os-release ]]; then
source /etc/os-release
case "$ID" in
debian | ubuntu)
echo "debian"
;;
arch)
echo "arch"
;;
alpine)
echo "alpine"
;;
centos | rhel)
echo "rhel"
;;
fedora)
echo "fedora"
;;
*)
echo "unsupported"
;;
esac
else
echo "unsupported"
fi
}
# ------------------------------
# Installers with Quiet Output
# ------------------------------
install_packages_debian() {
echo "🔧 Updating package lists (APT)..."
${SUDO} apt update -y >/dev/null 2>&1
echo "📦 Installing common packages (APT)..."
${SUDO} apt install -y "${COMMON_PACKAGES[@]}" >/dev/null 2>&1
}
install_packages_arch() {
echo "🔧 Updating package lists (Pacman)..."
${SUDO} pacman -Syu --noconfirm >/dev/null 2>&1
echo "📦 Installing common packages (Pacman)..."
${SUDO} pacman -S --noconfirm "${COMMON_PACKAGES[@]}" >/dev/null 2>&1
}
install_packages_alpine() {
echo "🔧 Updating package lists (APK)..."
${SUDO} apk update >/dev/null 2>&1
echo "📦 Installing common packages (APK)..."
${SUDO} apk add "${COMMON_PACKAGES[@]}" >/dev/null 2>&1
}
install_packages_rhel() {
echo "📦 Installing common packages (YUM)..."
${SUDO} yum install -y "${COMMON_PACKAGES[@]}" >/dev/null 2>&1
}
install_packages_fedora() {
echo "📦 Installing common packages (DNF)..."
${SUDO} dnf install -y "${COMMON_PACKAGES[@]}" >/dev/null 2>&1
}
# ------------------------------
# LazyVim Installer (Optional)
# ------------------------------
install_lazyvim() {
if command -v nvim >/dev/null 2>&1; then
echo "🎨 Installing LazyVim..."
git clone https://github.com/LazyVim/starter ~/.config/nvim >/dev/null 2>&1
nvim --headless "+Lazy sync" +qa >/dev/null 2>&1
else
echo " Neovim not found, skipping LazyVim install."
fi
}
# ------------------------------
# Main Logic
# ------------------------------
main() {
OS=$(detect_os)
echo "🖥 Detected OS: $OS"
case "$OS" in
debian)
install_packages_debian
;;
arch)
install_packages_arch
;;
alpine)
install_packages_alpine
;;
rhel)
install_packages_rhel
;;
fedora)
install_packages_fedora
;;
*)
echo "❌ Unsupported OS. Exiting."
exit 1
;;
esac
install_lazyvim
echo "✅ Setup complete!"
}
main "$@"