diff --git a/README.md b/README.md index 3ac5d66..f21a469 100644 --- a/README.md +++ b/README.md @@ -72,6 +72,10 @@ cp -r templates/project-bootstrap/* ../my-project/ && cd ../my-project # Option B: Use the CLI (builds v2 scaffolding automatically) cd my-project && ../rebar/bin/rebar init + +# Option C: One-line installer (clones rebar to ~/.rebar, wires PATH) +curl -fsSL https://raw.githubusercontent.com/willackerly/rebar/v3.0.0-alpha/setup-rebar.sh | bash +# then: rebar new my-project -d "what it does" ``` **What you get:** Contracts linked to code + agent coordination + immediate productivity boost diff --git a/setup-rebar.sh b/setup-rebar.sh new file mode 100755 index 0000000..81bebd2 --- /dev/null +++ b/setup-rebar.sh @@ -0,0 +1,121 @@ +#!/usr/bin/env bash +# setup-rebar.sh — One-line installer for rebar. +# +# Clones rebar to $REBAR_DIR (default ~/.rebar), runs the canonical +# `bin/install` to add ASK + rebar to your PATH, and exits pointing +# you at `rebar new` / `rebar adopt` for actual project bootstrap. +# +# This is intentionally a thin shim over rebar's existing tooling +# (`bin/install`, `rebar new`, `rebar adopt`) — not a parallel +# bootstrap. Anything beyond clone + PATH wiring belongs in the +# Go CLI so it stays in sync with the rest of the project. +# +# Usage (curl pipe): +# curl -fsSL https://raw.githubusercontent.com/willackerly/rebar/v3.0.0-alpha/setup-rebar.sh | bash +# +# Usage (local): +# ./setup-rebar.sh [--server HOST:PORT] [--dir PATH] + +set -euo pipefail + +REBAR_REPO="${REBAR_REPO:-https://github.com/willackerly/rebar.git}" +REBAR_REF="${REBAR_REF:-v3.0.0-alpha}" +REBAR_DIR="${REBAR_DIR:-$HOME/.rebar}" +ASK_SERVER="${ASK_SERVER:-}" + +if [[ -t 1 ]]; then + RED=$'\033[0;31m'; GREEN=$'\033[0;32m'; YELLOW=$'\033[1;33m' + BLUE=$'\033[0;34m'; NC=$'\033[0m' +else + RED=''; GREEN=''; YELLOW=''; BLUE=''; NC='' +fi + +log() { printf '%s[rebar]%s %s\n' "$BLUE" "$NC" "$*"; } +warn() { printf '%s[rebar]%s %s\n' "$YELLOW" "$NC" "$*" >&2; } +err() { printf '%s[rebar]%s %s\n' "$RED" "$NC" "$*" >&2; } +ok() { printf '%s[rebar]%s %s\n' "$GREEN" "$NC" "$*"; } + +usage() { + cat <&2; exit 2 ;; + esac +done + +if ! command -v git >/dev/null 2>&1; then + err "git is required. Install it and re-run." + exit 1 +fi + +if [[ -d "$REBAR_DIR/.git" ]]; then + log "Updating existing rebar checkout at $REBAR_DIR" + if ! git -C "$REBAR_DIR" diff --quiet || ! git -C "$REBAR_DIR" diff --cached --quiet; then + warn "$REBAR_DIR has uncommitted changes — skipping fetch/checkout" + else + git -C "$REBAR_DIR" fetch --tags origin "$REBAR_REF" + git -C "$REBAR_DIR" checkout "$REBAR_REF" + git -C "$REBAR_DIR" pull --ff-only origin "$REBAR_REF" || true + fi +elif [[ -e "$REBAR_DIR" ]]; then + err "$REBAR_DIR exists but is not a git checkout." + err "Move it aside or set REBAR_DIR= and re-run." + exit 1 +else + log "Cloning $REBAR_REPO ($REBAR_REF) → $REBAR_DIR" + git clone --branch "$REBAR_REF" --depth=1 "$REBAR_REPO" "$REBAR_DIR" +fi + +if [[ ! -x "$REBAR_DIR/bin/install" ]]; then + err "$REBAR_DIR/bin/install not found or not executable." + err "The clone may have failed or the ref does not contain bin/install." + exit 1 +fi + +install_args=() +[[ -n "$ASK_SERVER" ]] && install_args+=(--server "$ASK_SERVER") +log "Running $REBAR_DIR/bin/install ${install_args[*]:-}" +"$REBAR_DIR/bin/install" "${install_args[@]}" + +ok "rebar installed at $REBAR_DIR (ref: $REBAR_REF)" +cat <