#!/usr/bin/env bash # PlaysmithAI installer for macOS (runs with the bash 3.2 that macOS ships). # # curl -fsSL https:///install.sh | bash # # With options: # curl -fsSL https:///install.sh | bash -s -- --update # or: export PLAYSMITHAI_ARGS="--update" before the one-liner. # # It checks for Node.js 24+, Git and pnpm and offers to install what is missing with Homebrew, then downloads # installer.mjs from the site and runs it. installer.mjs asks for your license key and installs the Studio into # ~/PlaysmithAI/studio. The install docs on the website list every option. # The website this script downloads installer.mjs from, set before release. PLAYSMITHAI_SITE or # --site overrides it. While it still holds the __PLAYSMITHAI_ token, the script downloads nothing. PLAYSMITHAI_DEFAULT_SITE="https://playsmithai.com" GF_TMP="" say() { printf '%s\n' "$*"; } step() { printf '\n==> %s\n' "$*"; } # Everything runs inside main(), called on the last line, so a download cut off halfway runs nothing. main() { set -u trap 'if [ -n "${GF_TMP:-}" ]; then rm -rf "$GF_TMP"; fi' EXIT local site="${PLAYSMITHAI_SITE:-$PLAYSMITHAI_DEFAULT_SITE}" local local_mjs="" GF_YES=0 local pass=() while [ $# -gt 0 ]; do case "$1" in --local) if [ $# -lt 2 ]; then say "--local needs the path of installer.mjs"; return 2; fi local_mjs="$2"; shift 2 ;; --local=*) local_mjs="${1#--local=}"; shift ;; --site) if [ $# -lt 2 ]; then say "--site needs a URL"; return 2; fi site="$2"; shift 2 ;; --site=*) site="${1#--site=}"; shift ;; --yes|-y) GF_YES=1; pass+=("--yes"); shift ;; *) pass+=("$1"); shift ;; esac done if [ -n "${PLAYSMITHAI_ARGS:-}" ]; then local a set -f for a in $PLAYSMITHAI_ARGS; do case "$a" in --yes|-y) GF_YES=1 ;; esac pass+=("$a") done set +f fi # Keep the key out of the Node child's argv, including options supplied through PLAYSMITHAI_ARGS. local child_key="${PLAYSMITHAI_KEY:-}" filtered=() i=0 while [ "$i" -lt "${#pass[@]}" ]; do case "${pass[$i]}" in --key) i=$((i + 1)) if [ "$i" -ge "${#pass[@]}" ] || [[ "${pass[$i]}" == --* ]]; then say "--key needs a value"; return 2; fi child_key="${pass[$i]}" ;; --key=*) child_key="${pass[$i]#--key=}" ;; *) filtered+=("${pass[$i]}") ;; esac i=$((i + 1)) done pass=(${filtered[@]+"${filtered[@]}"}) site="${site%/}" local site_set=1 case "$site" in __PLAYSMITHAI_*) site_set=0 ;; esac local os os="$(uname -s 2>/dev/null || echo unknown)" say "PlaysmithAI installer for macOS" say "Claude is recommended: your Claude Code sign-in (Claude Pro or Max) or Anthropic API key. Other providers are configurable." if [ "$os" = "Darwin" ]; then local mac_version mac_version="$(sw_vers -productVersion 2>/dev/null || true)" if ! macos_supported "$mac_version"; then say "macOS 13.5 or newer is required by Node.js 24 (Intel or Apple Silicon). Update macOS, then run this again." return 1 fi fi if [ "$os" != "Darwin" ]; then say "" say "This script is made for macOS; this system reports $os." case "$os" in MINGW*|MSYS*|CYGWIN*) say "On Windows, use the PowerShell install command from the PlaysmithAI website instead." ;; esac say "It continues only if Node.js 24+, Git and pnpm are already installed, and nothing is installed for you." fi step "Node.js 24 or later" local major major="$(node_major)" if [ "$major" -ge 24 ] 2>/dev/null; then say "found Node.js $(node -v)" else if [ "$major" -gt 0 ] 2>/dev/null; then say "found Node.js $major, which is too old"; else say "not found"; fi if need_brew "Node.js" "$os" && confirm "Install Node.js 24 with Homebrew (brew install node@24)? A Node.js you already have stays as it is."; then if ! "$GF_BREW" install node@24 /dev/null 2>&1; then "$GF_BREW" link --force node@24 >/dev/null 2>&1 || true fi PATH="$keg/bin:$PATH"; export PATH hash -r major="$(node_major)" fi if ! [ "$major" -ge 24 ] 2>/dev/null; then say "Node.js 24 or later is needed. Install it from https://nodejs.org (or: brew install node@24), then run this again." return 1 fi say "using Node.js $(node -v)" fi step "Git" if git_ok "$os"; then say "found $(git --version)" else say "not found" if need_brew "Git" "$os" && confirm "Install Git with Homebrew (brew install git)?"; then "$GF_BREW" install git /dev/null 2>&1 && pnpm --version >/dev/null 2>&1; then say "found pnpm $(pnpm --version)" else say "not found" if ! confirm "Set up pnpm now (corepack enable pnpm, or npm install -g pnpm)?"; then say "Install pnpm (npm install -g pnpm, or see https://pnpm.io/installation), then run this again." return 1 fi if command -v corepack >/dev/null 2>&1 && corepack enable pnpm /dev/null 2>&1 && hash -r && pnpm --version >/dev/null 2>&1; then say "enabled pnpm $(pnpm --version) with corepack" elif npm install -g pnpm /dev/null 2>&1; then say "installed pnpm $(pnpm --version) with npm" else say "pnpm could not be set up. Install it (npm install -g pnpm, or see https://pnpm.io/installation), then run this again." return 1 fi fi step "PlaysmithAI installer" GF_TMP="$(mktemp -d 2>/dev/null || mktemp -d -t playsmithai)" local mjs if [ -n "$local_mjs" ]; then mjs="$local_mjs" say "using $mjs (--local)" else if [ "$site_set" = 0 ]; then say "This copy of install.sh has no website address in it, so it cannot download the installer." say "Copy the install command from the PlaysmithAI website again, or pass --site https://." return 1 fi local protocols='=https' local loopback_re='^http://(localhost|127[.]0[.]0[.]1|\[::1\])(:[0-9]+)?(/|$)' if [[ "$site" =~ $loopback_re ]]; then protocols='=http,https'; fi mjs="$GF_TMP/installer.mjs" say "downloading $site/installer.mjs" if ! curl --proto "$protocols" --proto-redir '=https' --tlsv1.2 -fsSL "$site/installer.mjs" -o "$mjs"; then say "The download failed. Check your internet connection and try again." return 1 fi fi if [ "$site_set" = 1 ]; then pass=(--site "$site" ${pass[@]+"${pass[@]}"}); fi # Node's fetch goes through the proxy in HTTPS_PROXY / NO_PROXY only when told to (Node 24+). NODE_USE_ENV_PROXY=1; export NODE_USE_ENV_PROXY # Piped through bash, this script's stdin is the download, so installer.mjs reads the keyboard from /dev/tty. local code=0 if [ -t 0 ]; then PLAYSMITHAI_KEY="$child_key" node "$mjs" ${pass[@]+"${pass[@]}"} || code=$? elif (exec /dev/null; then PLAYSMITHAI_KEY="$child_key" node "$mjs" ${pass[@]+"${pass[@]}"} /dev/tty && read -r answer /dev/null; then say "$1 no (no keyboard attached; pass --yes to answer yes)" return 1 fi case "$answer" in y|Y|yes|YES|Yes) return 0 ;; esac return 1 } node_major() { if ! command -v node >/dev/null 2>&1; then echo 0; return; fi node -p 'process.versions.node.split(".")[0]' 2>/dev/null || echo 0 } macos_supported() { local version="$1" major minor rest case "$version" in ''|*[!0-9.]*) return 1 ;; esac case "$version" in *.*) ;; *) return 1 ;; esac major="${version%%.*}"; rest="${version#*.}"; minor="${rest%%.*}" [ -n "$major" ] && [ -n "$minor" ] || return 1 [ "$major" -ge 14 ] || { [ "$major" -eq 13 ] && [ "$minor" -ge 5 ]; } } git_ok() { local g g="$(command -v git 2>/dev/null)" || return 1 # On a Mac without the Command Line Tools, /usr/bin/git is a stub that opens an install dialog. if [ "$1" = "Darwin" ] && [ "$g" = "/usr/bin/git" ]; then xcode-select -p >/dev/null 2>&1 return $? fi return 0 } GF_BREW="" find_brew() { GF_BREW="" if command -v brew >/dev/null 2>&1; then GF_BREW="$(command -v brew)" elif [ -x /opt/homebrew/bin/brew ]; then GF_BREW=/opt/homebrew/bin/brew elif [ -x /usr/local/bin/brew ]; then GF_BREW=/usr/local/bin/brew fi if [ -n "$GF_BREW" ]; then eval "$("$GF_BREW" shellenv)"; fi } # need_brew : makes sure Homebrew is there (offering to install it) on macOS. need_brew() { [ "$2" = "Darwin" ] || return 1 find_brew if [ -n "$GF_BREW" ]; then return 0; fi say "Homebrew (https://brew.sh) installs $1 on a Mac, and it is not installed." confirm "Install Homebrew now? It asks for your Mac password." || return 1 local input=/dev/null if (exec /dev/null; then input=/dev/tty; fi if [ "${GF_YES:-0}" = 1 ]; then NONINTERACTIVE=1 /bin/bash -c "$(curl --proto '=https' --proto-redir '=https' --tlsv1.2 -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)" <"$input" || return 1 else /bin/bash -c "$(curl --proto '=https' --proto-redir '=https' --tlsv1.2 -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)" <"$input" || return 1 fi find_brew [ -n "$GF_BREW" ] } main "$@" exit $?