#!/bin/sh # Wrangle helper installer: curl -fsSL https://wrangle.stackframes.dev/install | sh # Downloads the universal binary to ~/.wrangle/bin, links it onto your PATH when it can, runs `wrangle setup`. # Everything lives in main(), called on the last line, so a truncated download runs nothing. set -eu main() { BASE="${WRANGLE_DOWNLOAD_BASE:-https://wrangle.stackframes.dev/releases/latest}" DEST="${WRANGLE_INSTALL_DIR:-$HOME/.wrangle/bin}" LINK_DIRS="${WRANGLE_LINK_DIRS:-/opt/homebrew/bin /usr/local/bin}" ASSET="wrangle-darwin-universal.tar.gz" RETRY="Try again in a minute, or email contact@stackframes.dev if it keeps happening." say() { printf '%s\n' "$*"; } fail() { printf 'wrangle install: %s\n' "$*" >&2; exit 1; } if [ "$(uname -s)" != "Darwin" ] && [ -z "${WRANGLE_ALLOW_ANY_OS:-}" ]; then fail "this installer is for macOS. On Linux, follow the manual steps in the Wrangle app (Computers → + → Advanced)." fi command -v curl >/dev/null 2>&1 || fail "curl is missing. Install the Xcode command line tools with 'xcode-select --install', then run this again." command -v shasum >/dev/null 2>&1 || fail "shasum is missing. Install the Xcode command line tools with 'xcode-select --install', then run this again." tmp="$(mktemp -d)" cleanup() { rm -rf "$tmp"; rm -f "$DEST/wrangle.new"; } trap cleanup EXIT trap 'exit 130' INT trap 'exit 143' TERM case "$BASE" in https://*) set -- --proto '=https' --proto-redir '=https' ;; *) set -- ;; esac curl -fsSL "$@" "$BASE/$ASSET" -o "$tmp/$ASSET" || fail "the download failed ($BASE/$ASSET). Check your internet connection. $RETRY" curl -fsSL "$@" "$BASE/$ASSET.sha256" -o "$tmp/$ASSET.sha256" || fail "the checksum download failed. Check your internet connection. $RETRY" want="$(awk '{print $1}' "$tmp/$ASSET.sha256")" got="$(shasum -a 256 "$tmp/$ASSET" | awk '{print $1}')" [ -n "$want" ] && [ "$want" = "$got" ] || fail "checksum mismatch: the download is damaged or was changed, so nothing was installed. $RETRY" tar -xzf "$tmp/$ASSET" -C "$tmp" || fail "the download could not be unpacked, so nothing was installed. $RETRY" [ -f "$tmp/wrangle" ] || fail "the download has no wrangle binary, so nothing was installed. $RETRY" mkdir -p "$DEST" cp "$tmp/wrangle" "$DEST/wrangle.new" chmod 0755 "$DEST/wrangle.new" mv -f "$DEST/wrangle.new" "$DEST/wrangle" linked="" for d in $LINK_DIRS; do if [ -d "$d" ] && [ -w "$d" ]; then if [ -L "$d/wrangle" ] && [ "$(readlink "$d/wrangle")" = "$DEST/wrangle" ]; then linked="$d/wrangle" elif [ -e "$d/wrangle" ] || [ -L "$d/wrangle" ]; then say "Left the existing $d/wrangle alone." elif ln -s "$DEST/wrangle" "$d/wrangle" 2>/dev/null; then linked="$d/wrangle" fi break fi done if [ -n "$linked" ]; then say "✓ Installed wrangle → $linked" else say "✓ Installed wrangle → $DEST/wrangle" say " Add it to your PATH: echo 'export PATH=\"$DEST:\$PATH\"' >> ~/.zprofile" fi if [ -n "${WRANGLE_SKIP_SETUP:-}" ]; then return 0 fi cleanup # `curl | sh` gives the script as stdin, so setup's questions read the terminal directly. if (: /dev/null; then exec "$DEST/wrangle" setup