#!/usr/bin/env bash install_oscova() { local os arch dotnet sdk version line tool_path temp_dir nuget_config answer distro distro_version original_path configured_root ready=0 local sdk_url='https://builds.dotnet.microsoft.com/dotnet/Sdk/10.0.401/dotnet-sdk-10.0.401-osx-arm64.pkg' local sdk_hash='d431f774f1efa8d3a30acb217d24606160cc85929f9b1075009417ea1ce896db26b01398971d0f9aa8bb96e97b4903b5c50dd1550ef6c5fa97600f40c508ff82' export DOTNET_CLI_TELEMETRY_OPTOUT=1 # The .NET SDK reports usage to Microsoft unless opted out; keep every dotnet call in this install silent. fail() { printf 'Oscova installation incomplete: %s\n' "$*" >&2; return 1; } manual() { printf 'Install the .NET 10 SDK for your computer, then rerun this command: https://learn.microsoft.com/dotnet/core/install/\n' >&2; } checked_dotnet() { local output output=$("$dotnet" "$@") || { fail "dotnet $1 failed."; return 1; } printf '%s\n' "$output" } sdk_ready() { local info sdks runtimes candidate info=$(checked_dotnet --info) || return 1 [[ "$info" =~ Architecture:[[:space:]]*(arm64|x64) ]] || { fail 'Cannot determine the .NET host architecture.'; return 1; } [[ "${BASH_REMATCH[1]}" == "$arch" ]] || { fail "The .NET host is not $arch. Use a native .NET installation."; return 1; } sdks=$(checked_dotnet --list-sdks) || return 1 runtimes=$(checked_dotnet --list-runtimes) || return 1 sdk='' while IFS= read -r line; do if [[ "$line" =~ ^(10\.[0-9]+\.[0-9]+)[[:space:]]+\[ ]]; then candidate="${BASH_REMATCH[1]}" if [[ -z "$sdk" || "$(printf '%s\n%s\n' "$sdk" "$candidate" | sort -t. -k1,1n -k2,2n -k3,3n | tail -n 1)" == "$candidate" ]]; then sdk="$candidate" fi fi done <<< "$sdks" [[ -n "$sdk" ]] || return 1 [[ "$runtimes" =~ Microsoft\.NETCore\.App[[:space:]]+10\.[0-9]+\.[0-9]+[[:space:]] ]] || return 1 [[ "$runtimes" =~ Microsoft\.AspNetCore\.App[[:space:]]+10\.[0-9]+\.[0-9]+[[:space:]] ]] || return 1 } if [[ $(id -u) -eq 0 ]]; then fail 'Run this command in a normal user terminal, without sudo.'; return 1 fi os=$(uname -s) || { fail 'Cannot identify the operating system.'; return 1; } arch=$(uname -m) || { fail 'Cannot identify the CPU architecture.'; return 1; } case "$os:$arch" in Darwin:arm64) if (( $(sw_vers -productVersion | cut -d. -f1) < 15 )); then fail 'macOS 15 or newer is required.'; return 1 fi if [[ $(sysctl -in sysctl.proc_translated 2>/dev/null || true) == 1 ]]; then fail 'Open a native Apple Silicon terminal, then rerun the command.'; return 1 fi dotnet='/usr/local/share/dotnet/dotnet' ;; Darwin:x86_64) if [[ $(sysctl -in hw.optional.arm64 2>/dev/null || true) == 1 ]]; then fail 'Open a native Apple Silicon terminal, then rerun the command.'; return 1 fi if (( $(sw_vers -productVersion | cut -d. -f1) < 15 )); then fail 'macOS 15 or newer is required.'; return 1 fi arch='x64' dotnet='/usr/local/share/dotnet/dotnet' sdk_url='https://builds.dotnet.microsoft.com/dotnet/Sdk/10.0.401/dotnet-sdk-10.0.401-osx-x64.pkg' sdk_hash='b3865a117b5141863dbc97ff7557fcca16acd9761e07cceeb22aada680461ff4c5419a3286c62e22e361796f9ddd96019451c2cd9abe86f6d017b14ee808cab0' ;; Linux:x86_64) arch='x64' if [[ $(getconf GNU_LIBC_VERSION 2>/dev/null) != glibc* ]]; then fail 'This installer requires glibc Linux x64. musl is unsupported.'; return 1 fi dotnet='/usr/bin/dotnet' [[ -x "$dotnet" ]] || dotnet=$(command -v dotnet || true) if [[ -x "$dotnet" ]]; then dotnet=$(readlink -f "$dotnet") || return 1; fi ;; *) fail 'Supported computers are Intel or Apple Silicon macOS 15 or newer and glibc Linux x64.'; return 1 ;; esac if [[ -n "${DOTNET_ROOT:-}" ]]; then configured_root="${DOTNET_ROOT%/}" if [[ "$os" == Linux ]]; then configured_root=$(readlink -f "$configured_root" 2>/dev/null || true); fi if [[ "$configured_root" != "${dotnet%/dotnet}" ]]; then fail "DOTNET_ROOT points to a different .NET installation: $DOTNET_ROOT"; return 1 fi fi if [[ -x "$dotnet" ]] && sdk_ready; then ready=1; fi if [[ "$os" == Linux && "$ready" -eq 0 ]]; then distro=''; distro_version='' if [[ -r /etc/os-release ]]; then . /etc/os-release distro="${ID:-}"; distro_version="${VERSION_ID:-}" fi if [[ "$distro:$distro_version" != ubuntu:24.04 ]]; then manual; fail 'Automatic .NET setup supports Ubuntu 24.04 x64 only.'; return 1 fi fi if [[ "$ready" -eq 0 ]]; then printf 'Oscova needs the .NET 10 SDK. Install it now? [y/N] ' # stdin may contain this script, so consent must come from the terminal. if ! IFS= read -r answer /dev/null || { manual; fail 'The .NET download failed SHA-512 verification.'; return 1; } sudo /usr/sbin/installer -pkg "$temp_dir/dotnet-sdk.pkg" -target / || { manual; fail 'The .NET installer failed or was canceled.'; return 1; } else if [[ "$distro:$distro_version" != ubuntu:24.04 ]]; then manual; fail 'Automatic .NET setup supports Ubuntu 24.04 x64 only.'; return 1 fi printf 'apt will request administrator approval and may ask package questions.\n' sudo apt-get update || { manual; fail 'apt-get update failed.'; return 1; } if [[ ! -r /dev/tty ]]; then manual; fail 'A terminal is required for apt.'; return 1; fi sudo apt-get install dotnet-sdk-10.0 "$temp_dir/global.json" || return 1 nuget_config="$temp_dir/NuGet.Config" printf '%s\n' '' > "$nuget_config" || return 1 cd "$temp_dir" || return 1 local tools_output installed_version='' tools_output=$(checked_dotnet tool list --global) || return 1 while IFS= read -r line; do if [[ "$line" =~ ^[[:space:]]*[Oo]scova\.[Aa]gents\.[Aa]pp[[:space:]] ]]; then if [[ "$line" =~ ^[[:space:]]*[Oo]scova\.[Aa]gents\.[Aa]pp[[:space:]]+([^[:space:]]+)[[:space:]]+oscova[[:space:]]*$ ]]; then installed_version="${BASH_REMATCH[1]}" else fail 'Cannot read the installed Oscova package record safely.'; return 1 fi fi done <<< "$tools_output" if [[ -z "$installed_version" ]]; then "$dotnet" tool install --global Oscova.Agents.App --no-cache --configfile "$nuget_config" || { fail 'NuGet tool installation failed. See the package error above.'; return 1; } else printf 'Oscova %s is already installed for this account. Update instructions: https://oscova.ai/docs/articles/user-guide/getting-started/command-line.html#install\n' "$installed_version" fi tool_path="$HOME/.dotnet/tools/oscova" [[ -x "$tool_path" ]] || { fail "The installed command is missing: $tool_path"; return 1; } version=$("$tool_path" --version) || { fail 'oscova --version failed.'; return 1; } "$tool_path" --help >/dev/null || { fail 'oscova --help failed.'; return 1; } printf 'Oscova %s is ready.\n' "$version" original_path="$PATH" case ":$original_path:" in *":$HOME/.dotnet/tools:"*) ;; *) printf 'To run oscova in this terminal later, run: export PATH="$HOME/.dotnet/tools:$PATH"\nAdd that same line to your chosen shell startup file to keep it available.\n' ;; esac PATH="$HOME/.dotnet/tools:$PATH" if [[ $(command -v oscova || true) != "$tool_path" ]]; then fail "Command lookup does not reach $tool_path. Move $HOME/.dotnet/tools earlier on PATH."; return 1 fi # stdin may contain this script, so the started app reads the terminal instead. if [[ -t 1 ]] && { : /dev/null; then printf 'Starting Oscova. Next time, run: oscova start\n' cd "$HOME" || return 1 rm -rf -- "$temp_dir" trap - EXIT exec "$tool_path" start --detach