Files
provision/scripts/packages.sh
2025-12-30 19:51:28 -08:00

246 lines
7.3 KiB
Bash
Executable File

#!/usr/bin/env bash
set -euo pipefail
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
source "$SCRIPT_DIR/../lib/common.sh"
source "$SCRIPT_DIR/../lib/package.sh"
log_info "Installing packages"
# Essential packages
PACKAGES=(
"git"
"curl"
"wget"
"tmux"
"jq"
)
# Modern CLI tools
MODERN_TOOLS=(
"starship"
"gh"
)
# Install essential packages
for pkg in "${PACKAGES[@]}"; do
if command_exists "$pkg" || command_exists "${pkg}find" 2>/dev/null; then
log_success "$pkg already installed"
else
log_info "Installing $pkg"
case "$pkg" in
fd)
install_package fd fd-find fd
;;
*)
install_package "$pkg"
;;
esac
fi
done
# Install modern tools
for tool in "${MODERN_TOOLS[@]}"; do
if command_exists "$tool"; then
log_success "$tool already installed"
continue
fi
log_info "Installing $tool"
case "$tool" in
starship)
if is_debian; then
curl -sS https://starship.rs/install.sh | sh -s -- -y
else
install_package starship
fi
;;
zoxide)
if is_debian && ! package_installed zoxide; then
install_cargo zoxide
else
install_package zoxide
fi
;;
eza)
if is_debian && ! package_installed eza; then
if command_exists exa; then
log_success "exa (predecessor) already installed"
else
install_cargo eza
fi
else
install_package eza
fi
;;
gh)
if is_debian && ! package_installed gh; then
maybe_sudo mkdir -p -m 755 /etc/apt/keyrings
wget -qO- https://cli.github.com/packages/githubcli-archive-keyring.gpg | maybe_sudo tee /etc/apt/keyrings/githubcli-archive-keyring.gpg > /dev/null
echo "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/githubcli-archive-keyring.gpg] https://cli.github.com/packages stable main" | maybe_sudo tee /etc/apt/sources.list.d/github-cli.list > /dev/null
update_package_cache
fi
install_package gh gh github-cli
;;
*)
install_package "$tool"
;;
esac
done
# Install 1Password CLI
if command_exists op; then
log_success "1Password CLI already installed"
else
log_info "Installing 1Password CLI"
case "$OS_TYPE" in
macos)
install_cask 1password-cli
;;
debian)
# Add 1Password repository
curl -sS https://downloads.1password.com/linux/keys/1password.asc | \
maybe_sudo gpg --dearmor --output /usr/share/keyrings/1password-archive-keyring.gpg
echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/1password-archive-keyring.gpg] https://downloads.1password.com/linux/debian/$(dpkg --print-architecture) stable main" | \
maybe_sudo tee /etc/apt/sources.list.d/1password.list
update_package_cache
install_package 1password-cli
;;
arch)
install_aur 1password-cli
;;
esac
fi
# Install Tailscale
if command_exists tailscale; then
log_success "Tailscale already installed"
else
log_info "Installing Tailscale"
case "$OS_TYPE" in
macos)
install_cask tailscale
;;
debian)
# Add Tailscale's GPG key and repository
curl -fsSL https://pkgs.tailscale.com/stable/debian/$(lsb_release -cs).noarmor.gpg | maybe_sudo tee /usr/share/keyrings/tailscale-archive-keyring.gpg >/dev/null
curl -fsSL https://pkgs.tailscale.com/stable/debian/$(lsb_release -cs).tailscale-keyring.list | maybe_sudo tee /etc/apt/sources.list.d/tailscale.list
update_package_cache
install_package tailscale
;;
arch)
install_package tailscale
;;
esac
fi
# Install Meslo LG Nerd Font
log_info "Installing Meslo LG Nerd Font"
case "$OS_TYPE" in
macos)
# Check in Homebrew cask font directory and user fonts
if ls "$HOME/Library/Fonts"/MesloLG* 2>/dev/null | grep -q . || \
ls /Library/Fonts/MesloLG* 2>/dev/null | grep -q . || \
ls ~/Library/Fonts/MesloLG* 2>/dev/null | grep -q .; then
log_success "Meslo LG Nerd Font already installed"
else
install_cask font-meslo-lg-nerd-font
fi
;;
debian|arch)
FONT_DIR="$HOME/.local/share/fonts"
if [ -d "$FONT_DIR" ] && ls "$FONT_DIR"/MesloLG* 2>/dev/null | grep -q .; then
log_success "Meslo LG Nerd Font already installed"
else
log_info "Downloading Meslo LG Nerd Font"
ensure_dir "$FONT_DIR"
TEMP_DIR=$(mktemp -d)
cd "$TEMP_DIR"
curl -fsSL -o Meslo.zip https://github.com/ryanoasis/nerd-fonts/releases/download/v3.1.1/Meslo.zip
unzip -q Meslo.zip -d Meslo
mv Meslo/*.ttf "$FONT_DIR/"
cd -
rm -rf "$TEMP_DIR"
# Update font cache
if command_exists fc-cache; then
fc-cache -f "$FONT_DIR"
fi
log_success "Meslo LG Nerd Font installed"
fi
;;
esac
# Install X11 utilities (Linux only)
if is_linux; then
# TWM window manager
if command_exists twm; then
log_success "twm already installed"
else
log_info "Installing twm"
install_package twm twm xorg-twm
fi
# slock screen locker
if command_exists slock; then
log_success "slock already installed"
else
log_info "Installing slock"
install_package slock
fi
# xsetroot (in x11-xserver-utils on Debian, xorg-xsetroot on Arch)
if command_exists xsetroot; then
log_success "xsetroot already installed"
else
log_info "Installing xsetroot"
install_package xsetroot x11-xserver-utils xorg-xsetroot
fi
# feh image viewer/wallpaper setter
if command_exists feh; then
log_success "feh already installed"
else
log_info "Installing feh"
install_package feh
fi
# xclock (in x11-apps on Debian, xorg-xclock on Arch)
if command_exists xclock; then
log_success "xclock already installed"
else
log_info "Installing xclock"
install_package xclock x11-apps xorg-xclock
fi
# xload (in x11-apps on Debian, xorg-xload on Arch)
if command_exists xload; then
log_success "xload already installed"
else
log_info "Installing xload"
install_package xload x11-apps xorg-xload
fi
# XDM display manager
if command_exists xdm; then
log_success "xdm already installed"
else
log_info "Installing xdm"
install_package xdm
fi
fi
# Install TPM (Tmux Plugin Manager)
TPM_DIR="${XDG_CONFIG_HOME:-$HOME/.config}/tmux/plugins/tpm"
if [ ! -d "$TPM_DIR" ]; then
log_info "Installing TPM (Tmux Plugin Manager)"
ensure_dir "$(dirname "$TPM_DIR")"
git clone https://github.com/tmux-plugins/tpm "$TPM_DIR"
log_success "TPM installed"
else
log_success "TPM already installed"
fi
log_success "All packages installed"