chezmoi runs run_once_* scripts as the invoking user (uid != 0). The earlier check [[ $(id -u) -ne 0 ]] && die ... killed the script immediately when invoked via 'chezmoi apply' or 'chezmoi init --apply' from a normal user session. The scripts use sudo internally for package operations (pacman/apt), so elevation happens correctly. The id -u check was wrong: it belongs in a script that's *meant* to be invoked as root directly, not in a chezmoi-managed script.
41 lines
No EOL
1.4 KiB
Bash
Executable file
41 lines
No EOL
1.4 KiB
Bash
Executable file
#!/usr/bin/env bash
|
|
# =============================================================================
|
|
# run_once_00-install-bootstrap-tools.sh.tmpl
|
|
# Install age, curl, ca-certificates, git — needed before anything else.
|
|
# Idempotent: skips if already installed.
|
|
# =============================================================================
|
|
set -euo pipefail
|
|
|
|
log() { printf '\033[1;34m[bootstrap]\033[0m %s\n' "$*"; }
|
|
die() { printf '\033[1;31m[bootstrap ERROR]\033[0m %s\n' "$*" >&2; exit 1; }
|
|
|
|
# This script runs as the invoking user via `chezmoi apply`/`init`. It uses
|
|
# sudo for system package installs. If sudo isn't passwordless, the user
|
|
# will be prompted once per sudo invocation.
|
|
|
|
{{ if eq .os_family "arch" -}}
|
|
log "pacman-sync"
|
|
pacman -Sy --noconfirm
|
|
|
|
log "install base tools (arch)"
|
|
PACMAN_PKGS=(age curl ca-certificates git base-devel wget)
|
|
pacman -S --needed --noconfirm "${PACMAN_PKGS[@]}"
|
|
|
|
{{ else if eq .os_family "debian" -}}
|
|
export DEBIAN_FRONTEND=noninteractive
|
|
log "apt-update"
|
|
apt-get update -y
|
|
log "apt-upgrade"
|
|
apt-get upgrade -y
|
|
|
|
log "install base tools (debian)"
|
|
APT_PKGS=(age curl ca-certificates git wget gnupg)
|
|
apt-get install -y --no-install-recommends "${APT_PKGS[@]}"
|
|
|
|
{{ else -}}
|
|
die "unsupported os_family: {{ .os_family }} (this script supports arch or debian)"
|
|
{{ end -}}
|
|
|
|
log "bootstrap tools installed"
|
|
command -v age && age --version
|
|
command -v git && git --version |