Files
Server-scripts/utils/download_latest_ubuntu.sh
T

70 lines
1.6 KiB
Bash
Executable File

#!/usr/bin/env bash
set -euo pipefail
DOWNLOAD_DIR="/data/ubuntu"
mkdir -p "$DOWNLOAD_DIR"
ARCH="amd64"
# Supported:
# 24.04 desktop
# 24.04 server
# 26.04 desktop
# 26.04 server
declare -A URLS=(
["24-desktop"]="https://releases.ubuntu.com/24.04/"
["24-server"]="https://releases.ubuntu.com/24.04/"
["26-desktop"]="https://releases.ubuntu.com/resolute/"
["26-server"]="https://releases.ubuntu.com/resolute/"
)
download_if_newer() {
local key="$1"
local base_url="${URLS[$key]}"
echo "Checking $key..."
iso_name=$(curl -fsSL "$base_url" \
| grep -oE 'ubuntu-[0-9.]+(-live-server|-desktop)-amd64\.iso' \
| sort -Vu \
| tail -1)
if [[ -z "$iso_name" ]]; then
echo "Could not determine latest ISO for $key"
return 1
fi
latest_version=$(echo "$iso_name" | grep -oE '[0-9]+(\.[0-9]+)+')
local_iso=$(find "$DOWNLOAD_DIR" -name "*$(basename "$iso_name" | sed 's/[0-9.]\+//')*" 2>/dev/null | sort | tail -1 || true)
if [[ -n "$local_iso" ]]; then
local_version=$(basename "$local_iso" | grep -oE '[0-9]+(\.[0-9]+)+' | head -1)
if [[ "$local_version" == "$latest_version" ]]; then
echo "Already up to date: $iso_name"
return 0
fi
echo "Outdated local ISO found:"
echo " Local : $local_version"
echo " Latest: $latest_version"
fi
echo "Downloading $iso_name..."
wget --limit-rate=4M -c -P "$DOWNLOAD_DIR" "${base_url}${iso_name}"
echo "Done."
echo
}
download_if_newer "24-desktop"
download_if_newer "24-server"
download_if_newer "26-desktop"
download_if_newer "26-server"
echo "Finished."