#!/bin/sh # Installs shtuk, the console tool of the Shtukbase Standard, and the registry of the site's packages. # This is the template: the site build (apps/site/build.ts) fills in the version, the files and their sha256. # # curl -fsSL https://standard.shtukbase.com/install.sh | sh # tool + registry # curl -fsSL https://standard.shtukbase.com/install.sh | sh -s -- --no-registry # tool only # SHTUK_BIN_DIR=/usr/local/bin ... # another folder for the command # # Puts: $SHTUK_BIN_DIR/shtuk (default ~/.local/bin) a small wrapper that runs the tool on Bun # $DATA/shtuk-0.1.0.js the tool (DATA = ${XDG_DATA_HOME:-~/.local/share}/shtuk) # $DATA/registry/ the packages: // and index.md # Running it again updates the tool and adds the new versions of packages; old versions stay. set -eu BASE_URL="${SHTUK_BASE_URL:-https://standard.shtukbase.com}" VERSION="0.1.0" FILE="shtuk-0.1.0.js" SHA256="360c5aec9070eb31bae614d452fe51dbbd2544d35c30459c848ac6e8c9d6861e" REGISTRY_FILE="shtukbase-registry-2026-11-28.tar.gz" REGISTRY_SHA256="73907c881b250959cb7eb9316f8cd66471c0a21ac4b2e809001e7ed1737b9077" BIN_DIR="${SHTUK_BIN_DIR:-$HOME/.local/bin}" DATA="${XDG_DATA_HOME:-$HOME/.local/share}/shtuk" WITH_REGISTRY=1 for a in "$@"; do case "$a" in --no-registry) WITH_REGISTRY=0 ;; -h|--help) sed -n '2,13p' "$0" 2>/dev/null || true; exit 0 ;; *) printf 'shtuk install: unknown option %s\n' "$a" >&2; exit 2 ;; esac done say() { printf '%s\n' "$*"; } fail() { printf 'shtuk install: %s\n' "$*" >&2; exit 1; } # shtuk and the checks of packages run on Bun if command -v bun >/dev/null 2>&1; then BUN="$(command -v bun)" elif [ -x "$HOME/.bun/bin/bun" ]; then BUN="$HOME/.bun/bin/bun" else say "Нужен Bun 1.3 или новее: на нём работают shtuk и проверки пакетов." say "Поставьте его (сайт bun.sh) и запустите этот скрипт снова:" say " curl -fsSL https://bun.sh/install | bash" exit 1 fi have="$("$BUN" --version 2>/dev/null || echo 0)" major="${have%%.*}"; rest="${have#*.}"; minor="${rest%%.*}" if [ "${major:-0}" -lt 1 ] || { [ "${major:-0}" -eq 1 ] && [ "${minor:-0}" -lt 3 ]; }; then fail "у вас Bun $have, нужен 1.3 или новее: bun upgrade" fi tmp="$(mktemp -d 2>/dev/null || mktemp -d -t shtuk)" trap 'rm -rf "$tmp"' EXIT INT TERM fetch() { # url file if command -v curl >/dev/null 2>&1; then curl -fsSL "$1" -o "$2" || fail "не скачалось: $1" elif command -v wget >/dev/null 2>&1; then wget -q "$1" -O "$2" || fail "не скачалось: $1" else fail "нужен curl или wget"; fi } verify() { # file sha256 if command -v shasum >/dev/null 2>&1; then got="$(shasum -a 256 "$1" | cut -d' ' -f1)" elif command -v sha256sum >/dev/null 2>&1; then got="$(sha256sum "$1" | cut -d' ' -f1)" else fail "нечем сверить sha256: нужен shasum или sha256sum"; fi [ "$got" = "$2" ] || fail "sha256 не совпал у $(basename "$1"): ждали $2, пришло $got. Ничего не поставлено." } say "Скачиваю shtuk $VERSION" fetch "$BASE_URL/dl/$FILE" "$tmp/$FILE" verify "$tmp/$FILE" "$SHA256" if [ "$WITH_REGISTRY" = 1 ]; then say "Скачиваю реестр пакетов: $REGISTRY_FILE" fetch "$BASE_URL/dl/$REGISTRY_FILE" "$tmp/registry.tar.gz" verify "$tmp/registry.tar.gz" "$REGISTRY_SHA256" mkdir -p "$tmp/unpacked" tar -xzf "$tmp/registry.tar.gz" -C "$tmp/unpacked" || fail "архив реестра не распаковался" [ -f "$tmp/unpacked/registry/index.md" ] || fail "в архиве нет registry/index.md" fi # everything is downloaded and verified: now write mkdir -p "$DATA" "$BIN_DIR" mv "$tmp/$FILE" "$DATA/$FILE" if [ "$WITH_REGISTRY" = 1 ]; then mkdir -p "$DATA/registry" # new versions are added beside the old ones; the index is replaced (cd "$tmp/unpacked/registry" && tar -cf - .) | (cd "$DATA/registry" && tar -xf -) fi cat > "$tmp/shtuk" </dev/null 2>&1; then exec bun "$DATA/$FILE" "\$@"; fi exec "$BUN" "$DATA/$FILE" "\$@" WRAP chmod 755 "$tmp/shtuk" mv "$tmp/shtuk" "$BIN_DIR/shtuk" say "Готово: $BIN_DIR/shtuk — $("$BIN_DIR/shtuk" --version 2>/dev/null || echo "shtuk $VERSION")" [ "$WITH_REGISTRY" = 1 ] && say "Реестр: $DATA/registry ($(ls -d "$DATA"/registry/*/ 2>/dev/null | wc -l | tr -d ' ') пакетов)" case ":$PATH:" in *":$BIN_DIR:"*) ;; *) say "Папки $BIN_DIR нет в PATH. Добавьте в ~/.zshrc или ~/.bashrc строку:" say " export PATH=\"$BIN_DIR:\$PATH\"" ;; esac say "Дальше: shtuk init my-project --blueprint basic --defaults && cd my-project && shtuk check"