]> Frank Brehm's Git Trees - pixelpark/create-vmware-tpl.git/commitdiff
Starting with bin/get-centos8-streams-boot
authorFrank Brehm <frank.brehm@pixelpark.com>
Mon, 7 Jun 2021 15:31:07 +0000 (17:31 +0200)
committerFrank Brehm <frank.brehm@pixelpark.com>
Mon, 7 Jun 2021 15:31:07 +0000 (17:31 +0200)
bin/get-centos8-streams-boot [new file with mode: 0755]

diff --git a/bin/get-centos8-streams-boot b/bin/get-centos8-streams-boot
new file mode 100755 (executable)
index 0000000..827a19f
--- /dev/null
@@ -0,0 +1,111 @@
+#!/bin/bash
+
+set -e
+set -u
+
+
+declare -a MIRROR_URLS=(
+    'https://de.mirrors.clouvider.net/CentOS/'
+    'https://mirror.fra10.de.leaseweb.net/centos/'
+    'https://mirror.23media.com/centos/'
+    'https://ftp.agdsn.de/pub/mirrors/centos/'
+    'https://centos.mirrors.as250.net/'
+    'https://mirror.checkdomain.de/centos/'
+    'https://mirror.cuegee.com/centos/'
+    'https://mirror.dogado.de/centos/'
+    'https://ftp.fau.de/centos/'
+    'https://mirror.imt-systems.com/centos/'
+    'https://mirror.netzwerge.de/centos/'
+    'https://ftp.plusline.net/centos/'
+    'https://ftp.halifax.rwth-aachen.de/centos/'
+    'https://mirror.scaleuptech.com/centos/'
+    'https://mirror1.hs-esslingen.de/pub/Mirrors/centos/'
+    'https://ftp.wrz.de/pub/CentOS/'
+    'https://mirrors.xtom.de/centos/'
+)
+
+declare -a URLS=()
+
+LAST_TSTAMP="20210602"
+
+create_urls() {
+
+    local omit_url="${1:-}"
+    local url=
+
+    if [[ -z "${omit_url}" ]] ; then
+        URLS=()
+        for url in "${MIRROR_URLS[@]}" ; do
+            URLS+=( "${url}" )
+        done
+        return 0
+    fi
+
+    local -a tmp_urls=()
+    for url in "${URLS[@]}" ; do
+        if [[ "${omit_url}" == "${url}" ]] ; then
+            continue
+        fi
+        tmp_urls+=( "${url}" )
+    done
+    URLS=()
+    for url in "${tmp_urls[@]}" ; do
+        URLS+=( "${url}" )
+    done
+    return 0
+}
+
+perform_mirror() {
+
+    local mirror="$1"
+    local checksum_url="${mirror}8-stream/isos/x86_64/CHECKSUM"
+
+    local line=$( curl -s -L "${checksum_url}" | grep -v '#' | grep -- '-boot.iso' )
+    if [[ -z "${line}" ]] ; then
+        echo "Image not found."
+        return 1
+    fi
+    # echo "Line: ${line}"
+
+    local check_method=$( echo "${line}" | sed -e "s/[         ][      ]*.*//" | tr '[:upper:]' '[:lower:]' )
+    local base_name=$( echo "${line}" | sed -e "s/.*(//" -e "s/).*//" )
+    local checksum=$( echo "${line}" | sed -e "s/.*=[  ]*//" | tr '[:upper:]' '[:lower:]' )
+    local image_url="${mirror}8-stream/isos/x86_64/${base_name}"
+    local tstamp=$( echo "${base_name}" | sed -e 's/CentOS-Stream-8-x86_64-\([0-9][0-9]*\)-.*/\1/i' )
+
+    if [[ "${tstamp}" -le "${LAST_TSTAMP}" ]] ; then
+        echo "Timestamp '${tstamp}' is too old."
+        return 1
+    fi
+
+    echo "$( cat <<-EOF
+       Performing:
+           Image:     ${image_url}
+           Timestamp: ${tstamp}
+           Check:     ${check_method}sum -> '${checksum}'
+       EOF
+    )"
+    echo
+
+    return 0
+
+}
+
+create_urls
+while [[ "${#URLS[*]}" -ge 1 ]] ; do
+
+    LEN="${#URLS[*]}"
+    INDEX=$(( ${RANDOM} % ${LEN} ))
+    BASE_URL="${URLS[${INDEX}]}"
+    echo "Trying '${BASE_URL}' ..."
+    echo
+    if perform_mirror "${BASE_URL}" ; then
+        exit 0
+    fi
+    sleep 2
+    create_urls "${BASE_URL}"
+
+done
+
+
+# vim: ts=4 et list