Add cross-platform package installation scripts

This commit is contained in:
Bastian Gruber 2026-01-29 20:06:38 +00:00
parent 98b265a8d0
commit 34f1f5d63b
Signed by: gruberb
GPG key ID: 426AF1CBA0530691
6 changed files with 300 additions and 5 deletions

View file

@ -4,14 +4,22 @@
[data] [data]
{{- if eq $hostname "maple" }} {{- if eq $hostname "maple" }}
machine = "server" machine = "server"
hasGUI = false
pkgManager = "apt"
editor = "hx" editor = "hx"
{{- else if eq $hostname "rufus" }} {{- else if eq $hostname "rufus" }}
machine = "laptop" machine = "laptop"
hasGUI = true
pkgManager = "pacman"
editor = "hx" editor = "hx"
{{- else if eq $os "darwin" }} {{- else if eq $os "darwin" }}
machine = "macbook" machine = "macbook"
hasGUI = true
pkgManager = "brew"
editor = "hx" editor = "hx"
{{- else }} {{- else }}
machine = "unknown" machine = "unknown"
hasGUI = false
pkgManager = "apt"
editor = "hx" editor = "hx"
{{- end }} {{- end }}

View file

@ -0,0 +1,150 @@
#!/bin/bash
# Install base packages using the appropriate package manager
# This script runs once before other chezmoi operations
set -e
echo "==> Installing base packages..."
{{ if eq .pkgManager "pacman" -}}
# Arch Linux (rufus)
echo "==> Detected Arch Linux, using pacman..."
# Update package database
sudo pacman -Sy --noconfirm
# Core CLI tools
sudo pacman -S --noconfirm --needed \
fish \
helix \
neovim \
ripgrep \
fd \
bat \
eza \
fzf \
jq \
tmux \
git \
base-devel \
keychain
{{ if .hasGUI -}}
# GUI tools (only on machines with GUI)
# Check if yay is installed for AUR packages
if ! command -v yay &> /dev/null; then
echo "==> Installing yay for AUR packages..."
cd /tmp
git clone https://aur.archlinux.org/yay.git
cd yay
makepkg -si --noconfirm
cd -
rm -rf /tmp/yay
fi
# Install Ghostty from AUR
echo "==> Installing Ghostty from AUR..."
yay -S --noconfirm --needed ghostty
{{ end -}}
{{ else if eq .pkgManager "apt" -}}
# Debian/Ubuntu (maple server)
echo "==> Detected Debian/Ubuntu, using apt..."
sudo apt-get update
# Core CLI tools
sudo apt-get install -y \
fish \
neovim \
ripgrep \
fd-find \
bat \
fzf \
jq \
tmux \
git \
curl \
wget \
build-essential \
keychain
# fd is installed as fdfind on Debian, create symlink
if [ ! -f ~/.local/bin/fd ] && command -v fdfind &> /dev/null; then
mkdir -p ~/.local/bin
ln -sf $(which fdfind) ~/.local/bin/fd
fi
# bat is installed as batcat on Debian, create symlink
if [ ! -f ~/.local/bin/bat ] && command -v batcat &> /dev/null; then
mkdir -p ~/.local/bin
ln -sf $(which batcat) ~/.local/bin/bat
fi
# Install eza (modern ls replacement)
if ! command -v eza &> /dev/null; then
echo "==> Installing eza..."
sudo mkdir -p /etc/apt/keyrings
wget -qO- https://raw.githubusercontent.com/eza-community/eza/main/deb.asc | sudo gpg --dearmor -o /etc/apt/keyrings/gierens.gpg
echo "deb [signed-by=/etc/apt/keyrings/gierens.gpg] http://deb.gierens.de stable main" | sudo tee /etc/apt/sources.list.d/gierens.list
sudo chmod 644 /etc/apt/keyrings/gierens.gpg /etc/apt/sources.list.d/gierens.list
sudo apt-get update
sudo apt-get install -y eza
fi
# Install Helix from GitHub releases (not in apt repos)
if ! command -v hx &> /dev/null; then
echo "==> Installing Helix from GitHub releases..."
HELIX_VERSION=$(curl -s https://api.github.com/repos/helix-editor/helix/releases/latest | jq -r '.tag_name')
curl -Lo /tmp/helix.tar.xz "https://github.com/helix-editor/helix/releases/download/${HELIX_VERSION}/helix-${HELIX_VERSION}-x86_64-linux.tar.xz"
sudo tar -xf /tmp/helix.tar.xz -C /usr/local/lib/
sudo ln -sf /usr/local/lib/helix-${HELIX_VERSION}-x86_64-linux/hx /usr/local/bin/hx
rm /tmp/helix.tar.xz
echo "==> Helix installed. Set HELIX_RUNTIME=/usr/local/lib/helix-${HELIX_VERSION}-x86_64-linux/runtime"
fi
{{ else if eq .pkgManager "brew" -}}
# macOS (macbook)
echo "==> Detected macOS, using Homebrew..."
# Install Homebrew if not present
if ! command -v brew &> /dev/null; then
echo "==> Installing Homebrew..."
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
eval "$(/opt/homebrew/bin/brew shellenv)"
fi
# Core CLI tools
brew install \
fish \
helix \
neovim \
ripgrep \
fd \
bat \
eza \
fzf \
jq \
tmux \
git \
keychain
{{ if .hasGUI -}}
# GUI tools (only on machines with GUI)
echo "==> Installing Ghostty..."
brew install --cask ghostty
{{ end -}}
{{ end -}}
# Change default shell to fish if not already
if [ "$SHELL" != "$(which fish)" ]; then
echo "==> Setting fish as default shell..."
# Add fish to /etc/shells if not present
if ! grep -q "$(which fish)" /etc/shells; then
echo "$(which fish)" | sudo tee -a /etc/shells
fi
chsh -s "$(which fish)"
fi
echo "==> Base packages installed successfully!"

View file

@ -0,0 +1,34 @@
#!/bin/bash
# Install Rust toolchain via rustup
# This script runs once before other chezmoi operations
set -e
echo "==> Installing Rust toolchain..."
# Install rustup if not present
if ! command -v rustup &> /dev/null; then
echo "==> Installing rustup..."
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y --no-modify-path
# Source cargo environment for this script
source "$HOME/.cargo/env"
else
echo "==> rustup already installed, updating..."
rustup update
fi
# Ensure stable toolchain is installed
rustup default stable
# Install common Rust components
echo "==> Installing Rust components..."
rustup component add rustfmt clippy rust-analyzer
# Install useful cargo tools
echo "==> Installing cargo tools..."
cargo install --locked cargo-watch cargo-edit cargo-outdated 2>/dev/null || true
echo "==> Rust toolchain installed successfully!"
echo " rustc: $(rustc --version)"
echo " cargo: $(cargo --version)"

View file

@ -0,0 +1,37 @@
#!/bin/bash
# Install Node.js via fnm (Fast Node Manager)
# This script runs once before other chezmoi operations
set -e
echo "==> Installing Node.js via fnm..."
# Install fnm if not present
if ! command -v fnm &> /dev/null; then
echo "==> Installing fnm..."
curl -fsSL https://fnm.vercel.app/install | bash -s -- --skip-shell
# Add fnm to PATH for this script
export PATH="$HOME/.local/share/fnm:$PATH"
eval "$(fnm env)"
else
echo "==> fnm already installed"
eval "$(fnm env)"
fi
# Install latest LTS Node.js
echo "==> Installing Node.js LTS..."
fnm install --lts
fnm default lts-latest
fnm use lts-latest
# Verify installation
echo "==> Node.js installed successfully!"
echo " node: $(node --version)"
echo " npm: $(npm --version)"
# Install common global npm packages
echo "==> Installing global npm packages..."
npm install -g typescript ts-node npm-check-updates 2>/dev/null || true
echo "==> Node.js setup complete!"

View file

@ -0,0 +1,40 @@
#!/bin/bash
# Install Python and common development tools
# This script runs once before other chezmoi operations
set -e
echo "==> Setting up Python environment..."
{{ if eq .pkgManager "pacman" -}}
# Arch Linux - Python is usually already installed
sudo pacman -S --noconfirm --needed python python-pip python-pipx
{{ else if eq .pkgManager "apt" -}}
# Debian/Ubuntu
sudo apt-get install -y python3 python3-pip python3-venv pipx
# Create python symlink if needed
if ! command -v python &> /dev/null && command -v python3 &> /dev/null; then
sudo ln -sf $(which python3) /usr/local/bin/python
fi
{{ else if eq .pkgManager "brew" -}}
# macOS
brew install python pipx
{{ end -}}
# Ensure pipx path
pipx ensurepath
# Install useful Python CLI tools via pipx
echo "==> Installing Python CLI tools via pipx..."
pipx install ruff 2>/dev/null || true
pipx install black 2>/dev/null || true
pipx install mypy 2>/dev/null || true
pipx install httpie 2>/dev/null || true
echo "==> Python setup complete!"
echo " python: $(python3 --version)"
echo " pip: $(pip3 --version)"

View file

@ -15,21 +15,47 @@ bind \cl 'printf "\e[2J\e[3J\e[H"; commandline -f repaint'
# PATH setup # PATH setup
fish_add_path -g ~/.local/bin fish_add_path -g ~/.local/bin
{{- if eq .machine "macbook" }} # Cargo/Rust
if test -d ~/.cargo/bin
fish_add_path -g ~/.cargo/bin
end
# fnm (Fast Node Manager)
if test -d ~/.local/share/fnm
fish_add_path -g ~/.local/share/fnm
fnm env | source
end
# pipx
if test -d ~/.local/bin
fish_add_path -g ~/.local/bin
end
{{- if eq .pkgManager "brew" }}
# macOS-specific: Homebrew paths # macOS-specific: Homebrew paths
fish_add_path -g /opt/homebrew/bin fish_add_path -g /opt/homebrew/bin
fish_add_path -g /opt/homebrew/sbin fish_add_path -g /opt/homebrew/sbin
{{- end }} {{- end }}
{{- if or (eq .machine "laptop") (eq .machine "macbook") }} {{- if .hasGUI }}
# SSH agent socket (systemd user service on Linux, launchd on macOS) # SSH agent socket (systemd user service on Linux, launchd on macOS)
{{- if eq .pkgManager "pacman" }}
set -gx SSH_AUTH_SOCK $XDG_RUNTIME_DIR/ssh-agent.socket set -gx SSH_AUTH_SOCK $XDG_RUNTIME_DIR/ssh-agent.socket
{{- else if eq .pkgManager "brew" }}
set -gx SSH_AUTH_SOCK ~/Library/Group\ Containers/2BUA8C4S2C.com.1password/t/agent.sock
{{- end }}
{{- end }} {{- end }}
{{- if eq .machine "server" }} {{- if not .hasGUI }}
# Server-specific: SSH key caching and Helix runtime # Server-specific: SSH key caching
keychain --eval --quiet id_ed25519 | source keychain --eval --quiet id_ed25519 | source
set -gx HELIX_RUNTIME /usr/local/lib/helix/runtime {{- end }}
{{- if eq .pkgManager "apt" }}
# Debian/Ubuntu: Helix runtime path (installed from GitHub releases)
if test -d /usr/local/lib/helix-*/runtime
set -gx HELIX_RUNTIME (ls -d /usr/local/lib/helix-*/runtime | head -1)
end
{{- end }} {{- end }}
# GPG TTY for signing # GPG TTY for signing