run_once_20 runs BEFORE run_onchange_30 in the bootstrap chain, so 'command -v cargo' inside run_once_20 was always false on a fresh box — cargo install bat was skipped, leaving bat missing on debian. Move the bat install to run_onchange_30 (which runs last, after rustup is installed). Restructure the script to: 1. Ensure cargo is installed (existing logic) 2. Install bat via cargo on debian only (new logic, gated by os_family) This way the bootstrap chain becomes: run_once_00 -> run_once_10 -> run_once_20 (apt packages, neovim, oh-my-zsh, font) -> run_onchange_30 (rustup, then bat from crates.io) Crouton currently has rustup installed but no bat (cargo install in progress in background). Re-running chezmoi init will skip run_once_20 (state recorded) and re-run run_onchange_30 (content changed), which will see bat missing and trigger cargo install automatically.
46 lines
No EOL
1.8 KiB
Bash
Executable file
46 lines
No EOL
1.8 KiB
Bash
Executable file
#!/usr/bin/env bash
|
|
# =============================================================================
|
|
# run_onchange_30-ensure-cargo.sh.tmpl
|
|
# Make sure rustup/cargo is available. If not, install rustup.
|
|
# After cargo is ready, install bat from crates.io on debian (apt renames
|
|
# upstream bat to batcat, which breaks .zshrc's `alias cat=bat`).
|
|
#
|
|
# Runs on every apply because the script body rarely changes but we want a
|
|
# fresh check after package installs.
|
|
# =============================================================================
|
|
set -euo pipefail
|
|
|
|
log() { printf '\033[1;34m[cargo]\033[0m %s\n' "$*"; }
|
|
|
|
# --- 1. Ensure cargo is on PATH ---
|
|
if ! command -v cargo >/dev/null 2>&1; then
|
|
if command -v rustup >/dev/null 2>&1; then
|
|
log "rustup present but cargo missing — running rustup default"
|
|
rustup default stable
|
|
else
|
|
log "no cargo or rustup — installing rustup"
|
|
sh -c "$(curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs)" -- -y --default-toolchain stable --profile minimal
|
|
# shellcheck disable=SC1091
|
|
source "$HOME/.cargo/env"
|
|
fi
|
|
fi
|
|
|
|
# Ensure subsequent commands in this script can find cargo
|
|
export PATH="$HOME/.cargo/bin:$PATH"
|
|
|
|
log "rustup installed: $(rustup --version 2>/dev/null || echo unknown)"
|
|
log "cargo installed: $(cargo --version)"
|
|
|
|
# --- 2. Install bat from crates.io if missing (debian only) ---
|
|
{{ if eq .os_family "debian" -}}
|
|
if ! command -v bat >/dev/null 2>&1; then
|
|
log "installing bat via cargo (upstream, debian renames it to batcat)"
|
|
cargo install bat --locked
|
|
log "bat installed: $(bat --version)"
|
|
else
|
|
log "bat already installed: $(bat --version)"
|
|
fi
|
|
{{ else -}}
|
|
# Arch already installs upstream bat via pacman; nothing extra to do.
|
|
log "skipping cargo bat install (os_family={{ .os_family }}, pacman handles it)"
|
|
{{ end -}} |