Files
dotfiles-public/.chezmoiscripts/run_before_00-require-git.sh
T
bcherb2 94d6acadb3 feat: bootstrap installs git, and prints a next step that works
run_before_00-require-git.sh: the documented first command died on the most
ordinary kind of fresh machine there is. chezmoi is a static download and
installs fine, but all six git-repo externals need git, and Ubuntu cloud
images, the Ubuntu docker image and WSL Ubuntu all ship curl and no git.
Installs it across apt/dnf/yum/pacman/zypper/apk/brew, and explains itself
where it cannot (no sudo, or macOS where `git` is a GUI-installer stub).

run_after_99-next-step.sh: `dotup` is command-not-found in the very session
that installed it, because Ubuntu's ~/.profile adds ~/.local/bin to PATH only
if the directory existed at login. No child process can fix its parent's PATH,
so print the absolute path instead of letting the user guess. Silent once PATH
is sorted out.
2026-08-21 22:34:06 -04:00

65 lines
2.7 KiB
Bash
Executable File

#!/bin/sh
# git has to exist before chezmoi fetches the six git-repo externals.
#
# The documented first command is
#
# sh -c "$(curl -fsLS get.chezmoi.io)" -- init --apply <url>
#
# and on a stock box it used to fail here:
#
# chezmoi: .config/tmux/plugins/tpm: exec: "git": executable file not found
#
# chezmoi itself is a static download and installs fine. git is a different
# matter: Ubuntu Server cloud images, the Ubuntu docker image and WSL Ubuntu all
# ship curl and none of them ship git. So the front door of the whole system
# did not open on the most ordinary kind of fresh machine there is.
#
# `run_before_` is the fix rather than a README note, because chezmoi runs these
# before every other target -- externals included. Verified, not assumed: a
# probe script printed "git ABSENT here" and the external failed immediately
# after, in that order.
#
# This exits in microseconds on every machine that already has git, which after
# the first apply is all of them.
set -eu
command -v git >/dev/null 2>&1 && exit 0
printf 'chezmoi: git is required for the shell externals and is not installed.\n' >&2
# Root needs no sudo; a non-root user without sudo cannot do this at all, and
# should be told rather than shown a package manager error.
if [ "$(id -u)" -eq 0 ]; then
SUDO=
elif command -v sudo >/dev/null 2>&1; then
SUDO=sudo
else
printf 'chezmoi: cannot install it -- not root and no sudo. Install git and re-run:\n' >&2
printf 'chezmoi: chezmoi init --apply <url>\n' >&2
exit 1
fi
printf 'chezmoi: installing git...\n' >&2
if command -v apt-get >/dev/null 2>&1; then
${SUDO} env DEBIAN_FRONTEND=noninteractive apt-get update -qq || :
${SUDO} env DEBIAN_FRONTEND=noninteractive apt-get install -y -qq git
elif command -v dnf >/dev/null 2>&1; then ${SUDO} dnf install -y git
elif command -v yum >/dev/null 2>&1; then ${SUDO} yum install -y git
elif command -v pacman >/dev/null 2>&1; then ${SUDO} pacman -Sy --noconfirm git
elif command -v zypper >/dev/null 2>&1; then ${SUDO} zypper --non-interactive install git
elif command -v apk >/dev/null 2>&1; then ${SUDO} apk add --no-cache git
elif command -v brew >/dev/null 2>&1; then brew install git
elif [ "$(uname -s)" = Darwin ]; then
# On macOS `git` is a stub that triggers the Command Line Tools installer,
# which is a GUI dialog -- there is nothing useful to do unattended.
printf 'chezmoi: run `xcode-select --install`, then re-run chezmoi init --apply.\n' >&2
exit 1
else
printf 'chezmoi: no package manager I recognise. Install git and re-run.\n' >&2
exit 1
fi
command -v git >/dev/null 2>&1 \
|| { printf 'chezmoi: git still not on PATH after installing it.\n' >&2; exit 1; }
printf 'chezmoi: git %s installed.\n' "$(git --version | awk '{print $3}')" >&2