Something went wrong. Try again.
Open source agent hosting on the AT Protocol
Something went wrong. Try again.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168#!/bin/sh# Installs the languid CLI, or updates it: curl -fsSL https://languid.ai/install | sh## Needs Node 22.18 or newer, curl and tar. No git, no pnpm: the code comes as a tarball, and# the pinned pnpm runs through npx. The code goes in ~/.languid/app, a `languid` command in# ~/.local/bin. Running it again updates both. Then, on a first install from a terminal, it# signs you in (LANGUID_NO_LOGIN=1 skips that).## The service fills in @SERVICE@ and @TARBALL@ when it serves this file.set -eu
SERVICE="${LANGUID_SERVER:-@SERVICE@}"TARBALL="${LANGUID_TARBALL:-@TARBALL@}"RELEASE_VERSION="${LANGUID_RELEASE_VERSION:-@VERSION@}"RELEASE_REVISION="${LANGUID_RELEASE_REVISION:-@REVISION@}"RELEASE_SHA256="${LANGUID_RELEASE_SHA256:-@SHA256@}"APP="${LANGUID_APP_DIR:-$HOME/.languid/app}"BIN="${LANGUID_BIN_DIR:-$HOME/.local/bin}"
say() { printf '%s\n' "$@"; }fail() { printf 'languid install: %s\n' "$*" >&2; exit 1; }sh_quote() { _sq_in=$1 _sq_out="'" while :; do case "$_sq_in" in *"'"*) _sq_out="$_sq_out${_sq_in%%"'"*}'\\''" _sq_in=${_sq_in#*"'"} ;; *) _sq_out="$_sq_out$_sq_in'" break ;; esac done printf '%s' "$_sq_out"}
[ -n "$APP" ] && [ -n "$BIN" ] || fail "install paths cannot be empty"nl=''cr=$(printf '\r')for p in "$APP" "$BIN"; do case "$p" in *"$nl"*|*"$cr"*) fail "install paths cannot contain newlines or carriage returns" ;; esacdone
command -v curl >/dev/null 2>&1 || fail "needs curl"command -v tar >/dev/null 2>&1 || fail "needs tar"command -v node >/dev/null 2>&1 || fail "needs Node 22.18 or newer: https://nodejs.org"command -v npx >/dev/null 2>&1 || fail "needs npx, which comes with Node: https://nodejs.org"node -e 'const [a, b] = process.versions.node.split(".").map(Number); process.exit(a > 22 || (a === 22 && b >= 18) ? 0 : 1)' || fail "needs Node 22.18 or newer (this is $(node --version)): https://nodejs.org"
node -e 'const [v,r,s]=process.argv.slice(1);if(!/^(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)$/.test(v)||!/^[a-f0-9]{40}$/.test(r)||!/^[a-f0-9]{64}$/.test(s))process.exit(1)' "$RELEASE_VERSION" "$RELEASE_REVISION" "$RELEASE_SHA256" || fail "missing or invalid versioned release metadata"mkdir -p "$(dirname "$APP")" "$BIN" && chmod 700 "$(dirname "$APP")"LOCK="$APP.install.lock"mkdir "$LOCK" 2>/dev/null || fail "another installer is running (lock: $LOCK)"NEW="$APP.new.$$"OLD="$APP.old.$$"SWAPPED=COMMITTED=cleanup() { result=$? trap - EXIT INT TERM if [ -n "$SWAPPED" ] && [ -z "$COMMITTED" ]; then rm -rf "$APP" if [ -d "$OLD" ]; then mv "$OLD" "$APP"; fi fi rm -rf "$NEW" "$NEW.tgz" "$BIN/.languid.new.$$" rmdir "$LOCK" 2>/dev/null || true exit "$result"}trap cleanup EXITtrap 'exit 130' INTtrap 'exit 143' TERM
say "downloading languid…"curl -fsSL "$TARBALL" -o "$NEW.tgz" || fail "could not download $TARBALL"node -e 'const fs=require("node:fs"),c=require("node:crypto");const [f,expected]=process.argv.slice(1);if(c.createHash("sha256").update(fs.readFileSync(f)).digest("hex")!==expected)process.exit(1)' "$NEW.tgz" "$RELEASE_SHA256" || fail "release checksum mismatch; nothing changed"mkdir "$NEW"tar -xzf "$NEW.tgz" -C "$NEW" --strip-components=1 || fail "could not unpack $TARBALL"[ -f "$NEW/src/cli.ts" ] || fail "$TARBALL doesn't look like languid"
# Swap it in before installing: pnpm writes absolute paths into node_modules/.bin.first=yesif [ -d "$APP" ]; then first=; mv "$APP" "$OLD"; SWAPPED=yes; fimv "$NEW" "$APP"SWAPPED=yessay "installing its dependencies…"if ! (cd "$APP" && NPM_CONFIG_UPDATE_NOTIFIER=false npx --yes "pnpm@$(node -p 'require("./package.json").packageManager.split("@")[1]')" install --frozen-lockfile --reporter=silent); then fail "installing dependencies failed; restoring the previous installation"finode -e 'const fs=require("node:fs"),path=require("node:path");const [app,version,revision,sha256,service,binDir]=process.argv.slice(1);fs.writeFileSync(path.join(app,"client-install.json"),JSON.stringify({version,revision,sha256,service,binDir:path.resolve(binDir)})+"\n",{mode:0o600})' "$APP" "$RELEASE_VERSION" "$RELEASE_REVISION" "$RELEASE_SHA256" "$SERVICE" "$BIN"
CLI_Q=$(sh_quote "$APP/src/cli.ts")printf '#!/bin/sh\nexec node %s "$@"\n' "$CLI_Q" > "$BIN/.languid.new.$$"chmod +x "$BIN/.languid.new.$$"mv "$BIN/.languid.new.$$" "$BIN/languid"# marshell: the same command, by another name.ln -sf languid "$BIN/marshell"COMMITTED=yesrm -rf "$OLD"say "installed languid $RELEASE_VERSION: $BIN/languid (and $BIN/marshell)"
# A computer set up from this install keeps running the old code until its runner restarts.if [ -z "$first" ]; then if [ "$(uname)" = Darwin ]; then # Languid.app runs the runners set up with it; restarting it restarts them all. if grep -qsF -- "$APP/src/cli.ts" "$HOME/Library/Application Support/Languid/runners/"*.json && launchctl kickstart -k "gui/$(id -u)/ai.languid.app" >/dev/null 2>&1; then say "restarted Languid.app's runners" fi for label in $(launchctl list 2>/dev/null | awk '$3 ~ /^ai\.languid\.runner/ { print $3 }'); do launchctl print "gui/$(id -u)/$label" 2>/dev/null | grep -qF -- "$APP/src/cli.ts" && launchctl kickstart -k "gui/$(id -u)/$label" >/dev/null 2>&1 && say "restarted this computer's runner ($label)" done elif command -v systemctl >/dev/null 2>&1; then for unit in $(systemctl --user list-units --plain --no-legend 'languid-runner*' 2>/dev/null | awk '{ print $1 }'); do systemctl --user cat "$unit" 2>/dev/null | grep -qF -- "$APP/src/cli.ts" && systemctl --user restart "$unit" && say "restarted this computer's runner ($unit)" done # The tray (src/tray.ts) runs the old code until it restarts too. if pkill -f "$APP/src/cli.ts computer tray" 2>/dev/null && { [ -n "${DISPLAY:-}" ] || [ -n "${WAYLAND_DISPLAY:-}" ]; }; then sleep 1 log="${XDG_STATE_HOME:-$HOME/.local/state}/languid/tray.log" mkdir -p "$(dirname "$log")" (cd && nohup node "$APP/src/cli.ts" computer tray >>"$log" 2>&1 &) && say "restarted the Languid tray" fi fifi
# Put ~/.local/bin on PATH for new shells, once.BIN_Q=$(sh_quote "$BIN")case ":$PATH:" in *":$BIN:"*) onpath=yes ;; *) onpath= case "${SHELL:-}" in */zsh) rc="$HOME/.zshrc" ;; */bash) [ "$(uname)" = Darwin ] && rc="$HOME/.bash_profile" || rc="$HOME/.bashrc" ;; *) rc="$HOME/.profile" ;; esac line="export PATH=$BIN_Q:\"\$PATH\" # languid" if ! grep -qsF -- "$line" "$rc"; then printf '\n%s\n' "$line" >> "$rc" say "added $BIN to PATH in $rc" fi ;;esac
newshell=[ -n "$onpath" ] || newshell="open a new terminal (or run: export PATH=$BIN_Q:\"\$PATH\"), then "if [ -z "$first" ]; then say "updated"elif [ -z "${LANGUID_NO_LOGIN:-}" ] && [ -t 1 ] && (: </dev/tty) 2>/dev/null; then say "" if "$BIN/languid" login --url "$SERVICE" </dev/tty; then say "" "${newshell}run: languid" else say "" "${newshell}sign in with: languid login" fielse say "" "${newshell}sign in with: languid login"fi