#!/usr/bin/env zsh # ambre bootstrap · https://install.ambre.kud.io # # Public on purpose: kud/ambre is a private repo, so the CLONE needs credentials # but the BOOTSTRAP has to be fetchable by a machine with nothing on it yet. # Nothing secret lives here — it asks for your token at run time. # # Idempotent AND self-updating: rerun it any time. A fresh machine clones; an # existing checkout is pulled to latest before install, so a plain rerun always # runs the newest code — no manual `git pull` needed. # # curl -L --silent https://install.ambre.kud.io | zsh REPO="kud/ambre" DEST="$HOME/.ambre" print "ambre — bootstrapping ${DEST}" # Command Line Tools are what provide git on a fresh Mac. Already-present is not # an error, so test for it rather than trusting xcode-select --install's status. if ! xcode-select -p >/dev/null 2>&1; then print "Installing Command Line Tools — accept the dialog, then run this again." xcode-select --install exit 1 fi # Prompt for GitHub credentials, but only when a network op actually needs them. # /dev/null || print " Open manually: $url" print "" print -n "GitHub username: "; read -r GH_USER /dev/null 2>&1; then _get_creds if ! git -C "$DEST" -c credential.helper= pull --ff-only \ "https://${GH_USER}:${GH_TOKEN}@github.com/${REPO}.git" main; then print -u2 "Update failed — check the token, or resolve a diverged checkout by hand." exit 1 fi fi else _get_creds if ! git clone "https://${GH_USER}:${GH_TOKEN}@github.com/${REPO}.git" "$DEST"; then print -u2 "Clone failed — check the token has repo scope and has not expired." exit 1 fi # The token would otherwise sit in .git/config for good. Strip it straight away; # `ambre install` repoints origin at SSH once your keys are back from the vault. git -C "$DEST" remote set-url origin "https://github.com/${REPO}.git" fi # Verify rather than assume: a partial clone would fail here with a clearer # message than whatever `install` would say three steps later. if [[ ! -x "${DEST}/bin/ambre" ]]; then print -u2 "${DEST}/bin/ambre is missing or not executable — checkout looks incomplete." exit 1 fi exec "${DEST}/bin/ambre" install