From: Frank Brehm Date: Tue, 8 Jun 2021 10:44:06 +0000 (+0200) Subject: Creating and evaluating timestamp of last update X-Git-Tag: 2.2.6^2^2~2 X-Git-Url: https://git.uhu-banane.org/?a=commitdiff_plain;h=dde3526eb6e876ac039caf844c70352002253b76;p=pixelpark%2Fcreate-vmware-tpl.git Creating and evaluating timestamp of last update --- diff --git a/bin/get-centos8-streams-boot b/bin/get-centos8-streams-boot index 5d71eb5..c57ca12 100755 --- a/bin/get-centos8-streams-boot +++ b/bin/get-centos8-streams-boot @@ -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." }