From: Frank Brehm Date: Tue, 8 Jun 2021 10:19:32 +0000 (+0200) Subject: Syncing content of iso image to the correct place X-Git-Tag: 2.2.6^2^2~3 X-Git-Url: https://git.uhu-banane.org/?a=commitdiff_plain;h=57a001ff7af536a3fda404ae1fe28d3eca0e0280;p=pixelpark%2Fcreate-vmware-tpl.git Syncing content of iso image to the correct place --- diff --git a/bin/get-centos8-streams-boot b/bin/get-centos8-streams-boot index 5f86954..5d71eb5 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.2" +VERSION="0.3.3" 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}" +TMP_IMAGE_DIR= LAST_TSTAMP="0" LOGFILE= LOG_ROOTDIR="/var/log" @@ -312,6 +313,41 @@ purge() { } +#------------------------------------------------------------------------------ +RMDIR() { + + if [[ "${SIMULATE}" == "y" ]] ; then + debug "Simulated removing of: $*" + return + fi + if [[ "${VERBOSE}" != "y" ]] ; then + rmdir "$@" + else + rmdir --verbose "$@" + fi + +} + +#------------------------------------------------------------------------------ +MV() { + + local cmd="mv $*" + if [[ "${VERBOSE}" == "y" ]] ; then + cmd="mv --verbose $*" + fi + if [[ "${SIMULATE}" == "y" ]] ; then + info "Executing: ${cmd}" + return + fi + debug "Executing: ${cmd}" + if [[ "${VERBOSE}" != "y" ]] ; then + mv "$@" + else + mv --verbose "$@" + fi + +} + #------------------------------------------------------------------------------ MKDIR() { @@ -516,6 +552,10 @@ cleanup_image() { info "Cleaning up mounts and images" + if [[ -n "${TMP_IMAGE_DIR}" && -e "${TMP_IMAGE_DIR}" ]] ; then + purge -r "${TMP_IMAGE_DIR}" + fi + if [[ -n "${MOUNTPOINT}" ]] ; then if [[ "${HAS_MOUNTED}" == "y" ]] ; then umount "${MOUNTPOINT}" @@ -617,6 +657,42 @@ mount_image() { } +#------------------------------------------------------------------------------ +copy_image() { + + TMP_IMAGE_DIR=$( mktemp --directory "${IMAGE_DIR}.XXXXXXXX" ) + + info "Syncing content of ISO image '${CYAN}${MOUNTPOINT}${NORMAL}' => '${CYAN}${TMP_IMAGE_DIR}${NORMAL}' ..." + + local cmd="rsync --archive --hard-links" + if [[ "${VERBOSE}" == "y" ]] ; then + cmd+=" --verbose --progress" + fi + cmd+=" \"${MOUNTPOINT}/\" \"${TMP_IMAGE_DIR}/\"" + if [[ "${SIMULATE}" == "y" ]] ; then + info "Executing: ${cmd}" + return 0 + fi + debug "Executing: ${cmd}" + if eval ${cmd} 2>&1 | tee -a "${LOGFILE}" ; then + : + else + error "Sync was not successful" + return 8 + fi + + if [[ -d "${IMAGE_DIR}" ]] ; then + MV "${IMAGE_DIR}" "${IMAGE_DIR}.old" + fi + MV "${TMP_IMAGE_DIR}" "${IMAGE_DIR}" + if [[ -d "${IMAGE_DIR}.old" ]] ; then + RM -r "${IMAGE_DIR}.old" + fi + + return 0 + +} + #------------------------------------------------------------------------------ perform_mirror() { @@ -628,7 +704,7 @@ perform_mirror() { info "Image not found on '${CYAN}${checksum_url}${NORMAL}'." return 1 fi - # echo "Line: ${line}" + debug "CHECKSUM Line: ${line}" local check_method=$( echo "${line}" | sed -e "s/[ ][ ]*.*//" | tr '[:upper:]' '[:lower:]' ) local base_name=$( echo "${line}" | sed -e "s/.*(//" -e "s/).*//" ) @@ -655,37 +731,45 @@ perform_mirror() { ISO_IMAGE=$( mktemp "${ISO_IMAGE_DIR}/${iso_base}.XXXXXXXX.iso" ) debug "Local ISO image is '${CYAN}${ISO_IMAGE}${NORMAL}'." + local ret=0 + trap cleanup_image INT TERM EXIT ABRT if download_image "${image_url}" "${ISO_IMAGE}" ; then : else + ret=$? info "Download from '${CYAN}${mirror}${NORMAL}' not successful." - trap - INT TERM EXIT ABRT - cleanup_image - return 1 fi - if verify_image "${ISO_IMAGE}" "${check_method}" "${checksum}" ; then - : - else - trap - INT TERM EXIT ABRT - cleanup_image - return 1 + if [[ "${ret}" == 0 ]] ; then + if verify_image "${ISO_IMAGE}" "${check_method}" "${checksum}" ; then + : + else + ret=$? + fi fi - if mount_image ; then - : - else - trap - INT TERM EXIT ABRT - cleanup_image - return 1 + if [[ "${ret}" == 0 ]] ; then + if mount_image ; then + : + else + ret=$? + fi + fi + + if [[ "${ret}" == 0 ]] ; then + if copy_image ; then + : + else + ret=$? + fi fi trap - INT TERM EXIT ABRT cleanup_image - return 0 + return ${ret} }