Something went wrong. Try again.
Open source agent hosting on the AT Protocol
Something went wrong. Try again.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142#!/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@}"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"
mkdir -p "$(dirname "$APP")" "$BIN" && chmod 700 "$(dirname "$APP")"NEW="$APP.new.$$"OLD="$APP.old.$$"trap 'rm -rf "$NEW" "$NEW.tgz"' EXIT INT TERM
say "downloading languid…"curl -fsSL "$TARBALL" -o "$NEW.tgz" || fail "could not download $TARBALL"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"; fimv "$NEW" "$APP"say "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 rm -rf "$APP" [ -d "$OLD" ] && mv "$OLD" "$APP" fail "installing dependencies failed; nothing changed"firm -rf "$OLD"
CLI_Q=$(sh_quote "$APP/src/cli.ts")printf '#!/bin/sh\nexec node %s "$@"\n' "$CLI_Q" > "$BIN/languid"chmod +x "$BIN/languid"say "installed: $BIN/languid"
# 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