#!/bin/bash # Take a factory-fresh Mac to the point where mise sets up the rest from hq: # the developer tools, mise, and a checkout of hq at ~/Development/hq. # # curl -fsSL https://bootstrap.azohra.com | bash # # This script is public: bootstrap.azohra.com serves it, so it holds no # secret. Runs on the Bash 3.2 that ships with macOS, piped or from a file. # hq is private and a new Mac has no credential for it yet, so the clone asks # once for a personal access token with read access to hq's contents. The # token is handed to git for that one clone and stored nowhere. The work is # one function, called on the last line, so a download that stops part way # runs nothing. bootstrap/README.md lists what else a person does by hand. set -euo pipefail main() { https=https://github.com/azohra/hq.git ssh=git@github.com:azohra/hq.git dest=$HOME/Development/hq mise=$HOME/.local/bin/mise [[ $(uname -sm) == "Darwin arm64" ]] || { echo "Apple Silicon macOS only." >&2; exit 1; } if ! xcode-select -p >/dev/null 2>&1; then echo "Install the Command Line Tools in the dialog that opens." xcode-select --install || true until xcode-select -p >/dev/null 2>&1; do sleep 5; done fi [[ -x $mise ]] || curl -fsSL https://mise.run | sh if [[ ! -d $dest/.git ]]; then if GIT_TERMINAL_PROMPT=0 git ls-remote "$https" HEAD >/dev/null 2>&1 /dev/tty IFS= read -r -s token /dev/tty (umask 077 && printf '%s\n' "$token" >"$tmp/token") unset token # git asks for a username, then a password; the token is deleted as it is read. cat >"$tmp/askpass" <&2; exit 1; } fi fi # The token is gone, and nothing can read hq over HTTPS again until gh is # signed in, before the bootstrap's tools. From here the checkout is what the # fleet declares it to be: its origin is the SSH address, and every fetch and # push uses the vault's key that the pre-repos hook loads. git -C "$dest" remote set-url origin "$ssh" # The clone above is plain git so that mise never sees the token's helper. # mise finds the checkout, links ~/.config/mise to its wiring/ and applies it. # Its hooks sign in to 1Password and sudo asks for a password, so it reads # from the terminal even when this script is piped. mise stops at a declared # repository with local changes. The tools keep their files in the home # directory, so the checkout stays clean and a second run goes through. "$mise" bootstrap --from "$ssh" --from-dir "$dest" --config-dir wiring --yes