Compare commits

..

9 Commits

2 changed files with 387 additions and 8 deletions

View File

@@ -40,7 +40,6 @@ Packaged Tauri builds launch the bundled backend with app-managed data paths so
Requirements:
- Python 3.13
- Ollama running locally
- Optional: SearXNG on `http://127.0.0.1:8888`
@@ -50,7 +49,17 @@ Quick start:
./run.sh
```
This creates or refreshes `backend/.venv`, installs Python dependencies, installs npm dependencies, and starts the dev stack. If Node.js 18+ and npm are missing, `run.sh` downloads the current Node.js 22 LTS binary for Linux or macOS into the user cache and verifies its SHA-256 checksum. Set `HEIMGEIST_NODE_MAJOR` or `HEIMGEIST_NODE_DIR` to override that bootstrap.
This bootstraps the development environment and starts the dev stack. On a fresh machine it installs:
- the native Tauri prerequisites through `pacman` on Arch/SteamOS or `apt-get` on Debian/Ubuntu
- stable Rust and Cargo through `rustup`
- Python 3.13 through `uv`
- Node.js 22 LTS and npm from the official Node.js binaries
- the project's Python and npm dependencies
SteamOS temporarily requires a writable root filesystem while native packages are installed. `run.sh` disables the read-only mode only around `pacman`, restores it afterward, and may ask for the user's sudo password. It also initializes and populates the SteamOS pacman keyring before installing packages, because a fresh or updated Steam Deck can otherwise reject valid packages with "unknown trust" / PGP signature errors. If that keyring repair is still insufficient and SteamOS provides `steamos-devmode`, `run.sh` uses it as a final SteamOS bootstrap fallback. Set `HEIMGEIST_STEAMOS_DEVMODE=0` to skip that fallback. SteamOS system updates can remove manually installed system packages; rerunning `./run.sh` restores any missing prerequisites.
Downloads and package installation are skipped when usable dependencies already exist. Node.js archives are verified with their published SHA-256 checksum. Use `HEIMGEIST_BOOTSTRAP_ONLY=1 ./run.sh` to install/check dependencies without launching Heimgeist, or `HEIMGEIST_SKIP_SYSTEM_DEPS=1 ./run.sh` when native Tauri dependencies are managed externally. If the package manager succeeds but the native dependency preflight still cannot verify a `pkg-config` module, `run.sh` prints a preflight report and continues so the real Tauri build can produce the authoritative compiler/linker error. Set `HEIMGEIST_STRICT_SYSTEM_DEPS=1` to make that preflight warning fatal. `HEIMGEIST_NODE_MAJOR`, `HEIMGEIST_NODE_DIR`, `HEIMGEIST_TOOL_BIN_DIR`, `CARGO_HOME`, `RUSTUP_HOME`, `PYTHON_BIN`, `HEIMGEIST_STEAMOS_DEVMODE`, and `HEIMGEIST_STRICT_SYSTEM_DEPS` provide explicit runtime overrides.
On Linux `x86_64`, `run.sh` now selects a PyTorch flavor before installing `openai-whisper`:

382
run.sh
View File

@@ -4,6 +4,10 @@ set -eu
SCRIPT_DIR="$(CDPATH= cd "$(dirname "$0")" && pwd)"
cd "$SCRIPT_DIR"
PYTHON_BIN_WAS_SET=0
if [ -n "${PYTHON_BIN:-}" ]; then
PYTHON_BIN_WAS_SET=1
fi
PYTHON_BIN="${PYTHON_BIN:-python3.13}"
VENV_DIR="backend/.venv"
TORCH_FLAVOR_FILE="$VENV_DIR/.heimgeist-torch-flavor"
@@ -12,9 +16,280 @@ PYTHON_DEPS_STATE_FILE="$VENV_DIR/.heimgeist-python-deps-state"
NODE_DEPS_STATE_FILE="node_modules/.heimgeist-node-deps-state"
HEIMGEIST_NODE_MAJOR="${HEIMGEIST_NODE_MAJOR:-22}"
HEIMGEIST_NODE_DIR="${HEIMGEIST_NODE_DIR:-${XDG_CACHE_HOME:-$HOME/.cache}/heimgeist/node-v$HEIMGEIST_NODE_MAJOR}"
HEIMGEIST_TOOL_BIN_DIR="${HEIMGEIST_TOOL_BIN_DIR:-$HOME/.local/bin}"
HEIMGEIST_SKIP_SYSTEM_DEPS="${HEIMGEIST_SKIP_SYSTEM_DEPS:-0}"
HEIMGEIST_STRICT_SYSTEM_DEPS="${HEIMGEIST_STRICT_SYSTEM_DEPS:-0}"
HEIMGEIST_BOOTSTRAP_ONLY="${HEIMGEIST_BOOTSTRAP_ONLY:-0}"
HEIMGEIST_STEAMOS_DEVMODE="${HEIMGEIST_STEAMOS_DEVMODE:-auto}"
HEIMGEIST_TORCH_FLAVOR="${HEIMGEIST_TORCH_FLAVOR:-auto}"
HEIMGEIST_TORCH_INDEX_URL="${HEIMGEIST_TORCH_INDEX_URL:-}"
HEIMGEIST_FORCE_BOOTSTRAP="${HEIMGEIST_FORCE_BOOTSTRAP:-0}"
CARGO_HOME="${CARGO_HOME:-$HOME/.cargo}"
RUSTUP_HOME="${RUSTUP_HOME:-$HOME/.rustup}"
PATH="$HEIMGEIST_TOOL_BIN_DIR:$CARGO_HOME/bin:$PATH"
export CARGO_HOME RUSTUP_HOME PATH
as_root() {
if [ "$(id -u)" -eq 0 ]; then
"$@"
return
fi
if ! command -v sudo >/dev/null 2>&1; then
echo "Installing native build dependencies requires root access, but sudo is unavailable." >&2
exit 1
fi
if ! sudo -v; then
if is_steamos; then
echo "SteamOS needs a local user password for sudo. Run 'passwd', then rerun ./run.sh." >&2
fi
exit 1
fi
sudo "$@"
}
is_steamos() {
[ -r /etc/os-release ] \
&& grep -Eiq '(^ID=steamos$|^NAME=.*SteamOS|^PRETTY_NAME=.*SteamOS)' /etc/os-release
}
linux_native_deps_usable() {
command -v cc >/dev/null 2>&1 \
&& command -v file >/dev/null 2>&1 \
&& command -v pkg-config >/dev/null 2>&1 \
&& pkg-config --exists webkit2gtk-4.1 gtk+-3.0 openssl librsvg-2.0
}
print_native_dependency_report() {
echo "Native dependency preflight report:" >&2
for command_name in cc file pkg-config; do
if command -v "$command_name" >/dev/null 2>&1; then
echo " ok: command '$command_name' -> $(command -v "$command_name")" >&2
else
echo " missing: command '$command_name'" >&2
fi
done
if ! command -v pkg-config >/dev/null 2>&1; then
return
fi
for pkg_config_name in webkit2gtk-4.1 gtk+-3.0 openssl librsvg-2.0; do
if pkg-config --exists "$pkg_config_name"; then
pkg_config_version="$(pkg-config --modversion "$pkg_config_name" 2>/dev/null || true)"
echo " ok: pkg-config '$pkg_config_name' ${pkg_config_version}" >&2
else
echo " missing: pkg-config '$pkg_config_name'" >&2
fi
done
}
handle_incomplete_native_dependencies() {
echo "The native Tauri dependency preflight is still incomplete after package installation." >&2
print_native_dependency_report
if [ "$HEIMGEIST_STRICT_SYSTEM_DEPS" = "1" ]; then
exit 1
fi
echo "Continuing because the package manager reported success." >&2
echo "If the Tauri build still fails, rerun with HEIMGEIST_STRICT_SYSTEM_DEPS=1 for a hard preflight failure." >&2
}
STEAMOS_RESTORE_READONLY=0
restore_steamos_readonly() {
if [ "$STEAMOS_RESTORE_READONLY" -eq 1 ]; then
echo "Re-enabling the SteamOS read-only filesystem"
as_root steamos-readonly enable
STEAMOS_RESTORE_READONLY=0
fi
}
prepare_steamos_package_install() {
if ! is_steamos || ! command -v steamos-readonly >/dev/null 2>&1; then
return
fi
readonly_status="$(as_root steamos-readonly status || true)"
if printf '%s\n' "$readonly_status" | grep -Eqi '(^|[[:space:]])enable(d)?($|[[:space:]])'; then
echo "Temporarily disabling the SteamOS read-only filesystem"
as_root steamos-readonly disable
STEAMOS_RESTORE_READONLY=1
fi
}
pacman_keyring_names() {
for keyring_file in /usr/share/pacman/keyrings/*.gpg; do
[ -e "$keyring_file" ] || continue
keyring_name="$(basename "$keyring_file" .gpg)"
printf ' %s' "$keyring_name"
done
}
ensure_steamos_pacman_keyring() {
if ! is_steamos; then
return
fi
if ! command -v pacman-key >/dev/null 2>&1; then
echo "SteamOS package signing cannot be repaired because pacman-key is unavailable." >&2
exit 1
fi
echo "Initializing and populating the SteamOS pacman keyring"
as_root pacman-key --init
keyring_names="$(pacman_keyring_names)"
if [ -n "$keyring_names" ]; then
# shellcheck disable=SC2086
as_root pacman-key --populate $keyring_names
else
as_root pacman-key --populate
fi
}
run_steamos_devmode_bootstrap() {
if ! is_steamos || [ "$HEIMGEIST_STEAMOS_DEVMODE" = "0" ]; then
return 1
fi
if ! command -v steamos-devmode >/dev/null 2>&1; then
return 1
fi
echo "Pacman still cannot install packages; running SteamOS devmode bootstrap"
as_root steamos-devmode enable
}
install_pacman_packages() {
if as_root pacman "$@"; then
return
fi
if ! is_steamos; then
return 1
fi
echo "Pacman failed on SteamOS. Refreshing package-signing trust and retrying once."
ensure_steamos_pacman_keyring
if as_root pacman "$@"; then
return
fi
if run_steamos_devmode_bootstrap && as_root pacman "$@"; then
return
fi
echo "SteamOS pacman package installation still failed." >&2
echo "This is usually a broken SteamOS pacman keyring, not a corrupt Heimgeist download." >&2
echo "Try running 'sudo steamos-devmode enable' manually, then rerun ./run.sh." >&2
return 1
}
install_arch_native_deps() {
set -- \
webkit2gtk-4.1 \
base-devel \
pkgconf \
gtk3 \
curl \
wget \
file \
openssl \
appmenu-gtk-module \
libappindicator-gtk3 \
librsvg \
xdotool
missing_packages=""
for package_name in "$@"; do
if ! pacman -Q "$package_name" >/dev/null 2>&1; then
missing_packages="$missing_packages $package_name"
fi
done
if [ -z "$missing_packages" ]; then
return
fi
echo "Installing missing Tauri/Arch packages:$missing_packages"
echo "SteamOS/Arch may ask for your sudo password."
prepare_steamos_package_install
trap 'restore_steamos_readonly' EXIT
trap 'restore_steamos_readonly; exit 130' HUP INT TERM
ensure_steamos_pacman_keyring
install_status=0
if is_steamos; then
# SteamOS system updates own the base image, so only install missing packages.
install_pacman_packages -S --needed --noconfirm $missing_packages || install_status=$?
else
# Arch requires a full upgrade when synchronizing/installing packages.
install_pacman_packages -Syu --needed --noconfirm $missing_packages || install_status=$?
fi
restore_steamos_readonly
trap - EXIT HUP INT TERM
return "$install_status"
}
install_debian_native_deps() {
set -- \
libwebkit2gtk-4.1-dev \
build-essential \
curl \
wget \
file \
libxdo-dev \
libssl-dev \
libayatana-appindicator3-dev \
librsvg2-dev \
pkg-config
missing_packages=""
for package_name in "$@"; do
if ! dpkg-query -W -f='${Status}' "$package_name" 2>/dev/null | grep -q 'ok installed'; then
missing_packages="$missing_packages $package_name"
fi
done
if [ -z "$missing_packages" ]; then
return
fi
echo "Installing missing Tauri/Debian packages:$missing_packages"
as_root apt-get update
as_root env DEBIAN_FRONTEND=noninteractive apt-get install -y $missing_packages
}
ensure_native_build_dependencies() {
if [ "$HEIMGEIST_SKIP_SYSTEM_DEPS" = "1" ]; then
return
fi
case "$(uname -s)" in
Darwin)
if ! xcode-select -p >/dev/null 2>&1; then
echo "Installing the Xcode Command Line Tools required by Tauri."
xcode-select --install || true
echo "Complete the Xcode Command Line Tools installation, then run ./run.sh again." >&2
exit 1
fi
;;
Linux)
if linux_native_deps_usable; then
return
fi
if command -v pacman >/dev/null 2>&1; then
install_arch_native_deps
elif command -v apt-get >/dev/null 2>&1 && command -v dpkg-query >/dev/null 2>&1; then
install_debian_native_deps
else
echo "Native dependency installation currently supports Arch/SteamOS and Debian/Ubuntu." >&2
echo "Install your distribution's Tauri 2 system prerequisites, then run ./run.sh again." >&2
exit 1
fi
if ! linux_native_deps_usable; then
handle_incomplete_native_dependencies
fi
;;
esac
}
node_runtime_usable() {
command -v node >/dev/null 2>&1 \
@@ -35,7 +310,7 @@ download_file() {
return
fi
echo "Node.js is missing and neither curl nor wget is available to download it." >&2
echo "A required tool is missing and neither curl nor wget is available to download it." >&2
echo "Install curl or wget, then run ./run.sh again." >&2
exit 1
}
@@ -56,6 +331,98 @@ file_sha256() {
exit 1
}
install_uv() {
uv_tmp_dir="$(mktemp -d "${TMPDIR:-/tmp}/heimgeist-uv.XXXXXX")"
trap 'rm -rf "$uv_tmp_dir"' EXIT HUP INT TERM
echo "Python 3.13 is missing; installing the uv runtime manager locally"
download_file "https://astral.sh/uv/install.sh" "$uv_tmp_dir/install.sh"
mkdir -p "$HEIMGEIST_TOOL_BIN_DIR"
UV_UNMANAGED_INSTALL="$HEIMGEIST_TOOL_BIN_DIR" UV_NO_MODIFY_PATH=1 sh "$uv_tmp_dir/install.sh"
rm -rf "$uv_tmp_dir"
trap - EXIT HUP INT TERM
}
ensure_uv() {
if command -v uv >/dev/null 2>&1; then
return
fi
install_uv
if ! command -v uv >/dev/null 2>&1; then
echo "The local uv installation did not provide an executable." >&2
exit 1
fi
}
python_runtime_usable() {
command -v "$PYTHON_BIN" >/dev/null 2>&1 \
&& "$PYTHON_BIN" -c 'import sys; raise SystemExit(0 if sys.version_info[:2] == (3, 13) else 1)' >/dev/null 2>&1
}
ensure_python_runtime() {
if python_runtime_usable; then
return
fi
if [ "$PYTHON_BIN_WAS_SET" -eq 1 ]; then
echo "PYTHON_BIN '$PYTHON_BIN' is unavailable or is not Python 3.13." >&2
exit 1
fi
ensure_uv
echo "Installing Python 3.13 locally"
uv python install 3.13
PYTHON_BIN="$(uv python find 3.13)"
if ! python_runtime_usable; then
echo "The local Python 3.13 installation is incomplete." >&2
exit 1
fi
}
rust_runtime_usable() {
command -v cargo >/dev/null 2>&1 \
&& command -v rustc >/dev/null 2>&1 \
&& rustc --version | awk '
{
split($2, version, ".")
exit !((version[1] > 1) || (version[1] == 1 && version[2] >= 77))
}
'
}
install_rustup() {
rustup_tmp_dir="$(mktemp -d "${TMPDIR:-/tmp}/heimgeist-rustup.XXXXXX")"
trap 'rm -rf "$rustup_tmp_dir"' EXIT HUP INT TERM
echo "Rust/Cargo 1.77+ was not found; installing the stable Rust toolchain locally"
download_file "https://sh.rustup.rs" "$rustup_tmp_dir/rustup-init.sh"
sh "$rustup_tmp_dir/rustup-init.sh" -y --profile minimal --default-toolchain stable --no-modify-path
rm -rf "$rustup_tmp_dir"
trap - EXIT HUP INT TERM
}
ensure_rust_runtime() {
if rust_runtime_usable; then
return
fi
if command -v rustup >/dev/null 2>&1; then
echo "Installing/updating the stable Rust toolchain"
rustup toolchain install stable --profile minimal
rustup default stable
else
install_rustup
fi
if ! rust_runtime_usable; then
echo "The Rust installation is incomplete; cargo and rustc 1.77+ are required." >&2
exit 1
fi
}
install_project_node() {
case "$(uname -s)" in
Linux) node_platform="linux" ;;
@@ -290,12 +657,10 @@ install_selected_torch() {
esac
}
ensure_native_build_dependencies
ensure_node_runtime
if ! command -v "$PYTHON_BIN" >/dev/null 2>&1; then
echo "Python 3.13 is required. Set PYTHON_BIN to a Python 3.13 executable if needed." >&2
exit 1
fi
ensure_python_runtime
ensure_rust_runtime
TORCH_FLAVOR="$(resolve_torch_flavor)"
RECREATE_VENV=0
@@ -390,4 +755,9 @@ if [ "$NEED_NODE_DEPS_INSTALL" -eq 1 ]; then
write_state "$NODE_DEPS_STATE_FILE" package.json package-lock.json
fi
if [ "$HEIMGEIST_BOOTSTRAP_ONLY" = "1" ]; then
echo "Heimgeist development dependencies are ready."
exit 0
fi
npm run dev