4
0

download_kernel_images.sh 812 B

123456789101112131415161718192021222324252627282930313233
  1. #!/usr/bin/env bash
  2. set -euo pipefail
  3. # Check for required arguments.
  4. if [ "$#" -lt 3 ]; then
  5. echo "Usage: $0 <output directory> <architecture> <version1> [<version2> ...]"
  6. exit 1
  7. fi
  8. OUTPUT_DIR=$1
  9. ARCHITECTURE=$2
  10. shift 2
  11. VERSIONS=("$@")
  12. URLS=$(lynx -dump -listonly -nonumbers https://mirrors.wikimedia.org/debian/pool/main/l/linux/)
  13. readonly URLS
  14. # Find the latest revision of each kernel version.
  15. FILES=()
  16. for VERSION in "${VERSIONS[@]}"; do
  17. while read -r line; do
  18. FILES+=("$line")
  19. done <<< "$(
  20. printf '%s\n' "$URLS" \
  21. | grep -E "linux-image-${VERSION//./\\.}\\.[0-9]+(-[0-9]+)?-cloud-${ARCHITECTURE}-unsigned_.*\\.deb" \
  22. | sort -V \
  23. | tail -n1
  24. )"
  25. done
  26. printf '%s\n' "${FILES[@]}" \
  27. | xargs -t curl -sfSL --create-dirs --output-dir "$OUTPUT_DIR" --parallel --remote-name-all