#!/usr/bin/env bash # ROS2Lab - Try ROS 2 on your PC (Ubuntu 22.04 / 24.04 on x86_64; other Linux: it tries, and says so). # # curl -fsSL https://www.ros2lab.com/install/try.sh | bash # (no curl: wget -qO- https://www.ros2lab.com/install/try.sh | bash) # # STATUS: tested on Ubuntu 24.04; Windows and macOS not yet run on a real machine. # 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 PC (system, glibc >= 2.34, processor type, 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 335 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 opens the turtlesim window, # connects OUT to the ROS2Lab relay (no port is opened on this PC) and opens your browser at www.ros2lab.com/pc with a # secret link (it also prints a short code for another browser). The page can then run ros2 commands for turtlesim here # (node/topic/service/param/action/interface/pkg/doctor/bag), checked word by word on THIS PC, never through a shell. # Log: ~/ros2lab-try/bridge.log. 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 "Ubuntu 24.04 PC" (never your computer's name or files). Ctrl+C deletes it all from the relay. # Where it writes: ONLY ~/ros2lab-try (pixi, its cache and the ROS 2 files are all in there). No sudo, no password, no # change to ~/.bashrc, PATH or /opt/ros. A ROS 2 you installed with apt (/opt/ros/jazzy) is not touched or used. # 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. # Ctrl+C stops the turtle and the helper. set -euo pipefail PIXI_VERSION=0.84.2 PIXI_SHA256=6d2a576bde0a7b26533a068fec0aea6e4ee21c36668efc1dc73fce90110906ae # pixi-x86_64-unknown-linux-musl.tar.gz main() { local ORIGIN="${ROS2LAB_ORIGIN:-https://www.ros2lab.com}" TRY="${ROS2LAB_TRY_DIR:-$HOME/ros2lab-try}" T0 os arch ram free shown local CMD="curl -fsSL https://www.ros2lab.com/install/try.sh | bash" T0=$(date +%s) say() { printf '%s\n' "$*"; } stop() { say ""; say "Stopped: $*"; say "The Browser Lab on www.ros2lab.com needs no install."; exit 1; } say "ROS2Lab - Try ROS 2 on your PC" say "Checking this PC..." os="$(uname -s)"; arch="$(uname -m)" case "$os" in MINGW*|MSYS*|CYGWIN*) stop "this is Git Bash on Windows. Open PowerShell instead (Start menu, type PowerShell) and paste: powershell -ExecutionPolicy Bypass -c \"irm https://www.ros2lab.com/install/try.ps1 | iex\"";; esac # shellcheck source=/dev/null if [ -r /etc/os-release ]; then os="$(. /etc/os-release && printf '%s' "${PRETTY_NAME:-$os}")"; fi say " system: $os" [ "$(uname -s)" = Linux ] || stop "this command is for Linux. On a Mac use try-mac.sh, on Windows try.ps1 (see the page)." case "$os" in *"Ubuntu 22.04"*|*"Ubuntu 24.04"*) ;; *) say " (tested on Ubuntu 24.04; this system is not, so it tries anyway)";; esac # the ROS 2 packages need glibc 2.34 or newer (Ubuntu 22.04+); Ubuntu 20.04 has 2.31 glibc="${ROS2LAB_TEST_GLIBC:-$(getconf GNU_LIBC_VERSION 2>/dev/null | awk '{print $2}')}" if [ -n "$glibc" ]; then if [ "$(printf '%s\n2.34\n' "$glibc" | sort -V | head -n1)" != 2.34 ]; then stop "this Linux is too old for these ROS 2 packages (glibc $glibc; they need 2.34, which is Ubuntu 22.04 or newer). Use the browser missions on www.ros2lab.com instead: they need no install." fi say " glibc: $glibc (OK, needs 2.34)" fi say " processor: $arch" [ "$arch" = x86_64 ] || stop "the ROS 2 packages here are for x86_64 (Intel/AMD) Linux; this PC is $arch." mkdir -p "$(dirname "$TRY")" 2>/dev/null || true free=$(df -Pk "$(dirname "$TRY")" | awk 'NR==2{printf "%.1f", $4/1048576}'); free="${ROS2LAB_TEST_FREE_GB:-$free}" say " free space: ${free} GB in $(dirname "$TRY") (needs 2 GB)" if [ ! -d "$TRY/.pixi/envs/default" ] && awk -v f="$free" 'BEGIN{exit !(f < 2)}'; then stop "only ${free} GB free in $(dirname "$TRY"); ROS 2 needs 2 GB. Free some space (empty the Trash, delete big downloads) or install somewhere else: curl -fsSL https://www.ros2lab.com/install/try.sh | ROS2LAB_TRY_DIR=/path/with/space/ros2lab-try bash" fi ram=$(awk '/^MemTotal/{printf "%.1f", $2/1048576}' /proc/meminfo 2>/dev/null || echo "?") say " memory: ${ram} GB" if awk -v r="$ram" 'BEGIN{exit !(r+0 > 0 && r+0 < 4)}'; then say " (less than 4 GB: it works, but close other programs first)"; fi if [ -n "${DISPLAY:-}${WAYLAND_DISPLAY:-}" ]; then shown=yes; say " screen: yes (the turtle window can open)" else shown=no; say " screen: none in this terminal (SSH or a server): ROS 2 is installed, but the turtle window cannot open"; fi say " folder: $TRY" # the conda `ros2` launcher (#!/bin/sh + exec /python) breaks on a path with a space (tested: "exec: ... not found") # also the REAL path: pixi resolves symlinks, so a home linked to e.g. "/media/me/New Volume" breaks the same way (seen 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.sh | ROS2LAB_TRY_DIR=/tmp/ros2lab-try bash";; esac # curl or wget, whichever this PC has; a failed download says why in plain English (proxy, school/office SSL inspection) dl() { local rc=0 if command -v curl >/dev/null 2>&1; then curl --proto '=https,http' -fsSL --retry 3 -o "$2" "$1" || rc=$? elif command -v wget >/dev/null 2>&1; then wget -q --tries=3 -O "$2" "$1" || rc=$? else stop "this PC has neither curl nor wget, so nothing can be downloaded."; fi 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" } sum() { sha256sum "$1" | awk '{print $1}'; } if [ "$("$TRY/bin/pixi" --version 2>/dev/null || true)" != "pixi $PIXI_VERSION" ]; then say "Getting pixi $PIXI_VERSION (one file, 33 MB) from github.com/prefix-dev/pixi ..." mkdir -p "$TRY/bin"; dl "https://github.com/prefix-dev/pixi/releases/download/v$PIXI_VERSION/pixi-x86_64-unknown-linux-musl.tar.gz" "$TRY/pixi.tar.gz" [ "$(sum "$TRY/pixi.tar.gz")" = "$PIXI_SHA256" ] || { 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 (cd "$TRY/new" && sha256sum --quiet -c SHA256SUMS) || { rm -rf "$TRY/new"; stop "a downloaded file did not match SHA256SUMS."; } mv -f "$TRY/new/"* "$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 sourced in this terminal (apt) 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 # a ROS 2 sourced from /opt/ros or an active conda would mix in: cleared for this run only (~/.bashrc is never edited). # ROS_DOMAIN_ID stays: it only picks the channel, and with ROS_AUTOMATIC_DISCOVERY_RANGE=LOCALHOST nothing leaves this PC. if [ -n "${ROS_DISTRO:-}${AMENT_PREFIX_PATH:-}${CONDA_PREFIX:-}" ]; then say " OK: the ROS 2 or conda already set up in this terminal is ignored here; nothing in ~/.bashrc changes." fi for v in $(compgen -v | grep -E '^(ROS_|RMW_|CONDA|AMENT_|COLCON_)' | grep -vx ROS_DOMAIN_ID); do unset "$v"; done unset CMAKE_PREFIX_PATH PYTHONPATH PYTHONHOME LD_LIBRARY_PATH VIRTUAL_ENV || true say "Installing ROS 2 Jazzy + turtlesim into $TRY (first time: about 335 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)" local hook; hook="$("$TRY/bin/pixi" shell-hook --frozen --shell bash --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). Open a desktop session and run: $CMD"; return 0; fi # Ubuntu's Wayland desktop also offers X11 (XWayland); the Qt in this folder draws through X11 [ -n "${DISPLAY:-}" ] && export QT_QPA_PLATFORM="${QT_QPA_PLATFORM:-xcb}" 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) local rc=0 ROS2LAB_TRY_CMD="$CMD" python -I "$TRY/ros2lab-try.py" --turtlesim