#!/bin/sh # Nomadex worker installer for Linux and macOS (servers, headless boxes, or a Mac without the desktop app). # # curl -fsSL https://nomadex.soolutions.io/install.sh | sh # curl -fsSL https://nomadex.soolutions.io/install.sh | sh -s -- --no-service --no-pair # # Installs (or updates) the self-contained worker into ~/.local/share/nomadex (no root needed), # links ~/.local/bin/nomadex-worker, (re)starts it at login (systemd --user or launchd) and shows # the pairing QR code for the Nomadex iPhone app. See usage() for options and environment. set -eu usage() { # A heredoc, not this file's comments: under `curl … | sh` there is no file to read. cat <<'USAGE' Nomadex worker installer for Linux and macOS (servers, headless boxes, or a Mac without the desktop app). curl -fsSL https://nomadex.soolutions.io/install.sh | sh curl -fsSL https://nomadex.soolutions.io/install.sh | sh -s -- --no-service --no-pair Installs or updates the worker in ~/.local/share/nomadex (no root needed), links ~/.local/bin/nomadex-worker, (re)starts it at login (systemd --user or launchd) and shows the pairing QR code for the Nomadex iPhone app, unless a phone is already paired. Options: --no-service do not install or restart the login service --no-pair do not show the pairing QR code -h, --help show this help Environment: NOMADEX_DOWNLOAD_BASE (default https://nomadex.soolutions.io/dl), NOMADEX_PREFIX, NOMADEX_BIN_DIR, NOMADEX_VERSION (pin a version), NOMADEX_NODE (node binary to use). USAGE } BASE="${NOMADEX_DOWNLOAD_BASE:-https://nomadex.soolutions.io/dl}" PREFIX="${NOMADEX_PREFIX:-$HOME/.local/share/nomadex}" BIN_DIR="${NOMADEX_BIN_DIR:-$HOME/.local/bin}" NODE="${NOMADEX_NODE:-node}" SERVICE=1 PAIR=1 for arg in "$@"; do case "$arg" in --no-service) SERVICE=0 ;; --no-pair) PAIR=0 ;; -h|--help) usage; exit 0 ;; *) printf 'nomadex: unknown option %s\n' "$arg" >&2; exit 2 ;; esac done say() { printf '%s\n' "$*"; } step() { printf '\n\033[1m%s\033[0m\n' "$*"; } fail() { printf '\nnomadex: %s\n' "$*" >&2; exit 1; } have() { command -v "$1" >/dev/null 2>&1; } fetch() { # url dest if have curl; then curl -fsSL --retry 3 -o "$2" "$1" elif have wget; then wget -q -O "$2" "$1" else fail "curl or wget is required"; fi } sha256() { if have sha256sum; then sha256sum "$1" | cut -d' ' -f1 elif have shasum; then shasum -a 256 "$1" | cut -d' ' -f1 else fail "sha256sum or shasum is required"; fi } step "Nomadex worker" case "$(uname -s)" in Linux|Darwin) ;; *) fail "this installer supports Linux and macOS; on Windows use the Nomadex desktop app" ;; esac have "$NODE" || fail "Node.js 20 or newer is required (https://nodejs.org, or your package manager)" NODE_MAJOR=$("$NODE" -p 'process.versions.node.split(".")[0]' 2>/dev/null || echo 0) [ "$NODE_MAJOR" -ge 20 ] 2>/dev/null || fail "Node.js 20 or newer is required (found $("$NODE" --version 2>/dev/null || echo none))" have tar || fail "tar is required" if have claude; then say "Claude Code: $(claude --version 2>/dev/null | head -n1)" else say "Claude Code is not on PATH yet: install it (https://docs.claude.com/claude-code) and log in;" say "the worker starts anyway and picks it up when it appears." fi VERSION="${NOMADEX_VERSION:-}" TMP=$(mktemp -d 2>/dev/null || mktemp -d -t nomadex) trap 'rm -rf "$TMP"' EXIT INT TERM if [ -z "$VERSION" ]; then fetch "$BASE/latest" "$TMP/latest" || fail "cannot reach $BASE" VERSION=$(tr -d ' \r\n' < "$TMP/latest") fi case "$VERSION" in ''|*[!0-9A-Za-z.+-]*) fail "unexpected version string from $BASE/latest" ;; esac ARCHIVE="nomadex-worker-$VERSION.tar.gz" say "Downloading $ARCHIVE" fetch "$BASE/$ARCHIVE" "$TMP/$ARCHIVE" || fail "download failed: $BASE/$ARCHIVE" fetch "$BASE/$ARCHIVE.sha256" "$TMP/$ARCHIVE.sha256" || fail "checksum download failed" EXPECTED=$(cut -d' ' -f1 < "$TMP/$ARCHIVE.sha256") ACTUAL=$(sha256 "$TMP/$ARCHIVE") [ -n "$EXPECTED" ] && [ "$EXPECTED" = "$ACTUAL" ] || fail "checksum mismatch for $ARCHIVE" DEST="$PREFIX/$VERSION" rm -rf "$DEST.tmp" mkdir -p "$DEST.tmp" tar -xzf "$TMP/$ARCHIVE" --no-same-owner -C "$DEST.tmp" rm -rf "$DEST" mv "$DEST.tmp/nomadex-worker" "$DEST" rmdir "$DEST.tmp" 2>/dev/null || true ln -sfn "$DEST" "$PREFIX/current" mkdir -p "$BIN_DIR" ln -sf "$PREFIX/current/nomadex-worker" "$BIN_DIR/nomadex-worker" say "Installed nomadex-worker $VERSION in $DEST" case ":$PATH:" in *":$BIN_DIR:"*) ;; *) # The startup file the user's shell actually reads (zsh ignores ~/.profile; login bash on macOS reads ~/.bash_profile). case "$(basename "${SHELL:-sh}")" in zsh) RC='~/.zshrc' ;; bash) if [ "$(uname -s)" = Darwin ]; then RC='~/.bash_profile'; else RC='~/.bashrc'; fi ;; *) RC='~/.profile' ;; esac if [ "$(basename "${SHELL:-sh}")" = fish ]; then say "Add $BIN_DIR to your PATH: fish_add_path $BIN_DIR" else say "Add $BIN_DIR to your PATH: echo 'export PATH=\"$BIN_DIR:\$PATH\"' >> $RC (then open a new terminal)" fi ;; esac WORKER="$BIN_DIR/nomadex-worker" SERVICE_OK=0 if [ "$SERVICE" = 1 ]; then step "Start at login" if [ "$(uname -s)" = Darwin ] || { have systemctl && systemctl --user show-environment >/dev/null 2>&1; }; then # (Re)starts the service: re-running the installer replaces a worker that is already running. if "$WORKER" service install --yes; then SERVICE_OK=1 if [ "$(uname -s)" = Linux ] && have loginctl; then if [ "$(loginctl show-user "$(id -un)" -p Linger --value 2>/dev/null || echo no)" != yes ]; then loginctl enable-linger "$(id -un)" >/dev/null 2>&1 \ && say "Enabled lingering: the worker keeps running after you log out." \ || say "To keep the worker running after logout: sudo loginctl enable-linger $(id -un)" fi fi else say "Could not install the service; run it in the foreground with: nomadex-worker start" fi else say "No systemd user session here (container or minimal VM). Run the worker with: nomadex-worker start" say "(or under your own supervisor: tmux, screen, a system unit running \"$WORKER start\")" fi fi PAIRED=$("$WORKER" devices list --json 2>/dev/null | grep -c '"pk"' || true) if [ "$PAIR" = 1 ] && [ "${PAIRED:-0}" -gt 0 ] 2>/dev/null; then step "Pair your iPhone" say "Already paired with $PAIRED phone(s): pair another one any time with nomadex-worker pair" PAIR=0 fi if [ "$PAIR" = 1 ]; then step "Pair your iPhone" if [ "$SERVICE_OK" = 1 ]; then # Pair through the service's worker: a second worker with the same key would answer the phone too. i=0 until "$WORKER" status --json 2>/dev/null | grep -q '"running": true'; do i=$((i + 1)) if [ "$i" -ge 20 ]; then say "The worker service is not answering yet (check with: nomadex-worker doctor)."; break; fi sleep 1 done fi say "On the iPhone: Nomadex → Macchine → Abbina una macchina, scan this code (valid 10 minutes)," say "check that the Codice di verifica (verification code) matches the one printed below, then tap Abbina." if (exec /dev/null; then "$WORKER" pair < /dev/tty || say "Pairing did not complete. Retry any time with: nomadex-worker pair" else "$WORKER" pair || say "Pairing did not complete. Retry any time with: nomadex-worker pair" fi fi step "Done" say " nomadex-worker status what the worker sees" say " nomadex-worker doctor check the setup, with a fix for each problem" say " nomadex-worker pair pair another phone" say " nomadex-worker hooks install remote permissions and turn-end prompts for every session (--dry-run first)" say " nomadex-worker update update to the latest version" say " nomadex-worker --help everything else"