#!/bin/sh # Fresh-machine launcher: curl -fsSL https://bootstrap.chip.network | sh # Installs git and gh, signs in through gh, clones chipsenkbeil/dotfiles, then # hands off to its bootstrap.sh. Credentials stay with gh. Set DOTFILES_DIR to # clone somewhere other than $HOME/projects/dotfiles. set -eu say() { printf '==> %s\n' "$*"; } die() { printf 'error: %s\n' "$*" >&2; exit 1; } have() { command -v "$1" >/dev/null 2>&1; } prepare_mac() { if ! xcode-select -p >/dev/null 2>&1; then say "requesting the Xcode command line tools" xcode-select --install || true die "finish the Xcode install dialog, then run this again" fi if ! have brew; then say "installing Homebrew" /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)" for b in /opt/homebrew/bin/brew /usr/local/bin/brew; do if [ -x "$b" ]; then eval "$("$b" shellenv)"; fi done fi say "installing git and gh with brew" brew install git gh } prepare_linux() { have sudo || die "sudo is required to install packages" if have pacman; then say "installing git and gh with pacman" sudo pacman -S --needed --noconfirm git github-cli elif have dnf; then say "installing git and gh with dnf" sudo dnf install -y git gh elif have apt-get; then say "installing git and gh with apt" sudo apt-get update && sudo apt-get install -y git gh else die "no supported package manager (pacman, dnf, apt)" fi } main() { [ "$(id -u)" -ne 0 ] || die "run as your own user, not root" case "$(uname -s)" in Darwin) say "detected macOS"; prepare_mac ;; Linux) say "detected Linux"; prepare_linux ;; *) die "unsupported OS: $(uname -s)" ;; esac if ! gh auth status >/dev/null 2>&1; then say "signing in to GitHub with gh" gh auth login --web --git-protocol https fi dir=${DOTFILES_DIR:-$HOME/projects/dotfiles} if [ ! -d "$dir" ]; then say "cloning chipsenkbeil/dotfiles to $dir" mkdir -p "$(dirname "$dir")" gh repo clone chipsenkbeil/dotfiles "$dir" fi say "running bootstrap.sh in $dir" cd "$dir" exec bash bootstrap.sh "$@" } # The script arrives on stdin, so the prompts inside main read the terminal # instead. The whole body is parsed before this line runs. main "$@"