#!/bin/sh # Atmosphere CLI Installer # Usage: curl -fsSL https://raw.githubusercontent.com/Atmosphere/atmosphere/main/cli/install.sh | sh # # Copyright 2008-2026 Async-IO.org — Apache License 2.0 set -e VERSION="4.0.77" INSTALL_DIR="${ATMOSPHERE_INSTALL_DIR:-/usr/local/bin}" ATMOSPHERE_HOME="${ATMOSPHERE_HOME:-$HOME/.atmosphere}" # The CLI and samples.json come from the release this installer belongs to: the # tag atmosphere-$VERSION, so "Installer v$VERSION" installs CLI $VERSION. The # release workflow sets VERSION to each release, so the installer on main names # the latest release. A SNAPSHOT installer has no tag and takes main. # ATMOSPHERE_INSTALL_REF picks another branch or tag. if [ -n "${ATMOSPHERE_INSTALL_REF:-}" ]; then INSTALL_REF="$ATMOSPHERE_INSTALL_REF" else case "$VERSION" in *SNAPSHOT*) INSTALL_REF="main" ;; *) INSTALL_REF="atmosphere-$VERSION" ;; esac fi BASE_URL="https://raw.githubusercontent.com/Atmosphere/atmosphere/$INSTALL_REF/cli" # ── Colors ────────────────────────────────────────────────────────────────── if [ -t 1 ]; then BOLD='\033[1m' CYAN='\033[36m' GREEN='\033[32m' YELLOW='\033[33m' RED='\033[31m' RESET='\033[0m' else BOLD='' CYAN='' GREEN='' YELLOW='' RED='' RESET='' fi info() { printf "${CYAN}→${RESET} %s\n" "$1"; } ok() { printf "${GREEN}✓${RESET} %s\n" "$1"; } warn() { printf "${YELLOW}!${RESET} %s\n" "$1"; } die() { printf "${RED}error:${RESET} %s\n" "$1" >&2; exit 1; } # ── Detect platform ──────────────────────────────────────────────────────── detect_platform() { os=$(uname -s | tr '[:upper:]' '[:lower:]') case "$os" in darwin|linux) ;; *) die "Unsupported OS: $os. Atmosphere CLI supports macOS and Linux." ;; esac } # ── Check prerequisites ──────────────────────────────────────────────────── check_java() { if command -v java >/dev/null 2>&1; then # Anchor on `version "` — a bare `.*"` is greedy, consumes through the # closing quote and captures the empty string, so every user with a # perfectly good JDK 21 was told to go install Java. java_ver=$(java -version 2>&1 | sed -n 's/.*version "\([0-9][0-9]*\).*/\1/p' | head -1) if [ -n "$java_ver" ] && [ "$java_ver" -ge 21 ] 2>/dev/null; then ok "Java $java_ver detected" return fi fi warn "Java 21+ not found" printf "\n Install Java 21:\n" case "$(uname -s)" in Darwin) printf " brew install openjdk@21\n" ;; *) printf " sudo apt install openjdk-21-jdk # Debian/Ubuntu\n" printf " sudo dnf install java-21-openjdk # Fedora/RHEL\n" ;; esac printf "\n Or use SDKMAN: https://sdkman.io\n" printf " sdk install java 21-tem\n\n" } # ── Download ──────────────────────────────────────────────────────────────── download() { url="$1"; dest="$2" if command -v curl >/dev/null 2>&1; then curl -fsSL -o "$dest" "$url" elif command -v wget >/dev/null 2>&1; then wget -q -O "$dest" "$url" else die "curl or wget is required" fi } # ── Install ───────────────────────────────────────────────────────────────── install_cli() { printf "\n${BOLD}Atmosphere CLI Installer${RESET} v%s\n\n" "$VERSION" detect_platform check_java # Create home directory mkdir -p "$ATMOSPHERE_HOME/cache" ok "Created $ATMOSPHERE_HOME" # Download CLI script and samples.json info "Downloading CLI ($INSTALL_REF)..." tmp_dir=$(mktemp -d) trap 'rm -rf "$tmp_dir"' EXIT download "$BASE_URL/atmosphere" "$tmp_dir/atmosphere" \ || die "could not download the CLI from $INSTALL_REF ($BASE_URL/atmosphere)" download "$BASE_URL/samples.json" "$tmp_dir/samples.json" \ || die "could not download samples.json from $INSTALL_REF ($BASE_URL/samples.json)" chmod +x "$tmp_dir/atmosphere" # Install to INSTALL_DIR if [ -w "$INSTALL_DIR" ]; then cp "$tmp_dir/atmosphere" "$INSTALL_DIR/atmosphere" cp "$tmp_dir/samples.json" "$ATMOSPHERE_HOME/samples.json" ok "Installed to $INSTALL_DIR/atmosphere" else info "Installing to $INSTALL_DIR requires sudo" sudo cp "$tmp_dir/atmosphere" "$INSTALL_DIR/atmosphere" cp "$tmp_dir/samples.json" "$ATMOSPHERE_HOME/samples.json" ok "Installed to $INSTALL_DIR/atmosphere" fi # Also store samples.json next to the script if possible if [ -w "$INSTALL_DIR" ]; then cp "$tmp_dir/samples.json" "$INSTALL_DIR/samples.json" 2>/dev/null || true fi # Verify the CLI this installer wrote, not whichever `atmosphere` the PATH # finds first: an earlier install (Homebrew, SDKMAN) may shadow it. installed="${INSTALL_DIR%/}/atmosphere" "$installed" version >/dev/null 2>&1 \ || die "the installed CLI does not run: $installed version" on_path=$(command -v atmosphere 2>/dev/null || true) if [ "$on_path" = "$installed" ]; then ok "Installation complete!" elif [ -n "$on_path" ]; then warn "Installed $installed, but another atmosphere comes first on your PATH: $on_path" printf "\n Remove it, or put %s first in your PATH:\n" "$INSTALL_DIR" printf " export PATH=\"%s:\$PATH\"\n\n" "$INSTALL_DIR" else warn "Installed $installed, but $INSTALL_DIR may not be in your PATH" printf "\n Add to your shell profile:\n" printf " export PATH=\"%s:\$PATH\"\n\n" "$INSTALL_DIR" fi # Print next steps printf "\n${BOLD}Get started:${RESET}\n\n" printf " atmosphere list # See all samples\n" printf " atmosphere run spring-boot-chat # Run a sample\n" printf " atmosphere new my-app # Create a new project\n" printf "\n" } # ── Uninstall ─────────────────────────────────────────────────────────────── uninstall_cli() { printf "\n${BOLD}Uninstalling Atmosphere CLI${RESET}\n\n" if [ -f "$INSTALL_DIR/atmosphere" ]; then if [ -w "$INSTALL_DIR" ]; then rm -f "$INSTALL_DIR/atmosphere" rm -f "$INSTALL_DIR/samples.json" else sudo rm -f "$INSTALL_DIR/atmosphere" sudo rm -f "$INSTALL_DIR/samples.json" fi ok "Removed $INSTALL_DIR/atmosphere" fi if [ -d "$ATMOSPHERE_HOME" ]; then printf " Remove cache? (%s) [y/N] " "$ATMOSPHERE_HOME" read -r confirm if [ "$confirm" = "y" ] || [ "$confirm" = "Y" ]; then rm -rf "$ATMOSPHERE_HOME" ok "Removed $ATMOSPHERE_HOME" fi fi ok "Uninstall complete" printf "\n" } # ── Main ──────────────────────────────────────────────────────────────────── case "${1:-install}" in install) install_cli ;; uninstall) uninstall_cli ;; *) die "Usage: install.sh [install|uninstall]" ;; esac