Skip to content

armgit / ODS

Public Imported from GitHub
0

ODS V3 Pre-Release: Public testing and refinement ahead of the official V3 launch. Turn your PC, Mac, or Linux box into a private AI server.

1.5 KB
Raw Blame
#!/usr/bin/env bash

# A dry run must never acquire missing host packages as a side effect.
ods_preflight_require_jq() {
    if ! command -v jq >/dev/null 2>&1; then
        if [[ "${DRY_RUN:-false}" == true ]]; then
            error "jq is required for a complete dry run. Install jq yourself and retry; dry run will not install packages."
            return 1
        fi
        # A forced-reinstall preflight only reports; the real run installs it.
        if [[ "${PREFLIGHT_ONLY:-false}" == true ]]; then
            log "jq not found - the installer will install it"
            return 0
        fi
        log "jq not found - attempting auto-install..."
        if ! ods_sudo_available; then
            error "jq is required but not installed and privileged package installation is unavailable. Install jq first, then re-run ODS."
            return 1
        fi
        case "$PKG_MANAGER" in
            dnf)    ods_sudo dnf install -y jq ;;
            pacman) ods_sudo pacman -S --noconfirm jq ;;
            zypper) ods_sudo zypper install -y jq ;;
            apk)    ods_sudo apk add jq ;;
            xbps)   ods_sudo xbps-install -Sy jq ;;
            apt)    ods_sudo apt-get update -qq </dev/null && ods_sudo apt-get install -y jq </dev/null ;;
            *)      ods_sudo apt-get install -y jq </dev/null ;;
        esac
        if ! command -v jq >/dev/null 2>&1; then
            error "Failed to install jq automatically. Install it manually and re-run."
            return 1
        fi
    fi
    log "jq: $(jq --version 2>/dev/null)"
}