]> Frank Brehm's Git Trees - pixelpark/create-vmware-tpl.git/commitdiff
Creating and evaluating timestamp of last update
authorFrank Brehm <frank.brehm@pixelpark.com>
Tue, 8 Jun 2021 10:44:06 +0000 (12:44 +0200)
committerFrank Brehm <frank.brehm@pixelpark.com>
Tue, 8 Jun 2021 10:44:06 +0000 (12:44 +0200)
bin/get-centos8-streams-boot

index 5d71eb50a30ddcaa2f338f30483e2f556e2933bc..c57ca12b83d52226bf4675dca83bb2d156543f79 100755 (executable)
@@ -8,7 +8,7 @@ DEBUG="n"
 QUIET='n'
 SIMULATE="n"
 
-VERSION="0.3.3"
+VERSION="0.3.4"
 
 BASE_NAME="$(basename ${0})"
 BASE_DIR="$(dirname ${0})"
@@ -41,6 +41,7 @@ MOUNTPOINT_ROOT="/var/tmp/centos8-stream-${ARCH}"
 MOUNTPOINT=
 IMAGE_ROOT="/var/www/cobbler/ks_mirror"
 IMAGE_DIR="${IMAGE_ROOT}/CentOS-8-Stream-${ARCH}"
+TIMESTAMP_FILE="${IMAGE_DIR}.timestamp"
 TMP_IMAGE_DIR=
 LAST_TSTAMP="0"
 LOGFILE=
@@ -769,6 +770,11 @@ perform_mirror() {
     trap - INT TERM EXIT ABRT
     cleanup_image
 
+    info "Writing current timestamp '${CYAN}${tstamp}${NORMAL}' into '${CYAN}${TIMESTAMP_FILE}${NORMAL}' ..."
+    if [[ "${SIMULATE}" != "y" ]] ; then
+        echo "${tstamp}" > "${TIMESTAMP_FILE}"
+    fi
+
     return ${ret}
 
 }
@@ -787,18 +793,47 @@ do_update() {
         len="${#URLS[*]}"
         index=$(( ${RANDOM} % ${len} ))
         base_url="${URLS[${index}]}"
+        line
         info "Trying '${CYAN}${base_url}${NORMAL}' ..."
-        empty_line
         if perform_mirror "${base_url}" ; then
             return 0
         fi
-        sleep 1
+        if [[ "${len}" == 1 ]] ; then
+            break
+        fi
+        empty_line
+        sleep 0.5
         create_urls "${base_url}"
 
     done
 
 }
 
+#------------------------------------------------------------------------------
+get_current_timestamp() {
+
+    info "Get timestamp of last update from '${CYAN}${TIMESTAMP_FILE}${NORMAL}' ..."
+
+    if [[ ! -e "${TIMESTAMP_FILE}" ]] ; then
+        debug "File '${CYAN}${TIMESTAMP_FILE}${NORMAL}' does not exists."
+        return
+    fi
+
+    if [[ ! -f "${TIMESTAMP_FILE}" ]] ; then
+        warn "File '${CYAN}${TIMESTAMP_FILE}${NORMAL}' exists, but is not a regular file."
+        return
+    fi
+
+    local first_line=$( cat "${TIMESTAMP_FILE}" | \
+        grep -v -E '^[         ]*(#.*)?$' | \
+        head -n 1 | \
+        sed -e 's/^[   ]*//' -e 's/[   ]$//' )
+    debug "First line: ${first_line}"
+    LAST_TSTAMP=$(( ${first_line} + 0 ))
+    info "Last Timestamp: '${CYAN}${LAST_TSTAMP}${NORMAL}'."
+
+}
+
 #------------------------------------------------------------------------------
 main() {
 
@@ -816,7 +851,10 @@ main() {
     info "Starting update of boot environment of '${GREEN}CentOS-8 Stream${NORMAL}'."
     empty_line
 
+    get_current_timestamp
+    empty_line
     do_update
+    empty_line
 
     info "Finished."
 }