#!/bin/sh # xpk bootstrap — installs the xpm static binary from the xe-am/pkg latest release. # curl -fsSL https://sh.xe.am | sh # Overridable: XPK_BASE (asset origin), XPK_BIN (install dir), XPK_ASSET (binary name). set -eu BASE=${XPK_BASE:-https://b.xe.am} BIN_DIR=${XPK_BIN:-$HOME/.local/bin} ASSET=${XPK_ASSET:-xpm-sta} say() { printf '%s\n' "$*"; } die() { say "xpk: $*" >&2 exit 1 } command -v curl >/dev/null 2>&1 || die 'curl is required' if command -v sha256sum >/dev/null 2>&1; then sum() { sha256sum "$1" | cut -d' ' -f1; } elif command -v shasum >/dev/null 2>&1; then sum() { shasum -a 256 "$1" | cut -d' ' -f1; } else die 'sha256sum or shasum is required' fi TMP=$(mktemp -d "${TMPDIR:-/tmp}/xpk.XXXXXX") || die 'cannot create temp dir' trap 'rm -rf "$TMP"' EXIT INT TERM say "xpk: fetching $BASE/SHA256SUMS" curl -fsS --retry 2 --retry-delay 1 --max-time 60 -o "$TMP/SHA256SUMS" "$BASE/SHA256SUMS" || die "cannot fetch $BASE/SHA256SUMS" want=$(awk -v a="$ASSET" '$2 == a || $2 == "*" a { print $1; exit }' "$TMP/SHA256SUMS") [ -n "$want" ] || die "$ASSET is not listed in SHA256SUMS" say "xpk: downloading $BASE/$ASSET" curl -fsS --retry 2 --retry-delay 1 --max-time 300 -o "$TMP/$ASSET" "$BASE/$ASSET" || die "cannot fetch $BASE/$ASSET" got=$(sum "$TMP/$ASSET") [ "$want" = "$got" ] || die "checksum mismatch for $ASSET: want $want got $got" mkdir -p "$BIN_DIR" install -m 0755 "$TMP/$ASSET" "$BIN_DIR/xpm" 2>/dev/null || { cp "$TMP/$ASSET" "$BIN_DIR/xpm" chmod 0755 "$BIN_DIR/xpm" } say "xpk: installed $BIN_DIR/xpm (sha256 $got)" case ":${PATH:-}:" in *":$BIN_DIR:"*) say 'xpk: run `xpm --help`' ;; *) say "xpk: add $BIN_DIR to PATH to run xpm" ;; esac