#!/usr/bin/env bash # BUDO_FLATPAK_WRAPPER # Host-side command shim for the Flatpak build. Flatpak does not export # /app/bin/budo into the user's shell PATH, so this script provides the # expected `budo ...` command while preserving cwd-relative project paths. set -euo pipefail APP_ID="${BUDO_FLATPAK_APP_ID:-com.budo.app}" canonical_existing_dir() { local path="$1" if [[ -d "$path" ]]; then (cd "$path" && pwd -P) else local parent parent="$(dirname "$path")" (cd "$parent" 2>/dev/null && pwd -P) || return 1 fi } absolute_path() { local path="$1" case "$path" in /*) printf '%s\n' "$path" ;; *) printf '%s/%s\n' "$HOST_CWD" "$path" ;; esac } add_filesystem_override() { local path="$1" [[ -z "$path" || "$path" == -* ]] && return 0 local abs grant abs="$(absolute_path "$path")" if [[ -e "$abs" ]]; then if command -v realpath >/dev/null 2>&1; then grant="$(realpath "$abs")" else grant="$(canonical_existing_dir "$abs")" [[ -f "$abs" ]] && grant="$grant/$(basename "$abs")" fi else grant="$(canonical_existing_dir "$abs")" || return 0 fi FLATPAK_OVERRIDES+=("--filesystem=$grant") } HOST_CWD="$(pwd -P 2>/dev/null || pwd)" ORIGINAL_ARGS=("$@") FLATPAK_OVERRIDES=("--cwd=$HOST_CWD" "--filesystem=$HOST_CWD") if [[ $# -gt 0 ]]; then case "$1" in run|init|web-serve|web-export|android-apk|android-aab) [[ $# -gt 1 ]] && add_filesystem_override "$2" ;; help|--help|-h|budo.d.ts|budo-llm.md) ;; *) add_filesystem_override "$1" ;; esac fi while [[ $# -gt 0 ]]; do case "$1" in --file-root|-o|--output) shift [[ $# -gt 0 ]] && add_filesystem_override "$1" ;; esac shift || true done exec flatpak run "${FLATPAK_OVERRIDES[@]}" "$APP_ID" "${ORIGINAL_ARGS[@]}"