#!/usr/bin/env bash ## Last Updated: 2022-04-25 # ## Info: Download all pre-built iso from Ubuntu ## Wiki ~ https://wiki.ubuntu.com/Releases # ## Source: https://gitlab.com/-/snippets/2133024 # ## Quit on error #set -e ## Quit if any command in the chain errors #set -o pipefail ## Variable has to be defined set -u # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - function print_status() { printf '%-13s:' "${ver}/${arch}" } # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - ## Check if root (due to NAS) if [ "$(id -u)" -eq 0 ]; then echo "[-] You are root. Please switch to non-root" >&2 exit 1 fi ## Move to script folder cd "$( dirname $BASH_SOURCE )/" script_path="$( readlink -f "$( readlink "${BASH_SOURCE[0]}" )" || true)" cd "$( dirname "${script_path}" )/" pwd ## Remove any empty files find . \ -type f \ -name '*.iso' \ ! -path '*/.git/*' \ -empty \ -print \ -delete \ || true echo -e "\n[i] Archived images" for ver in $( curl -s http://old-releases.ubuntu.com/releases/ \ | awk -F '"' '/href/ {print $8}' \ | grep -v '-' \ | grep -v '_' \ | grep -v '?' \ | grep '\.' \ | grep '/$' \ | sed 's_/__g' ); do major=$( printf "%02d" "$( echo ${ver} | cut -d '.' -f1 )" ).$( echo ${ver} | cut -d '.' -f2 ) mkdir -p "Ubuntu-${major}/" for arch in amd64 i386; do url=$( curl -s http://old-releases.ubuntu.com/releases/${ver}/ \ | awk -F '"' '/href/ {print $8}' \ | grep -v '+mac' \ | grep -v 'live-server' \ | grep '\.iso$' \ | grep 'install\|server' \ | grep "${arch}" ) || true [[ "$( echo "${url}" | wc -l )" -gt 1 ]] \ && url=$( echo "${url}" | grep "$( echo ${ver} | sed 's/\.0$//' )-" ) [ -z "${url}" ] \ && echo -e "\n[-] $( print_status ) Missing pre-built ISO. Maybe it hasn't yet made it to archive/old-releases?" >&2 \ && continue #[[ "$( echo "${url}" | wc -l )" -ne 1 ]] \ # && echo -e "\n[-] $( print_status ) !!!More than one image detected!!! - work on those grep rules (1)\n${url}" >&2 \ # && continue ## Feedback #echo "[i] $( print_status ) ${url}" ## Download all echo "${url}" \ | while read x; do ## Feedback echo "[i] $( print_status ) ${x}" ## Download wget \ --continue \ --no-verbose \ -O "Ubuntu-${major}/${x}" \ "http://old-releases.ubuntu.com/releases/${ver}/${x}" \ || echo -e " [-] Issue with wget (1)" >&2 done done done # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - echo -e "\n[i] Current versions" for ver in $( curl -s http://releases.ubuntu.com/releases/ \ | awk -F '"' '/href/ {print $6}' \ | grep -v '-' \ | grep -v '_' \ | grep -v '?' \ | grep '\.' \ | grep '/$' \ | sed 's_/__g' ); do major=$( printf "%02d" "$( echo ${ver} \ | cut -d '.' -f1 )" ).$( echo ${ver} \ | cut -d '.' -f2 ) mkdir -p "Ubuntu-${major}/" for arch in amd64 i386; do url=$( curl -s http://releases.ubuntu.com/releases/${ver}/ \ | awk -F '"' '/href/ {print $12}' \ | grep -v '+mac' \ | grep '\.iso$' \ | grep 'install\|server' \ | grep "${arch}" ) [[ "$( echo "${url}" | wc -l )" -gt 1 ]] \ && url=$( echo "${url}" | grep "$( echo ${ver} | sed 's/\.0$//' )-" ) [ -z "${url}" ] \ && echo -e "\n[-] $( print_status ) Missing pre-built ISO" >&2 \ && continue #[[ "$( echo "${url}" | wc -l )" -ne 1 ]] \ # && echo -e "\n[-] $( print_status ) !!!More than one image detected!!! - work on those grep rules (2)\n${url}" >&2 \ # && continue ## Feedback #echo "[i] $( print_status ) ${url}" ## Download all echo "${url}" \ | while read x; do ## Feedback echo "[i] $( print_status ) ${x}" ## Download wget \ --continue \ --no-verbose \ -O "Ubuntu-${major}/${x}" \ "http://releases.ubuntu.com/releases/${ver}/${x}" \ || echo -e " [-] Issue with wget (2)" >&2 done done done echo "" # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - ## Generate hashes rm -f {MD5,SHA1,SHA256}SUM echo "[i] Generating hashes" find . \ -type f \ -name '*.iso' \ ! -path '*/.git/*' \ | sort -h \ | while read x; do echo "${x}" md5sum "${x}" >> MD5SUM; sha1sum "${x}" >> SHA1SUM; sha256sum "${x}" >> SHA256SUM; done echo "" # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - ## Done date > last.txt echo "[i] Done" exit