QUIET='n'
SIMULATE="n"
-VERSION="0.3.2"
+VERSION="0.3.3"
BASE_NAME="$(basename ${0})"
BASE_DIR="$(dirname ${0})"
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"
}
+#------------------------------------------------------------------------------
+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() {
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}"
}
+#------------------------------------------------------------------------------
+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() {
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/).*//" )
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}
}