#!/bin/sh # Terminal CLI -- AhoosAI in the terminal, installed for this user. Terminal CLI made by AhoosAI. # # curl -fsSL https://ahoos-ai.site/downloads/cli/install.sh | sh # # On Linux x64 and macOS it installs the built program; elsewhere, or where it cannot run, the script, run by the # python3 already there. Into ~/.local/bin, checked against the published checksum. set -eu base="https://ahoos-ai.site/downloads/cli" bin="${HOME}/.local/bin" mkdir -p "$bin" sums=$(curl -fsSL "$base/SHA256SUMS.txt") case "$(uname -s)-$(uname -m)" in Linux-x86_64) name=$(printf '%s\n' "$sums" | awk '/terminal-cli-[0-9.]+-linux-x64$/ {print $2; exit}') ;; Darwin-arm64) name=$(printf '%s\n' "$sums" | awk '/terminal-cli-[0-9.]+-macos-arm64$/ {print $2; exit}') ;; Darwin-x86_64) name=$(printf '%s\n' "$sums" | awk '/terminal-cli-[0-9.]+-macos-x64$/ {print $2; exit}') ;; *) name="" ;; esac if [ -n "$name" ]; then want=$(printf '%s\n' "$sums" | awk -v n="$name" '$2 == n {print $1}') echo "Downloading $name ..." curl -fsSL "$base/$name" -o "$bin/terminal-cli.part" got=$( (sha256sum "$bin/terminal-cli.part" 2>/dev/null || shasum -a 256 "$bin/terminal-cli.part") | awk '{print $1}') [ "$want" = "$got" ] || { rm -f "$bin/terminal-cli.part"; echo "The download does not match its checksum; nothing was installed." >&2; exit 1; } mv "$bin/terminal-cli.part" "$bin/terminal-cli" chmod +x "$bin/terminal-cli" # A system older than the one it was built on cannot run it: the script, with python3, instead. "$bin/terminal-cli" --version >/dev/null 2>&1 || { echo "The program does not run here; installing the script instead."; rm -f "$bin/terminal-cli"; name=""; } fi if [ -z "$name" ]; then command -v python3 >/dev/null 2>&1 || { echo "Python 3.9 or newer is needed here: https://www.python.org/downloads/" >&2; exit 1; } want=$(printf '%s\n' "$sums" | awk '$2 == "terminal_cli.py" {print $1}') curl -fsSL "$base/terminal_cli.py" -o "$bin/terminal_cli.py.part" got=$( (sha256sum "$bin/terminal_cli.py.part" 2>/dev/null || shasum -a 256 "$bin/terminal_cli.py.part") | awk '{print $1}') [ "$want" = "$got" ] || { rm -f "$bin/terminal_cli.py.part"; echo "The download does not match its checksum." >&2; exit 1; } mv "$bin/terminal_cli.py.part" "$bin/terminal_cli.py" printf '#!/bin/sh\nexec python3 "%s/terminal_cli.py" "$@"\n' "$bin" > "$bin/terminal-cli" chmod +x "$bin/terminal-cli" fi echo "Installed: $bin/terminal-cli" case ":$PATH:" in *":$bin:"*) ;; *) echo "Add $bin to your PATH (for example in ~/.profile)." ;; esac echo "Next: terminal-cli login (a key from https://ahoos-ai.site/services/platforme/)"