#!/bin/zsh # ROS2Lab - Try ROS 2 on your Mac (macOS 14 Sonoma or newer; Apple Silicon or Intel). # # curl -fsSL https://www.ros2lab.com/install/try-mac.sh | zsh # # STATUS: tested on Ubuntu 24.04; Windows and macOS not yet run on a real machine # (this Mac script was checked on Linux with zsh -n, bash -n, shellcheck and stand-in commands). # A web page cannot install programs by itself. This one pasted command is the closest safe thing: you can read it first. # What it does: # 1. checks this Mac (macOS >= 14, chip, free space >= 2 GB, memory, a screen for the turtle window); every check prints OK # or one line saying what to do; # 2. puts pixi 0.84.2 (a package manager, one file) in ~/ros2lab-try/bin, checked against its SHA256 below; # 3. downloads pixi.toml, pixi.lock, ros2lab-try.py and SHA256SUMS and checks them against SHA256SUMS; # 4. `pixi install --frozen`: ROS 2 Jazzy + turtlesim from RoboStack (conda-forge), about 290 MB of downloads, # exactly the versions in pixi.lock; # 5. starts ros2lab-try.py (bridge v3, source: www.ros2lab.com/install/try/ros2lab-try.py): it checks that ROS 2 can talk on # this Mac (a test message; if the default DDS stays silent it switches to Cyclone DDS), opens the turtlesim window, # connects OUT to the ROS2Lab relay (no port is opened on this Mac) and opens your browser at www.ros2lab.com/pc with a # secret link (works in Safari too; it also prints a short code for another browser). The page can then run ros2 # commands for turtlesim here, checked word by word on THIS Mac, never through a shell. # It stops by itself after 60 min with no page connected. # Advanced: ROS2LAB_DIRECT=1 (or a blocked relay) uses the older direct connection on 127.0.0.1:7777 with a pairing code. # Downloads: github.com/prefix-dev/pixi (pixi), www.ros2lab.com/install/try/ (the 4 files above), prefix.dev and # conda.anaconda.org (the ROS 2 packages). While it runs, the bridge talks to the relay (*.firebasedatabase.app, # identitytoolkit/securetoken.googleapis.com): commands from your page and their output, the turtle positions, and a label # like "macOS 14.5 Mac" (never your computer's name or files). Ctrl+C deletes it all from the relay. # Where it writes: ONLY ~/ros2lab-try. No sudo, no password, no Homebrew, no Xcode tools, no change to ~/.zshrc or PATH. # Remove it: Ctrl+C here, then rm -rf ~/ros2lab-try # Run it again: the same command. It upgrades in place (new files from the site, same folder) and opens the turtle again. # Syntax kept valid for both zsh and bash 3.2 (no arrays, every variable quoted). PIXI_VERSION=0.84.2 PIXI_SHA_ARM=039d4b48c7e17bc62a36faa2af1b13d0d187f5dd6e8fea17e0587302438df6e6 # pixi-aarch64-apple-darwin.tar.gz PIXI_SHA_X64=a633a4f8276955b73248397c17ce77380eb7133dc96c54bc271239b7dc9b8837 # pixi-x86_64-apple-darwin.tar.gz ros2lab_try() { set -eu ORIGIN="${ROS2LAB_ORIGIN:-https://www.ros2lab.com}"; TRY="${ROS2LAB_TRY_DIR:-$HOME/ros2lab-try}" CMD="curl -fsSL https://www.ros2lab.com/install/try-mac.sh | zsh" T0=$(date +%s) say() { printf '%s\n' "$*"; } stop() { say ""; say "Stopped: $*"; say "The Browser Lab on www.ros2lab.com needs no install."; exit 1; } dl() { rc=0; curl --proto '=https,http' -fsSL --retry 3 -o "$2" "$1" || rc=$? case "$rc" in 0) return 0;; 5|7) say " Download failed: could not connect${HTTPS_PROXY:+ through the proxy $HTTPS_PROXY}. Try a phone hotspot, or set HTTPS_PROXY to your network's proxy.";; 35|51|58|60|77|83|90|91) say " Download failed: this network inspects secure connections (common at schools and offices). Try a phone hotspot or set HTTPS_PROXY.";; *) say " Download failed ($1, error $rc). Check the internet connection; behind a proxy set HTTPS_PROXY, or try a phone hotspot.";; esac return "$rc" } sha() { shasum -a 256 "$1" | awk '{print $1}'; } say "ROS2Lab - Try ROS 2 on your Mac" say "Checking this Mac..." [ "$(uname -s)" = Darwin ] || stop "this command is for macOS. On Ubuntu use try.sh, on Windows try.ps1 (see the page)." osv=$(sw_vers -productVersion 2>/dev/null || echo 0) say " system: macOS $osv" # pixi assumes macOS 13 unless told and would quietly install older builds: the ROS 2 here needs macOS 14 (Sonoma) [ "${osv%%.*}" -ge 14 ] 2>/dev/null || stop "macOS 14 (Sonoma) or newer is needed; this Mac has $osv. Update macOS (Apple menu, System Settings, General, Software Update) or use the browser missions on www.ros2lab.com: they need no install." say " (OK, needs 14)" # an Apple chip running this terminal under Rosetta still reports x86_64 in uname -m if [ "$(sysctl -n hw.optional.arm64 2>/dev/null || echo 0)" = 1 ]; then chip="Apple chip"; ptar=pixi-aarch64-apple-darwin.tar.gz; psha="$PIXI_SHA_ARM" else chip="Intel"; ptar=pixi-x86_64-apple-darwin.tar.gz; psha="$PIXI_SHA_X64" fi say " processor: $chip" free=$(df -k "$HOME" | awk 'NR==2{printf "%.1f", $4/1048576}'); free="${ROS2LAB_TEST_FREE_GB:-$free}" say " free space: ${free} GB (needs 2 GB)" if [ ! -d "$TRY/.pixi/envs/default" ] && awk -v f="$free" 'BEGIN{exit !(f < 2)}'; then stop "only ${free} GB free; ROS 2 needs 2 GB. Free some space (empty the Trash, delete big downloads) and run the command again." fi ram=$(sysctl -n hw.memsize 2>/dev/null | awk '{printf "%.1f", $1/1073741824}') say " memory: ${ram:-?} GB" if awk -v r="${ram:-0}" 'BEGIN{exit !(r+0 > 0 && r+0 < 4)}'; then say " (less than 4 GB: it works, but close other programs first)"; fi if [ -n "${SSH_CONNECTION:-}" ]; then shown=no; say " screen: none (this is an SSH login): ROS 2 is installed, but the turtle window cannot open" else shown=yes; say " screen: yes (the turtle window can open)"; fi say " folder: $TRY" # the conda `ros2` launcher (#!/bin/sh + exec /python) breaks on a path with a space (tested on Linux: "exec: ... not found") # also the REAL path: pixi resolves symlinks, so a home linked into a folder with a space breaks the same way (seen on Linux in V73) mkdir -p "$TRY" case "$TRY|$(cd "$TRY" && pwd -P)" in *" "*) stop "ROS 2 from this folder cannot run from a path with a space ($(cd "$TRY" && pwd -P)). Pick one without, e.g.: curl -fsSL https://www.ros2lab.com/install/try-mac.sh | ROS2LAB_TRY_DIR=/Users/Shared/ros2lab-try zsh";; esac if [ "$("$TRY/bin/pixi" --version 2>/dev/null || true)" != "pixi $PIXI_VERSION" ]; then say "Getting pixi $PIXI_VERSION (one file, about 30 MB) from github.com/prefix-dev/pixi ..." mkdir -p "$TRY/bin"; dl "https://github.com/prefix-dev/pixi/releases/download/v$PIXI_VERSION/$ptar" "$TRY/pixi.tar.gz" [ "$(sha "$TRY/pixi.tar.gz")" = "$psha" ] || { rm -f "$TRY/pixi.tar.gz"; stop "the pixi download did not match its SHA256 (a broken or changed download)."; } tar -xzf "$TRY/pixi.tar.gz" -C "$TRY/bin" pixi; rm -f "$TRY/pixi.tar.gz" say " pixi checked (SHA256 ok)" fi say "Getting the ROS 2 list (pixi.toml, pixi.lock) from $ORIGIN/install/try/ ..." rm -rf "$TRY/new"; mkdir -p "$TRY/new" if dl "$ORIGIN/install/try/SHA256SUMS" "$TRY/new/SHA256SUMS" && dl "$ORIGIN/install/try/pixi.toml" "$TRY/new/pixi.toml" \ && dl "$ORIGIN/install/try/pixi.lock" "$TRY/new/pixi.lock" && dl "$ORIGIN/install/try/ros2lab-try.py" "$TRY/new/ros2lab-try.py"; then bad=0 for f in pixi.toml pixi.lock ros2lab-try.py; do want=$(awk -v f="$f" '$2==f{print $1}' "$TRY/new/SHA256SUMS") [ -n "$want" ] && [ "$(sha "$TRY/new/$f")" = "$want" ] || bad=1 done [ "$bad" = 0 ] || { rm -rf "$TRY/new"; stop "a downloaded file did not match SHA256SUMS."; } mv -f "$TRY/new/SHA256SUMS" "$TRY/new/pixi.toml" "$TRY/new/pixi.lock" "$TRY/new/ros2lab-try.py" "$TRY/"; say " files checked (SHA256SUMS ok)" elif [ -f "$TRY/pixi.lock" ]; then say " (no internet: using the files from last time)" else rm -rf "$TRY/new"; stop "could not download from $ORIGIN."; fi rm -rf "$TRY/new" # everything pixi keeps goes into the try folder; a ROS 2 or conda already set up in this terminal must not mix in export PIXI_HOME="$TRY/pixi-home" PIXI_CACHE_DIR="$TRY/cache" RATTLER_CACHE_DIR="$TRY/cache" PIXI_NO_PATH_UPDATE=1 # cleared for this run only (~/.zshrc is never edited); ROS_DOMAIN_ID stays (with LOCALHOST discovery nothing leaves this Mac) if [ -n "${ROS_DISTRO:-}${AMENT_PREFIX_PATH:-}${CONDA_PREFIX:-}" ]; then say " OK: a ROS 2 or conda already set up in this terminal is ignored here; nothing in ~/.zshrc changes." fi unset AMENT_PREFIX_PATH CMAKE_PREFIX_PATH COLCON_PREFIX_PATH PYTHONPATH PYTHONHOME DYLD_LIBRARY_PATH ROS_DISTRO ROS_VERSION \ ROS_PYTHON_VERSION ROS_LOCALHOST_ONLY ROS_AUTOMATIC_DISCOVERY_RANGE ROS_ETC_DIR ROS_PACKAGE_PATH RMW_IMPLEMENTATION \ CONDA_PREFIX CONDA_DEFAULT_ENV CONDA_SHLVL CONDA_EXE CONDA_PYTHON_EXE CONDA_PROMPT_MODIFIER VIRTUAL_ENV 2>/dev/null || true say "Installing ROS 2 Jazzy + turtlesim into $TRY (first time: about 290 MB, a few minutes) ..." "$TRY/bin/pixi" install --frozen --manifest-path "$TRY/pixi.toml" say " installed in $(( $(date +%s) - T0 )) s; the folder is $(du -sh "$TRY" | cut -f1)" sh_kind=bash; [ -n "${ZSH_VERSION:-}" ] && sh_kind=zsh hook="$("$TRY/bin/pixi" shell-hook --frozen --shell "$sh_kind" --manifest-path "$TRY/pixi.toml")" set +eu; eval "$hook"; set -eu # conda/ROS activation scripts read unset variables if [ "$shown" = no ]; then say ""; say "Done (no screen, so no turtle window). On the Mac itself run: $CMD"; return 0; fi say "" say "Keep this Terminal open: Ctrl+C here stops the turtle and the bridge." say " Open it again later: $CMD" say " Remove everything: rm -rf $TRY" # the bridge opens the turtle window, prints the pairing code and runs in the foreground (Ctrl+C reaches it directly) rc=0 ROS2LAB_TRY_CMD="$CMD" python -I "$TRY/ros2lab-try.py" --turtlesim