#!/bin/bash # Does the lab itself work? Clone the public tier from the local server exactly # as the README's first command does, and prove the code that arrived is the # working tree rather than whatever was last pushed. set -u fail() { echo "FAIL: $*"; exit 1; } ok() { echo " ok $*"; } echo "-- environment as handed to a real user --" echo " user=$(id -un) uid=$(id -u) shell=$SHELL home=$HOME" echo " PATH=$PATH" case ":$PATH:" in *":$HOME/.local/bin:"*) fail "~/.local/bin is already on PATH -- the box is not fresh, and the 'command not found' bug cannot reproduce here" ;; esac ok "~/.local/bin is NOT on PATH yet (matches a real fresh login)" command -v git >/dev/null && fail "git pre-installed -- image is too generous" ok "git absent, as on a stock image" echo "-- the documented first command --" # ISSUE-1 regression guard: NOTHING is installed by hand here. git is absent, # and the documented command has to cope with that on its own. If this scenario # ever needs an `apt-get install git` again, the front door has re-broken. sh -c "$(curl -fsLS get.chezmoi.io)" -- init --apply "$PUB_URL" >/tmp/init.log 2>&1 \ || { tail -20 /tmp/init.log; fail "chezmoi init --apply"; } ok "public tier applied — from a box with no git, unaided" grep -q 'installing git' /tmp/init.log \ || fail "git was installed, but not by run_before_00-require-git.sh — something else is satisfying the prerequisite and the fix is untested" ok "run_before_00-require-git.sh is what supplied git" command -v git >/dev/null || fail "git still missing after the apply" n=$(ls -d "$HOME/.oh-my-zsh" "$HOME/.tmux" 2>/dev/null | wc -l) [ "$n" -eq 2 ] || fail "the git-repo externals did not clone ($n/2 present)" ok "the six git-repo externals cloned" [ -x "$HOME/.local/bin/dotup" ] || fail "no executable at ~/.local/bin/dotup" ok "dotup landed at ~/.local/bin/dotup" # The whole point of the lab: prove we are running uncommitted code. The # snapshot commit message is the marker, and it cannot exist on any real remote. src=$(~/bin/chezmoi source-path 2>/dev/null || chezmoi source-path 2>/dev/null || echo "$HOME/.local/share/chezmoi") msg=$(git -C "$src" log -1 --format=%s 2>/dev/null || echo none) case $msg in "working-tree snapshot of dotfiles-public") ok "serving the WORKING TREE, not a pushed commit" ;; *) fail "expected the working-tree snapshot commit, got: $msg" ;; esac echo "-- and the bug, reproduced --" if command -v dotup >/dev/null 2>&1; then fail "bare 'dotup' resolved in this shell -- expected 'command not found'" fi ok "bare 'dotup' is command-not-found in the shell that ran the install" if bash -lc 'command -v dotup' >/dev/null 2>&1; then ok "a NEW login shell does resolve it (~/.profile picks up ~/.local/bin)" grep -q 'Next: ~/.local/bin/dotup' /tmp/init.log \ || fail "the install never told the user what to run next, so the only way to find out is to type 'dotup' and be told it does not exist" ok "the install printed the absolute path to run next, and why" else fail "even a new login shell cannot find dotup" fi echo "SMOKE PASS"