Skip to content

Instantly share code, notes, and snippets.

@jcoehoorn
Created September 4, 2026 20:01
Show Gist options
  • Select an option

  • Save jcoehoorn/1ceb0666ed20382ccba2ad38a419a232 to your computer and use it in GitHub Desktop.

Select an option

Save jcoehoorn/1ceb0666ed20382ccba2ad38a419a232 to your computer and use it in GitHub Desktop.
check_uosserver_version.sh
#!/bin/bash
echo "Querying Ubiquiti for the latest UniFi OS Server (Linux x64)..."
API_URL="https://fw-update.ubnt.com/api/firmware?filter=eq~~product~~unifi-os-server&filter=eq~~channel~~release&filter=eq~~platform~~linux-x64&sort=-version&limit=1"
if command -v curl &> /dev/null; then
PAYLOAD=$(curl -sL "$API_URL")
elif command -v wget &> /dev/null; then
PAYLOAD=$(wget -qO- "$API_URL")
else
echo "Error: Neither curl nor wget is installed on this system."
exit 1
fi
if [[ -z "$PAYLOAD" ]]; then
echo "Error: Failed to fetch data from the API."
exit 1
fi
# Extract the raw version string, then normalize it to just the numbers (e.g., 4.2.23)
RAW_LATEST=$(echo "$PAYLOAD" | grep -o '"version":"[^"]*"' | head -n 1 | cut -d'"' -f4)
LATEST_VERSION=$(echo "$RAW_LATEST" | grep -oE '[0-9]+(\.[0-9]+)+' | head -n 1)
# Extract the download link
DOWNLOAD_URL=$(echo "$PAYLOAD" | grep -o '"data":{"href":"[^"]*"' | head -n 1 | cut -d'"' -f6)
if [[ -z "$LATEST_VERSION" || -z "$DOWNLOAD_URL" ]]; then
echo "Error: Failed to parse the latest version information."
exit 1
fi
# ---------------------------------------------------------
# Check if UniFi OS Server is already installed
# ---------------------------------------------------------
INSTALLED_VERSION="Not Installed"
UPDATE_AVAILABLE="N/A"
if command -v uosserver &> /dev/null || [[ -f "/usr/local/bin/uosserver" ]]; then
UOS_BIN=$(command -v uosserver 2>/dev/null || echo "/usr/local/bin/uosserver")
# Try to execute the binary and extract the raw version output
RAW_INSTALLED=$("$UOS_BIN" --version 2>/dev/null || "$UOS_BIN" version 2>/dev/null)
# Normalize the output to just the numbers to match the LATEST_VERSION format
EXTRACTED_VERSION=$(echo "$RAW_INSTALLED" | grep -oE '[0-9]+(\.[0-9]+)+' | head -n 1)
if [[ -n "$EXTRACTED_VERSION" ]]; then
INSTALLED_VERSION="$EXTRACTED_VERSION"
# Compare versions using 'sort -V' (version sort)
if [[ "$INSTALLED_VERSION" == "$LATEST_VERSION" ]]; then
UPDATE_AVAILABLE="No (System is up to date)"
else
# sort -V puts the lowest version first. If the last item is LATEST_VERSION, an update is ready.
HIGHEST=$(printf "%s\n%s" "$INSTALLED_VERSION" "$LATEST_VERSION" | sort -V | tail -n 1)
if [[ "$HIGHEST" == "$LATEST_VERSION" ]]; then
UPDATE_AVAILABLE="Yes (Update to $LATEST_VERSION)"
else
UPDATE_AVAILABLE="No (Installed version is somehow newer)"
fi
fi
else
INSTALLED_VERSION="Installed (Version Unknown)"
UPDATE_AVAILABLE="Unknown (Could not parse local version)"
fi
fi
# ---------------------------------------------------------
# Output Summary
# ---------------------------------------------------------
echo ""
echo "=================================================="
echo "UniFi OS Server (Linux x64)"
echo "=================================================="
echo "Installed Version : $INSTALLED_VERSION"
echo "Latest Version : $LATEST_VERSION"
echo "Update Available : $UPDATE_AVAILABLE"
echo "Download URL : $DOWNLOAD_URL"
echo "=================================================="
echo ""
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment