#!/bin/sh # Microsandbox installer # Usage: curl -fsSL https://install.microsandbox.dev | sh set -eu # --------------------------------------------------------------------------- # Constants # --------------------------------------------------------------------------- GITHUB_REPO="superradcompany/microsandbox" INSTALL_DIR="${MSB_HOME:-$HOME/.microsandbox}" case "$INSTALL_DIR" in /*) ;; *) INSTALL_DIR="$(pwd -P)/$INSTALL_DIR" ;; esac BIN_DIR="$INSTALL_DIR/bin" LIB_DIR="$INSTALL_DIR/lib" LOCAL_BIN_DIR="$HOME/.local/bin" # Published Linux release bundles are built and audited against the # manylinux_2_28 baseline. LINUX_GLIBC_MIN_VERSION="2.28" # Progress bar BAR_WIDTH=40 # Colors (disabled if not a terminal) if [ -t 1 ]; then BOLD='\033[1m' DIM='\033[2m' GREEN='\033[0;32m' CYAN='\033[0;36m' RED='\033[0;31m' YELLOW='\033[0;33m' RESET='\033[0m' else BOLD='' DIM='' GREEN='' CYAN='' RED='' YELLOW='' RESET='' fi # --------------------------------------------------------------------------- # Helpers # --------------------------------------------------------------------------- info() { printf "${BOLD}${CYAN}info${RESET} %s\n" "$1" } success() { printf "${BOLD}${GREEN}done${RESET} %s\n" "$1" } warn() { printf "${BOLD}${YELLOW}warn${RESET} %s\n" "$1" } error() { printf "${BOLD}${RED}error${RESET} %s\n" "$1" >&2 exit 1 } need_cmd() { if ! command -v "$1" > /dev/null 2>&1; then error "required command not found: $1" fi } resolve_libkrunfw_artifact() { if [ "$OS" = "linux" ]; then # The full version belongs to the release artifact, so discover it # after extraction instead of keeping another version pin here. set -- libkrunfw.so.*.*.* if [ "$#" -ne 1 ] || [ ! -f "$1" ]; then error "release bundle must contain exactly one versioned libkrunfw shared library" fi LIBKRUNFW_FILE=$1 _libkrunfw_version=${LIBKRUNFW_FILE#libkrunfw.so.} LIBKRUNFW_ABI=${_libkrunfw_version%%.*} elif [ "$OS" = "darwin" ]; then set -- libkrunfw.*.dylib if [ "$#" -ne 1 ] || [ ! -f "$1" ]; then error "release bundle must contain exactly one versioned libkrunfw shared library" fi LIBKRUNFW_FILE=$1 LIBKRUNFW_ABI=${LIBKRUNFW_FILE#libkrunfw.} LIBKRUNFW_ABI=${LIBKRUNFW_ABI%.dylib} fi case "$LIBKRUNFW_ABI" in ''|*[!0-9]*) error "release bundle contains an invalid libkrunfw ABI version" ;; esac } link_command() { _name=$1 _target=$2 _link="$LOCAL_BIN_DIR/$_name" if [ -e "$_link" ] && [ ! -L "$_link" ]; then warn "Skipped $_link because it already exists and is not a symlink" return fi mkdir -p "$LOCAL_BIN_DIR" ln -sf "$_target" "$_link" success "Linked $_link -> $_target" } link_commands() { link_command msb "$BIN_DIR/msb" link_command microsandbox "$BIN_DIR/microsandbox" COMMAND_HINT="msb" case ":$PATH:" in *":$LOCAL_BIN_DIR:"*) ;; *) COMMAND_HINT="$LOCAL_BIN_DIR/msb" printf "\n" printf " ${YELLOW}Note:${RESET} %s is not on your PATH.\n" "$LOCAL_BIN_DIR" printf " Add it to your shell profile if you want to run ${BOLD}msb${RESET} directly:\n" printf "\n" printf " ${DIM}export${RESET} PATH=\"%s:\$PATH\"\n" "$LOCAL_BIN_DIR" printf "\n" ;; esac } # --------------------------------------------------------------------------- # Progress bar # --------------------------------------------------------------------------- # Draw a progress bar: progress_bar