Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 38 additions & 12 deletions download_cli.sh
Original file line number Diff line number Diff line change
Expand Up @@ -72,26 +72,52 @@ else
fi

# --- 3) Detect OS/Architecture ---
# Better OS detection for Windows environments
if [[ "${WINDIR:-}" ]] || [[ "${windir:-}" ]] || [[ "$OSTYPE" == "msys" ]] || [[ "$OSTYPE" == "cygwin" ]]; then
OS="windows"
elif [[ -f "/proc/version" ]] && grep -q "Microsoft\|WSL" /proc/version 2>/dev/null; then
# WSL detection
# Allow explicit override for automation or when auto-detection is wrong:
# INSTALL_OS=linux|windows|darwin
if [ -n "${INSTALL_OS:-}" ]; then
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: I would name it OVERRIDE_OS to signify what it is used for as INSTALL_OS and OS are kind of similar.

case "${INSTALL_OS}" in
linux|windows|darwin) OS="${INSTALL_OS}" ;;
*) echo "[error]: unsupported INSTALL_OS='${INSTALL_OS}' (expected: linux|windows|darwin)"; exit 1 ;;
esac
else
# Better OS detection for Windows environments, with safer WSL handling.
# If explicit Windows-like shells/variables are present (MSYS/Cygwin), treat as windows.
if [[ "${WINDIR:-}" ]] || [[ "${windir:-}" ]] || [[ "$OSTYPE" == "msys" ]] || [[ "$OSTYPE" == "cygwin" ]]; then
OS="windows"
elif [[ "$PWD" =~ ^/mnt/[a-zA-Z]/ ]]; then
# WSL mount point detection (like /mnt/c/)
elif [[ -f "/proc/version" ]] && grep -q "Microsoft\|WSL" /proc/version 2>/dev/null; then
# WSL detected. Prefer Linux unless there are clear signs we should install the Windows build:
# - running on a Windows-mounted path like /mnt/c/... OR
# - Windows executables are available AND we're on a Windows mount
if [[ "$PWD" =~ ^/mnt/[a-zA-Z]/ ]]; then
OS="windows"
else
# If powershell/cmd exist, only treat as Windows when in a Windows mount
if command -v powershell.exe >/dev/null 2>&1 || command -v cmd.exe >/dev/null 2>&1; then
if [[ "$PWD" =~ ^/mnt/[a-zA-Z]/ ]] || [[ -d "/c" || -d "/d" || -d "/e" ]]; then
OS="windows"
else
OS="linux"
fi
else
# No strong Windows interop present — install Linux build inside WSL by default
OS="linux"
fi
fi
elif [[ "$PWD" =~ ^/mnt/[a-zA-Z]/ ]]; then
# WSL mount point detection (like /mnt/c/) outside of /proc/version check
OS="windows"
elif [[ "$OSTYPE" == "darwin"* ]]; then
elif [[ "$OSTYPE" == "darwin"* ]]; then
OS="darwin"
elif command -v powershell.exe >/dev/null 2>&1 || command -v cmd.exe >/dev/null 2>&1; then
# Check if Windows executables are available (another Windows indicator)
elif command -v powershell.exe >/dev/null 2>&1 || command -v cmd.exe >/dev/null 2>&1; then
# Presence of Windows executables (likely a Windows environment)
OS="windows"
elif [[ "$PWD" =~ ^/[a-zA-Z]/ ]] && [[ -d "/c" || -d "/d" || -d "/e" ]]; then
elif [[ "$PWD" =~ ^/[a-zA-Z]/ ]] && [[ -d "/c" || -d "/d" || -d "/e" ]]; then
# Check for Windows-style mount points (like in Git Bash)
OS="windows"
else
else
# Fallback to uname for other systems
OS=$(uname -s | tr '[:upper:]' '[:lower:]')
fi
fi

ARCH=$(uname -m)
Expand Down
Loading