scripts/bootstrap.sh
2025-06-30 21:54:48 -05:00

145 lines
2.6 KiB
Bash

#!/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
# ------------------------------
install_packages_debian() {
${SUDO} apt update -y
${SUDO} apt install -y "${COMMON_PACKAGES[@]}"
}
install_packages_arch() {
${SUDO} pacman -Syu --noconfirm
${SUDO} pacman -S --noconfirm "${COMMON_PACKAGES[@]}"
}
install_packages_alpine() {
${SUDO} apk update
${SUDO} apk add "${COMMON_PACKAGES[@]}"
}
install_packages_rhel() {
${SUDO} yum install -y "${COMMON_PACKAGES[@]}"
}
install_packages_fedora() {
${SUDO} dnf install -y "${COMMON_PACKAGES[@]}"
}
# ------------------------------
# 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
nvim --headless "+Lazy sync" +qa
else
echo "Neovim not found, skipping LazyVim install."
fi
}
# ------------------------------
# Main Logic
# ------------------------------
main() {
OS=$(detect_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 "$@"