#!/bin/bash set -euo pipefail INSTALL_URL="${SUMR_INSTALL_URL:-https://sumr.co/install}" SUMR_HOME="${SUMR_HOME:-$HOME/.sumr}" SUMR_BACKUPS_DIR="$SUMR_HOME/backups" if [ -t 1 ] && [ "${TERM:-}" != "dumb" ]; then COLOR_RESET="$(printf '\033[0m')" COLOR_DIM="$(printf '\033[2m')" COLOR_BLUE="$(printf '\033[34m')" COLOR_GREEN="$(printf '\033[32m')" COLOR_YELLOW="$(printf '\033[33m')" COLOR_RED="$(printf '\033[31m')" else COLOR_RESET="" COLOR_DIM="" COLOR_BLUE="" COLOR_GREEN="" COLOR_YELLOW="" COLOR_RED="" fi print_line() { local color="$1" local prefix="$2" local message="$3" printf '%b%s%b %s\n' "$color" "$prefix" "$COLOR_RESET" "$message" } print_note() { local title="$1" shift local width=${#title} local line for line in "$@"; do if [ "${#line}" -gt "$width" ]; then width=${#line} fi done local top_rule_len=$((width - ${#title})) if [ "$top_rule_len" -lt 0 ]; then top_rule_len=0 fi local top_rule local bottom_rule top_rule="$(printf '%*s' "$top_rule_len" '' | tr ' ' '─')" bottom_rule="$(printf '%*s' $((width + 2)) '' | tr ' ' '─')" printf '\n' printf '%b◇ %s %s╮%b\n' "$COLOR_BLUE" "$title" "$top_rule" "$COLOR_RESET" printf '%b│%b %-*s %b│%b\n' "$COLOR_DIM" "$COLOR_RESET" "$width" "" "$COLOR_DIM" "$COLOR_RESET" for line in "$@"; do printf '%b│%b %-*s %b│%b\n' "$COLOR_DIM" "$COLOR_RESET" "$width" "$line" "$COLOR_DIM" "$COLOR_RESET" done printf '%b╰%s╯%b\n' "$COLOR_DIM" "$bottom_rule" "$COLOR_RESET" } step() { printf '\n' print_line "$COLOR_BLUE" ">" "$1" } info() { print_line "$COLOR_DIM" "-" "$1" } success() { print_line "$COLOR_GREEN" "+" "$1" } fail() { print_line "$COLOR_RED" "x" "$1" >&2 } display_path() { local path="$1" printf '%s' "${path/#$HOME/~}" } prepare_sumr_home() { mkdir -p "$SUMR_HOME" chmod 700 "$SUMR_HOME" 2>/dev/null || true mkdir -p "$SUMR_BACKUPS_DIR" chmod 700 "$SUMR_BACKUPS_DIR" 2>/dev/null || true } usage() { cat </dev/null 2>&1; then fail "Bun is required to install and run SUMR CLI." info "Install Bun first: curl -fsSL https://bun.sh/install | bash" exit 1 fi set +e install_output="$(bun add -g "${package}@${package_version}" 2>&1)" install_status=$? set -e if [ "$install_status" -ne 0 ]; then fail "Could not install ${package}@${package_version}." printf '%s\n' "$install_output" >&2 exit "$install_status" fi success "Installed ${package}@${package_version}" printf '\n' success "SUMR is ready." print_note "Next steps" "sumr --help" print_note "Team access" "curl -fsSL ${INSTALL_URL}/private | bash" } if [ "${1:-}" = "--help" ] || [ "${1:-}" = "-h" ]; then usage exit 0 fi install