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
set -euo pipefail

root="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
tmp="$(mktemp -d)"
trap 'rm -rf -- "$tmp"' EXIT

cat >"$tmp/powershell.exe" <<'PS'
#!/usr/bin/env bash
if [[ "${ODS_TEST_PS_MODE:-ok}" == fail ]]; then
    printf 'Exec format error\n' >&2
    exit 126
fi
printf '17179869184\r\n'
PS
cat >"$tmp/wmic.exe" <<'WMIC'
#!/usr/bin/env bash
if [[ "${ODS_TEST_WMIC_MODE:-ok}" == fail ]]; then
    printf 'Exec format error\n' >&2
    exit 126
fi
printf 'TotalVisibleMemorySize=33554432\r\n'
WMIC
chmod +x "$tmp/powershell.exe" "$tmp/wmic.exe"

export PATH="$tmp:$PATH"
source "$root/installers/lib/wsl-memory.sh"

[[ "$(ods_wsl_host_ram_kb)" == 16777216 ]]
ODS_TEST_PS_MODE=fail
export ODS_TEST_PS_MODE
[[ "$(ods_wsl_host_ram_kb)" == 33554432 ]]
ODS_TEST_WMIC_MODE=fail
export ODS_TEST_WMIC_MODE
if ods_wsl_host_ram_kb >"$tmp/failed.out"; then
    printf 'FAIL: unavailable Windows interop supplied host RAM\n' >&2
    exit 1
fi
[[ ! -s "$tmp/failed.out" ]]

# This is the installer call shape under set -euo pipefail: a failed optional
# Windows query must leave the caller alive to use Linux /proc/meminfo.
vm_kb=49209324
printf 'MemTotal: %s kB\n' "$vm_kb" > "$tmp/meminfo"
ODS_PROC_MEMINFO_FILE="$tmp/meminfo"
ods_is_wsl_host() { return 0; }
ods_detect_runtime_ram
[[ -z "$WINDOWS_HOST_RAM_KB" ]]
[[ "$RAM_KB" == "$vm_kb" && "$RAM_GB" == 46 ]]
[[ "$MODEL_TIER_RAM_GB" == 44 ]]

printf 'PASS: WSL host-RAM lookup falls back when Windows interop exits 126\n'