#!/usr/bin/env bash # Mochi installer — downloads and installs the Mochi CLI and desktop app. # # Usage: # curl -fsSL https://install.mochiexec.io | bash # curl -fsSL https://install.mochiexec.io/v1.2.3 | bash # curl -fsSL https://install.mochiexec.io | bash -s -- [VERSION] [--accept-eula] # # The installer asks for your license key on the terminal. The key is never an argument: # one passed that way would sit in the process list and in shell history. # # Options: # --accept-eula Accept the desktop app's license agreement without asking (macOS). # Read it first: https://mochiexec.io/eula # # Environment variables: # MOCHI_LICENSE License key to register after install, instead of the prompt # MOCHI_VERSION Version to install (default: latest); a leading "v" is optional # MOCHI_INSTALL_DIR Install root (default: ~/.mochi) # MOCHI_BASE_URL Release origin (default: https://releases.mochiexec.io) # MOCHI_SKIP_DESKTOP Set to 1 to install only the CLI # MOCHI_ACCEPT_EULA Set to 1 for the same effect as --accept-eula # MOCHI_NO_MODIFY_PATH Set to 1 to leave shell rc files alone # MOCHI_DEBUG Set to 1 for verbose output # # This script is piped into bash, so it must never read from stdin: stdin is the # script itself, and anything that consumes it eats the rest of the installer. # Piped into `sh`, the shell may be dash, which stops at the first bash-only line with # an error about that line. This check is plain POSIX so it runs first under any shell. if [ -z "${BASH_VERSION:-}" ]; then echo "The Mochi installer needs bash. Pipe it into bash instead of sh:" >&2 echo " curl -fsSL https://install.mochiexec.io | bash" >&2 exit 1 fi set -euo pipefail INSTALL_DIR="${MOCHI_INSTALL_DIR:-$HOME/.mochi}" BIN_DIR="${INSTALL_DIR}/bin" BASE_URL="${MOCHI_BASE_URL:-https://releases.mochiexec.io}" LICENSE_KEY="${MOCHI_LICENSE:-}" REQUESTED_VERSION="${MOCHI_VERSION:-latest}" DEBUG="${MOCHI_DEBUG:-0}" SKIP_DESKTOP="${MOCHI_SKIP_DESKTOP:-0}" NO_MODIFY_PATH="${MOCHI_NO_MODIFY_PATH:-0}" ACCEPT_EULA="${MOCHI_ACCEPT_EULA:-0}" # Everything downloaded goes into a private temp dir that the exit trap removes, so a # failed run never leaves half-verified binaries behind and never deletes a user # directory it did not create. WORK_DIR="" # ============================================================================ # Output # ============================================================================ if [ -t 1 ] && [ -z "${NO_COLOR:-}" ]; then RED=$'\033[0;31m'; GREEN=$'\033[0;32m'; YELLOW=$'\033[1;33m' BLUE=$'\033[0;34m'; MAGENTA=$'\033[0;35m'; CYAN=$'\033[0;36m' BOLD=$'\033[1m'; NC=$'\033[0m' else RED=''; GREEN=''; YELLOW=''; BLUE=''; MAGENTA=''; CYAN=''; BOLD=''; NC='' fi log_info() { printf '%s\n' "${BLUE}i${NC} $1"; } log_success() { printf '%s\n' "${GREEN}✓${NC} $1"; } log_error() { printf '%s\n' "${RED}✗${NC} $1" >&2; } log_warn() { printf '%s\n' "${YELLOW}!${NC} $1" >&2; } log_debug() { [ "$DEBUG" = "1" ] && printf '%s\n' "${CYAN}[debug]${NC} $1" >&2 || true; } log_step() { printf '\n%s\n' "${BOLD}${MAGENTA}▶${NC} ${BOLD}$1${NC}"; } banner() { cat << 'EOF' _ _ __ ___ _ _ __ ( \/ ) / \ / __)/ )( \( ) / \/ \( O )( (__ ) __ ( )( \_)(_/ \__/ \___)\_)(_/(__) EOF } cleanup() { local exit_code=$? if [ -n "$WORK_DIR" ] && [ -d "$WORK_DIR" ]; then rm -rf "$WORK_DIR" fi if [ $exit_code -ne 0 ]; then log_error "Installation failed." [ "$DEBUG" = "0" ] && log_info "Re-run with MOCHI_DEBUG=1 for details." log_info "If this keeps happening, email support@mochiexec.io" fi } trap cleanup EXIT command_exists() { command -v "$1" > /dev/null 2>&1; } # ============================================================================ # Download + verification # ============================================================================ # download URL DEST — returns non-zero rather than writing a partial or error-page file. # # Transport is pinned to HTTPS for the real release origin: these downloads become # executables on the user's machine, and a plaintext fetch is trivially substitutable. # The restriction is lifted only when the caller has deliberately pointed # MOCHI_BASE_URL at a plain-HTTP origin (a local mirror, or a test). download() { local url="$1" dest="$2" log_debug "GET $url" if command_exists curl; then local proto=(--proto '=https' --tlsv1.2) case "$url" in http://*) proto=() ;; esac # --fail turns an HTTP error into a non-zero exit instead of saving the error body. curl -fsSL "${proto[@]+"${proto[@]}"}" --retry 3 --retry-delay 2 \ --connect-timeout 20 "$url" -o "$dest" < /dev/null elif command_exists wget; then local https_only=(--https-only) case "$url" in http://*) https_only=() ;; esac wget -q "${https_only[@]+"${https_only[@]}"}" --retry-connrefused --waitretry=2 \ --tries=3 --timeout=60 "$url" -O "$dest" < /dev/null else log_error "Neither curl nor wget is available. Install one and re-run." exit 1 fi } sha256_of() { local file="$1" if command_exists sha256sum; then sha256sum "$file" | awk '{print $1}' elif command_exists shasum; then shasum -a 256 "$file" | awk '{print $1}' else log_error "Neither sha256sum nor shasum is available; cannot verify downloads." exit 1 fi } # verify_checksum FILE EXPECTED — an unverifiable download is a failed download. A # missing expected checksum is treated the same way: silently skipping verification is # how a corrupted or substituted artifact gets installed. verify_checksum() { local file="$1" expected="$2" actual if [ -z "$expected" ] || [ "$expected" = "null" ]; then log_error "No checksum published for $(basename "$file"); refusing to install it." return 1 fi actual="$(sha256_of "$file")" if [ "$actual" != "$expected" ]; then log_error "Checksum mismatch for $(basename "$file")" log_error " expected: $expected" log_error " actual: $actual" return 1 fi log_debug "checksum ok: $(basename "$file")" return 0 } # ============================================================================ # Platform # ============================================================================ detect_platform() { local os arch case "$(uname -s | tr '[:upper:]' '[:lower:]')" in linux*) os="linux" ;; darwin*) os="darwin" ;; *) log_error "Unsupported operating system: $(uname -s). Mochi supports Linux and macOS." exit 1 ;; esac case "$(uname -m)" in x86_64|amd64) arch="amd64" ;; arm64|aarch64) arch="arm64" ;; *) log_error "Unsupported architecture: $(uname -m). Mochi supports x86_64 and arm64." exit 1 ;; esac printf '%s-%s\n' "$os" "$arch" } # ============================================================================ # Release manifest # # version.txt is a line-oriented manifest published alongside version.json: # # version 1.2.3 # released 2026-01-01T00:00:00Z # cli darwin-arm64 mochi-1.2.3-darwin-arm64.tar.gz # desktop darwin Mochi-Desktop-1.2.3-darwin.dmg # # The installer reads that rather than version.json so it needs no JSON parser: a stock # macOS has no jq. # ============================================================================ MANIFEST="" fetch_manifest() { local version="$1" MANIFEST="${WORK_DIR}/version.txt" if download "${BASE_URL}/${version}/version.txt" "$MANIFEST" 2> /dev/null; then return 0 fi # Some early releases publish only version.json. log_debug "version.txt unavailable; falling back to version.json" local json="${WORK_DIR}/version.json" if ! download "${BASE_URL}/${version}/version.json" "$json" 2> /dev/null; then return 1 fi if ! command_exists jq; then log_error "This release only publishes version.json and jq is not installed." log_error "Install jq, or install a newer version of Mochi." exit 1 fi { jq -r '"version " + .version' "$json" jq -r '(.cli // {}) | to_entries[] | "cli \(.key) \(.value.filename) \(.value.checksum)"' "$json" jq -r '(.desktop // {}) | to_entries[] | "desktop \(.key) \(.value.filename) \(.value.checksum)"' "$json" } > "$MANIFEST" } # manifest_lookup KIND KEY — prints "filename checksum", or nothing when absent. manifest_lookup() { awk -v kind="$1" -v key="$2" '$1 == kind && $2 == key { print $3, $4; exit }' "$MANIFEST" } manifest_version() { awk '$1 == "version" { print $2; exit }' "$MANIFEST" } manifest_platforms() { awk -v kind="$1" '$1 == kind { printf " - %s\n", $2 }' "$MANIFEST" } # resolve_version normalizes "v1.2.3" and "1.2.3" to the form used as the release # prefix, and resolves "latest" through the latest pointer. # # Every failure path is explicit rather than left to `set -e`, which does not unwind out # of a command substitution, so an unresolved version fails here with a clear message. resolve_version() { local requested="$1" if [ "$requested" != "latest" ] && [ -n "$requested" ]; then printf '%s\n' "${requested#v}" return 0 fi log_step "Resolving the latest release..." >&2 local pointer="${WORK_DIR}/latest.txt" resolved="" status=0 if download "${BASE_URL}/latest/version.txt" "$pointer" 2> /dev/null; then resolved="$(awk '$1 == "version" { print $2; exit }' "$pointer")" elif download "${BASE_URL}/latest/version.json" "${WORK_DIR}/latest.json" 2> /dev/null; then if command_exists jq; then resolved="$(jq -r '.version // empty' "${WORK_DIR}/latest.json")" else resolved="$(sed -n 's/.*"version"[[:space:]]*:[[:space:]]*"\([^"]*\)".*/\1/p' \ "${WORK_DIR}/latest.json" | head -1)" fi else status=$? # curl exits 22 and wget 8 when the server answered with an error, so the origin # is reachable and simply has no latest pointer. Only stable releases set one. if [ "$status" -eq 22 ] || [ "$status" -eq 8 ]; then log_error "Mochi has no stable release yet, so there is no latest version to install." log_error "Install a specific version instead:" else log_error "Could not reach ${BASE_URL} to find the latest release." log_error "Check your connection, or install a specific version:" fi log_error " curl -fsSL https://install.mochiexec.io/v1.2.3 | bash" return 1 fi if [ -z "$resolved" ]; then log_error "The latest-release pointer at ${BASE_URL}/latest/ is unreadable." return 1 fi printf '%s\n' "${resolved#v}" } # ============================================================================ # Update window # ============================================================================ # Set when the license's year of updates ended before the release being installed came # out. Holds the date it ended, YYYY-MM-DD. UPDATES_ENDED="" # Set when an existing install was left in place for that reason. KEPT_EXISTING=0 # json_field NAME — the value of a top-level string field in `license status -o json`, # which prints one field per line. No jq: a stock macOS doesn't have it. json_field() { sed -n "s/^[[:space:]]*\"$1\"[[:space:]]*:[[:space:]]*\"\([^\"]*\)\".*/\1/p" | head -1 } # check_update_window BINARY asks the downloaded, not yet installed, CLI whether the # license covers it. The binary carries its own release date and applies the same rule # the app does, so the installer never compares dates itself. Any failure to get an # answer counts as covered: this check must never be the reason an install fails. check_update_window() { local binary="$1" status_json state if [ -n "$LICENSE_KEY" ]; then status_json="$(MOCHI_LICENSE_KEY="$LICENSE_KEY" "$binary" license status -o json 2> /dev/null)" || return 0 else status_json="$("$binary" license status -o json 2> /dev/null)" || return 0 fi state="$(printf '%s\n' "$status_json" | json_field state)" [ "$state" = "update_not_covered" ] || return 0 UPDATES_ENDED="$(printf '%s\n' "$status_json" | json_field updatesUntil | cut -c1-10)" UPDATES_ENDED="${UPDATES_ENDED:-unknown}" } # keep_existing_install leaves a working install alone rather than replacing it with a # release the license doesn't cover, which would refuse to run Mochi's own commands. keep_existing_install() { local version="$1" previous="$2" log_warn "Mochi ${version} came out after your updates ended on ${UPDATES_ENDED}." log_info "Keeping the version you have: ${previous:-the existing install}." log_info "Renew updates to install ${version}: ${BOLD}https://mochiexec.io${NC}" printf '\n' } # ============================================================================ # CLI # ============================================================================ install_cli() { local version="$1" platform="$2" log_step "Installing the Mochi CLI..." local entry filename checksum entry="$(manifest_lookup cli "$platform")" if [ -z "$entry" ]; then log_error "This release has no CLI build for $platform." log_info "Published platforms:" manifest_platforms cli exit 1 fi filename="${entry%% *}" checksum="${entry##* }" log_info "Downloading ${filename}" local archive="${WORK_DIR}/${filename}" download "${BASE_URL}/${version}/${filename}" "$archive" verify_checksum "$archive" "$checksum" || exit 1 log_success "Verified ${filename}" local extract="${WORK_DIR}/extract" mkdir -p "$extract" tar -xzf "$archive" -C "$extract" local binary binary="$(find "$extract" -name mochi -type f -perm -u+x | head -1)" if [ -z "$binary" ]; then log_error "The archive does not contain a mochi binary." exit 1 fi # Verify before installing, so a broken build never replaces a working one, and # install with mv so an in-use binary is swapped atomically rather than truncated. chmod +x "$binary" if ! "$binary" --version > /dev/null 2>&1; then log_error "The downloaded binary does not run on this machine." exit 1 fi check_update_window "$binary" if [ -n "$UPDATES_ENDED" ] && [ -x "${BIN_DIR}/mochi" ]; then KEPT_EXISTING=1 return 0 fi mkdir -p "$BIN_DIR" mv -f "$binary" "${BIN_DIR}/mochi" log_success "CLI installed: $("${BIN_DIR}/mochi" --version 2>/dev/null | head -1)" } # ============================================================================ # License # ============================================================================ # prompt_license asks for the key on the terminal. stdin is the script itself, so the # answer is read from /dev/tty, and only when there is a terminal to answer on. prompt_license() { [ -t 2 ] && { : < /dev/tty; } 2> /dev/null || return 0 local key="" printf '%s' "License key (Enter to skip): " >&2 IFS= read -rs key < /dev/tty || key="" printf '\n' >&2 printf '%s' "$key" } register_license() { local license="$1" if [ -z "$license" ]; then log_step "No license key supplied" log_info "Mochi's own commands need a license. Add one whenever you're ready:" printf ' %s\n' "${BOLD}mochi license set${NC}" log_info "Or try it free for 7 days: ${BOLD}mochi license trial --email you@example.com${NC}" log_info "Buy one at ${BOLD}https://buy.mochiexec.io${NC}" return 0 fi log_step "Registering your license..." # A rejected key is not a failed installation: the CLI is installed and working, and # the user can retry with `mochi license set` once they have the right key. Aborting # here would delete a perfectly good install over a typo. # On stdin, not as an argument, so the key never shows in the process list. if printf '%s\n' "$license" | "${BIN_DIR}/mochi" license set; then log_success "License registered." else log_warn "Could not register that license key." log_info "Mochi is installed. Retry with: ${BOLD}mochi license set${NC}" fi } # ============================================================================ # Desktop app # ============================================================================ # confirm_eula succeeds once the desktop app's license agreement has been accepted: by # --accept-eula or MOCHI_ACCEPT_EULA=1, or by an answer on the terminal. stdin is the # script itself, so the answer is read from /dev/tty. confirm_eula() { [ "$ACCEPT_EULA" = "1" ] && return 0 if [ -t 2 ] && { : < /dev/tty; } 2> /dev/null; then local answer="" log_info "Mochi Desktop's license agreement: ${BOLD}https://mochiexec.io/eula${NC}" printf '%s' "Accept it and install the app? [y/N] " >&2 IFS= read -r answer < /dev/tty || answer="" case "$answer" in [yY] | [yY][eE][sS]) return 0 ;; esac log_warn "The license agreement was not accepted; the desktop app was not installed." return 1 fi log_warn "Installing the desktop app means accepting its license agreement, and there is" log_warn "no terminal to ask on. Read it at https://mochiexec.io/eula, then re-run with" log_warn "--accept-eula to accept it." return 1 } # mount_dmg DMG MOUNT_POINT. The disk image carries the license agreement, and macOS will # not mount it until someone answers it. confirm_eula already has the answer, so hdiutil # gets it on a pipe rather than paging the agreement through the terminal. mount_dmg() { local dmg="$1" mount_point="$2" # `yes` ends on SIGPIPE once hdiutil stops reading, which pipefail would report. if ! (yes 2> /dev/null || true) | hdiutil attach -nobrowse -readonly \ -mountpoint "$mount_point" "$dmg" > /dev/null; then log_error "Could not mount the disk image." return 1 fi } install_desktop_macos() { local version="$1" log_step "Installing Mochi Desktop..." local entry filename checksum entry="$(manifest_lookup desktop darwin)" if [ -z "$entry" ]; then log_warn "This release has no macOS desktop build." return 0 fi filename="${entry%% *}" checksum="${entry##* }" # Declining is a choice rather than a failed install, and it saves the download. confirm_eula || return 0 log_info "Downloading ${filename}" local dmg="${WORK_DIR}/${filename}" download "${BASE_URL}/${version}/${filename}" "$dmg" verify_checksum "$dmg" "$checksum" || return 1 log_success "Verified ${filename}" local mount_point="${WORK_DIR}/dmg" mount_dmg "$dmg" "$mount_point" || return 1 # Detach even if the copy below fails, so a failed install does not leave the volume # mounted for the rest of the session. trap 'hdiutil detach "$mount_point" -quiet 2>/dev/null || true' RETURN local app_bundle app_bundle="$(find "$mount_point" -maxdepth 1 -name '*.app' | head -1)" if [ -z "$app_bundle" ]; then log_error "No application bundle inside the disk image." return 1 fi # Prefer /Applications, but never escalate on our own: a script being piped into # bash cannot prompt for a password (stdin is the script), so a sudo that needs one # would hang forever. ~/Applications needs no privileges and the CLI looks there too. local target app_name app_name="$(basename "$app_bundle")" if [ -w /Applications ]; then target="/Applications" else target="${HOME}/Applications" mkdir -p "$target" log_info "/Applications is not writable; installing to ~/Applications instead." fi rm -rf "${target:?}/${app_name}" cp -R "$app_bundle" "$target/" if command_exists codesign && ! codesign --verify --deep --strict "${target}/${app_name}" 2> /dev/null; then log_warn "${app_name} is not validly signed — macOS may refuse to open it." log_warn "Please report this to support@mochiexec.io rather than bypassing Gatekeeper." fi log_success "Desktop app installed to ${target}/${app_name}" } install_desktop_linux() { local version="$1" arch="$2" log_step "Installing Mochi Desktop..." # The Linux desktop app is published for x86_64 only; the CLI also covers arm64. if [ "$arch" != "amd64" ]; then log_warn "The desktop app is not yet built for Linux ${arch}; installing the CLI only." log_info "Track it at https://mochiexec.io — the CLI is fully supported here." return 0 fi local entry filename checksum entry="$(manifest_lookup desktop linux)" if [ -z "$entry" ]; then log_warn "This release has no Linux desktop build." return 0 fi filename="${entry%% *}" checksum="${entry##* }" log_info "Downloading ${filename}" local appimage="${WORK_DIR}/${filename}" download "${BASE_URL}/${version}/${filename}" "$appimage" verify_checksum "$appimage" "$checksum" || return 1 log_success "Verified ${filename}" # ~/.mochi/bin/mochi-desktop is one of the locations `mochi desktop` searches, so # installing here is what makes that command able to launch the app. mkdir -p "$BIN_DIR" chmod +x "$appimage" mv -f "$appimage" "${BIN_DIR}/mochi-desktop" install_linux_icon "${BIN_DIR}/mochi-desktop" local desktop_file="${HOME}/.local/share/applications/mochi.desktop" mkdir -p "$(dirname "$desktop_file")" cat > "$desktop_file" << EOF [Desktop Entry] Type=Application Name=Mochi Comment=Run and manage your development workflows Exec=${BIN_DIR}/mochi-desktop %u Icon=mochi Terminal=false Categories=Development;Utility; MimeType=x-scheme-handler/mochi; StartupWMClass=Mochi EOF # Register the mochi:// scheme handler so deep links from the CLI and the website # reach the app. Harmless when the desktop environment does not use it. if command_exists update-desktop-database; then update-desktop-database "$(dirname "$desktop_file")" 2> /dev/null || true fi log_success "Desktop app installed to ${BIN_DIR}/mochi-desktop" check_appimage_runtime "${BIN_DIR}/mochi-desktop" local deb_entry deb_entry="$(manifest_lookup desktop linux-deb)" if [ -n "$deb_entry" ]; then log_info "On an apt-based distro you can install the system package instead:" printf ' %s\n' "${BASE_URL}/${version}/${deb_entry%% *}" fi } # The .desktop entry names an icon by ID, which only resolves if a matching file is in # the icon theme. Without this the app shows up in the launcher as a blank square. The # icon lives inside the AppImage, and --appimage-extract reads it without needing FUSE. install_linux_icon() { local appimage="$1" extract_dir icon extract_dir="$(mktemp -d "${TMPDIR:-/tmp}/mochi-icon.XXXXXX")" if ! (cd "$extract_dir" && "$appimage" --appimage-extract '*.png' > /dev/null 2>&1); then log_debug "could not extract an icon from the AppImage" rm -rf "$extract_dir" return 0 fi # Largest available, so the launcher and the dock both have something crisp. icon="$(find "${extract_dir}/squashfs-root" -name '*.png' -type f 2> /dev/null | xargs -r ls -S 2> /dev/null | head -1)" if [ -n "$icon" ]; then local icon_dir="${HOME}/.local/share/icons/hicolor/256x256/apps" mkdir -p "$icon_dir" cp "$icon" "${icon_dir}/mochi.png" command_exists gtk-update-icon-cache && gtk-update-icon-cache -f -t "${HOME}/.local/share/icons/hicolor" > /dev/null 2>&1 || true log_debug "installed launcher icon" fi rm -rf "$extract_dir" } # An AppImage needs FUSE 2 to mount itself, and several current distros ship only FUSE # 3. The failure is a dlopen error about libfuse.so.2 at launch, which reads like a # broken download rather than a missing system library — so it is worth saying up front, # with both ways out. check_appimage_runtime() { local appimage="$1" if "$appimage" --appimage-version > /dev/null 2>&1; then return 0 fi log_warn "This system does not appear to have FUSE 2, which AppImages need." log_info "Either install it (Debian/Ubuntu: ${BOLD}sudo apt install libfuse2${NC})," log_info "or run the app without it: ${BOLD}mochi-desktop --appimage-extract-and-run${NC}" } # ============================================================================ # PATH # ============================================================================ configure_path() { if [ "$NO_MODIFY_PATH" = "1" ]; then log_info "Leaving PATH alone (MOCHI_NO_MODIFY_PATH=1). Add: ${BOLD}${BIN_DIR}${NC}" return 0 fi log_step "Configuring PATH..." case ":${PATH}:" in *":${BIN_DIR}:"*) log_success "${BIN_DIR} is already on PATH." return 0 ;; esac local line="export PATH=\"${BIN_DIR}:\$PATH\"" local touched=0 config # Write to the rc file for the user's login shell, creating it if needed, so a fresh # machine with no ~/.zshrc still gets a PATH entry. for config in $(path_config_files); do if [ -f "$config" ] && grep -Fq "$BIN_DIR" "$config"; then touched=1 continue fi mkdir -p "$(dirname "$config")" { printf '\n# Mochi\n' printf '%s\n' "$line" } >> "$config" log_success "Added ${BIN_DIR} to $(basename "$config")" touched=1 done if [ "$touched" = "1" ]; then log_info "Open a new shell, or run: ${BOLD}export PATH=\"${BIN_DIR}:\$PATH\"${NC}" else log_info "Add this to your shell profile: ${BOLD}${line}${NC}" fi } path_config_files() { case "$(basename "${SHELL:-/bin/bash}")" in zsh) printf '%s\n' "${ZDOTDIR:-$HOME}/.zshrc" ;; bash) printf '%s\n' "$HOME/.bashrc" ;; fish) printf '%s\n' "$HOME/.config/fish/conf.d/mochi.fish" ;; *) printf '%s\n' "$HOME/.profile" ;; esac } # ============================================================================ # Install record # ============================================================================ save_installation_info() { local version="$1" platform="$2" mkdir -p "$INSTALL_DIR" cat > "${INSTALL_DIR}/install.json" << EOF { "version": "${version}", "platform": "${platform}", "installed": "$(date -u +%Y-%m-%dT%H:%M:%SZ)", "install_dir": "${INSTALL_DIR}", "bin_dir": "${BIN_DIR}", "source": "${BASE_URL}" } EOF } # ============================================================================ # Main # ============================================================================ # parse_args takes an optional version and --accept-eula. Anything else is most likely a # license key, which is refused so it never lands in shell history; the installer prompts # for it instead. parse_args() { local arg for arg in "$@"; do [ -n "$arg" ] || continue if [ "$arg" = "--accept-eula" ]; then ACCEPT_EULA=1 continue fi if [ "$arg" = "latest" ] || printf '%s' "$arg" | grep -Eq '^v?[0-9]+\.[0-9]+\.[0-9]+([-+][0-9A-Za-z.-]+)?$'; then REQUESTED_VERSION="$arg" continue fi log_error "The installer only takes a version, like v1.2.3, and --accept-eula." log_error "Your license key is no longer an argument, where other users could see it." log_error "Run the installer without it and paste the key when asked:" log_error " curl -fsSL https://install.mochiexec.io | bash" log_error "or, unattended, set MOCHI_LICENSE in the environment." exit 1 done } main() { banner parse_args "$@" log_info "Installing Mochi into ${BOLD}${INSTALL_DIR}${NC}" if [ -z "$LICENSE_KEY" ]; then LICENSE_KEY="$(prompt_license)" fi WORK_DIR="$(mktemp -d "${TMPDIR:-/tmp}/mochi-install.XXXXXX")" local platform os arch version previous platform="$(detect_platform)" os="${platform%%-*}" arch="${platform##*-}" log_info "Platform: ${platform}" if ! version="$(resolve_version "$REQUESTED_VERSION")" || [ -z "$version" ]; then exit 1 fi if ! fetch_manifest "$version"; then log_error "No published release found at ${BASE_URL}/${version}/" exit 1 fi log_info "Version: ${BOLD}${version}${NC}" previous="" if [ -x "${BIN_DIR}/mochi" ]; then previous="$("${BIN_DIR}/mochi" --version 2>/dev/null | head -1 || true)" log_info "Replacing existing install: ${previous:-unknown}" fi install_cli "$version" "$platform" if [ "$KEPT_EXISTING" = "1" ]; then keep_existing_install "$version" "$previous" exit 0 fi register_license "$LICENSE_KEY" if [ "$SKIP_DESKTOP" = "1" ]; then log_info "Skipping the desktop app (MOCHI_SKIP_DESKTOP=1)." else case "$os" in darwin) install_desktop_macos "$version" || log_warn "Desktop install failed; the CLI is installed." ;; linux) install_desktop_linux "$version" "$arch" || log_warn "Desktop install failed; the CLI is installed." ;; esac fi configure_path save_installation_info "$version" "$platform" printf '\n%s\n' "${GREEN}${BOLD}Mochi ${version} is installed.${NC}" printf '\n' log_info "${BOLD}Binary:${NC} ${BIN_DIR}/mochi" printf '\n' if [ -n "$UPDATES_ENDED" ]; then # Nothing to keep on a fresh machine. Flow's commands all work; Mochi's own need # a release from inside the update window. log_warn "Mochi ${version} came out after your updates ended on ${UPDATES_ENDED}." log_info "Flow's commands work. For Mochi's own, renew updates at ${BOLD}https://mochiexec.io${NC}," log_info "or install a release from before then: ${BOLD}MOCHI_VERSION=${NC} curl -fsSL https://install.mochiexec.io | bash" printf '\n' fi log_info "${BOLD}Next steps${NC}" printf ' %s\n' "1. Open a new shell (or export the PATH line above)" printf ' %s\n' "2. mochi --version" printf ' %s\n' "3. mochi desktop # launch the app" printf '\n' log_info "Get started: ${BOLD}https://docs.mochiexec.io/getting-started/quickstart${NC}" printf '\n' } main "$@"