#!/bin/sh # Installs yeet, the yeethub.org command, for you alone (no sudo): https://yeethub.org/install # # curl -fsSL https://yeethub.org/install.sh | sh # # With Node.js 22 or newer it installs yeet.mjs (a few KB) and runs it with your node; otherwise a # single executable that needs nothing else (Linux x86-64). Every download is checked against # https://yeethub.org/downloads/SHA256SUMS. Settings: YEET_BIN_DIR (default ~/.local/bin), # YEET_STANDALONE=1 to use the single executable even when Node is there. # # Served by a development server (`npm run dev:web`), it installs the same release, then adds profiles # for that checkout and switches to `local` (its source against that server). `yeet use prod` goes # back. `npm run yeet:install` does the same without the server. (docs/cli.md) set -eu # The site serving this script fills these in (web/src/app/install.sh/route.ts). SERVED_BY='https://yeethub.org' RELEASES_FROM='https://yeethub.org' DEV_CHECKOUT= main() { base="${YEETHUB_URL:-$SERVED_BY}" releases="${YEET_RELEASES:-$RELEASES_FROM}" dev_root="${YEET_DEV_ROOT:-$DEV_CHECKOUT}" bin="${YEET_BIN_DIR:-$HOME/.local/bin}" share="${XDG_DATA_HOME:-$HOME/.local/share}/yeet" if [ -t 1 ] && [ -z "${NO_COLOR:-}" ]; then b=$(printf '\033[1m'); g=$(printf '\033[32m'); r=$(printf '\033[31m'); n=$(printf '\033[0m'); else b= g= r= n=; fi say() { printf '%s\n' "$*"; } die() { printf '%sCould not install yeet:%s %s\n' "$r" "$n" "$*" >&2; exit 1; } [ "$(uname -s)" = Linux ] || die "yeet is for Linux for now (this is $(uname -s))." proto='=https' case "$releases" in http://*) proto='=http' ;; esac # local testing only if command -v curl >/dev/null 2>&1; then fetch() { curl -fsSL --proto "$proto" -o "$2" "$1"; } elif command -v wget >/dev/null 2>&1; then fetch() { wget -q -O "$2" "$1"; } else die "it needs curl or wget."; fi command -v sha256sum >/dev/null 2>&1 || die "it needs sha256sum (coreutils)." tmp=$(mktemp -d) trap 'rm -rf "$tmp"' EXIT INT TERM fetch "$releases/downloads/SHA256SUMS" "$tmp/SHA256SUMS" || die "couldn't reach $releases." check() { want=$(grep " $1\$" "$tmp/SHA256SUMS" | cut -d' ' -f1) got=$(sha256sum "$tmp/$1" | cut -d' ' -f1) [ -n "$want" ] && [ "$want" = "$got" ] || die "$1 doesn't match its checksum. Nothing was installed." } node_major=0 if command -v node >/dev/null 2>&1; then node_major=$(node -p 'process.versions.node.split(".")[0]' 2>/dev/null || echo 0); fi mkdir -p "$bin" "$share" if [ "$node_major" -ge 22 ] && [ -z "${YEET_STANDALONE:-}" ]; then say "Using Node.js $(node -v) at $(command -v node)" fetch "$releases/downloads/yeet.mjs" "$tmp/yeet.mjs" || die "couldn't download yeet.mjs." check yeet.mjs mv "$tmp/yeet.mjs" "$share/yeet.mjs" rm -f "$share/yeet" printf '#!/bin/sh\nexec node "%s" "$@"\n' "$share/yeet.mjs" > "$tmp/yeet" else case "$(uname -m)" in x86_64 | amd64) ;; *) die "the single executable is for x86-64 only so far. Install Node.js 22 or newer and run this again." ;; esac say "Downloading the single executable (about 40 MB)..." fetch "$releases/downloads/yeet-linux-x64.gz" "$tmp/yeet-linux-x64.gz" || die "couldn't download yeet-linux-x64.gz." check yeet-linux-x64.gz gzip -dc "$tmp/yeet-linux-x64.gz" > "$share/yeet.new" chmod 755 "$share/yeet.new" mv "$share/yeet.new" "$share/yeet" rm -f "$share/yeet.mjs" printf '#!/bin/sh\nexec "%s" "$@"\n' "$share/yeet" > "$tmp/yeet" fi chmod 755 "$tmp/yeet" mv "$tmp/yeet" "$bin/yeet" installed=$(YEET_PROFILE=prod "$bin/yeet" --version 2>/dev/null) || die "yeet was installed to $bin/yeet but doesn't run." say "${g}Installed ${installed}${n} to $bin/yeet" if [ -n "$dev_root" ]; then # The development setups, as profiles of this one yeet (yeet profiles; yeet use ). y() { YEET_PROFILE=prod "$bin/yeet" "$@" 2>/dev/null; } y profile add local --server "$base" --source "$dev_root" || die "couldn't add the local profile (is $dev_root a yeethub checkout?)." y profile add local-cli --server https://yeethub.org --source "$dev_root" y profile add local-server --server "$base" y use "${YEET_USE:-local}" say "" say "Profiles for $dev_root:" YEET_PROFILE= "$bin/yeet" profiles 2>/dev/null | sed 's/^/ /' say "Using ${b}${YEET_USE:-local}${n}. Switch any time with ${b}yeet use ${n} (prod is the real yeethub.org)." fi case ":$PATH:" in *":$bin:"*) say "Next: ${b}yeet login${n}" ;; *) say "" say "$bin isn't on your PATH yet. Add this to your shell's startup file (~/.bashrc, ~/.zshrc):" say " export PATH=\"$bin:\$PATH\"" say "Then: ${b}yeet login${n}" ;; esac } main "$@"