#!/usr/bin/env bash set -Eeuo pipefail script_dir="$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" && pwd -P)" # shellcheck disable=SC2034 # Exported to scripts that source this helper. repo_root="$(cd -- "$script_dir/../.." && pwd -P)" container_name="${CAPTIONEER_DISTROBOX_NAME:-captioneer-dev}" container_image="${CAPTIONEER_DISTROBOX_IMAGE:-registry.fedoraproject.org/fedora-toolbox:44}" container_packages=( ShellCheck bzip2 curl gcc golang gobject-introspection-devel gtk4-devel gtk4-layer-shell-devel libX11-devel libXfixes-devel pkgconf-pkg-config pulseaudio-utils tar ) die() { printf 'captioneer: %s\n' "$*" >&2 exit 1 } require_command() { command -v "$1" >/dev/null 2>&1 || die "$1 was not found in PATH" } ensure_container() { require_command distrobox distrobox create \ --yes \ --no-entry \ --name "$container_name" \ --image "$container_image" >/dev/null } ensure_dependencies() { local dependency_script # shellcheck disable=SC2016 # This script is evaluated inside the container. dependency_script='set -Eeuo pipefail missing=() for package in "$@"; do if ! rpm -q "$package" >/dev/null 2>&1; then missing+=("$package") fi done if (( ${#missing[@]} > 0 )); then printf "Installing missing Captioneer dependencies: %s\\n" "${missing[*]}" sudo dnf install -y "${missing[@]}" fi' distrobox enter --no-workdir --name "$container_name" -- \ bash -lc "$dependency_script" captioneer-dependencies "${container_packages[@]}" } prepare_distrobox() { ensure_container ensure_dependencies } if [[ "${BASH_SOURCE[0]}" == "$0" ]]; then die "common.sh is a shared helper; run build.sh or run.sh instead" fi