From: Frank Brehm Date: Tue, 8 Jun 2021 09:37:01 +0000 (+0200) Subject: Mounting and unmounting iSO image X-Git-Tag: 2.2.6^2^2~4 X-Git-Url: https://git.uhu-banane.org/?a=commitdiff_plain;h=5d616ae647bd4cbcd78eaa48f9a5cec63f1825d6;p=pixelpark%2Fcreate-vmware-tpl.git Mounting and unmounting iSO image --- diff --git a/bin/get-centos8-streams-boot b/bin/get-centos8-streams-boot index 415cab1..5f86954 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.1" +VERSION="0.3.2" BASE_NAME="$(basename ${0})" BASE_DIR="$(dirname ${0})" @@ -38,6 +38,7 @@ declare -a URLS=() ARCH="x86_64" HAS_MOUNTED="n" MOUNTPOINT_ROOT="/var/tmp/centos8-stream-${ARCH}" +MOUNTPOINT= IMAGE_ROOT="/var/www/cobbler/ks_mirror" IMAGE_DIR="${IMAGE_ROOT}/CentOS-8-Stream-${ARCH}" LAST_TSTAMP="0" @@ -515,6 +516,16 @@ cleanup_image() { info "Cleaning up mounts and images" + if [[ -n "${MOUNTPOINT}" ]] ; then + if [[ "${HAS_MOUNTED}" == "y" ]] ; then + umount "${MOUNTPOINT}" + fi + + if [[ -d "${MOUNTPOINT}" ]] ; then + purge -r "${MOUNTPOINT}" + fi + fi + if [[ -n "${ISO_IMAGE}" && -f "${ISO_IMAGE}" ]] ; then purge "${ISO_IMAGE}"* fi @@ -582,6 +593,30 @@ verify_image() { } +#------------------------------------------------------------------------------ +mount_image() { + + MOUNTPOINT=$( mktemp --directory "${MOUNTPOINT_ROOT}/XXXXXXXX" ) + + info "Mounting '${CYAN}${ISO_IMAGE}${NORMAL}' => '${CYAN}${MOUNTPOINT}${NORMAL}' ..." + local cmd="mount -t iso9660 -o loop,ro \"${ISO_IMAGE}\" \"${MOUNTPOINT}\"" + if [[ "${SIMULATE}" == "y" ]] ; then + info "Executing: ${cmd}" + return 0 + fi + debug "Executing: ${cmd}" + + if eval ${cmd} 2>&1 | tee -a "${LOGFILE}" ; then + debug "Mount successful:\n$( ls -lA "${MOUNTPOINT}" )" + HAS_MOUNTED="y" + return 0 + fi + + warn "Mounting '${YELLOW}${ISO_IMAGE}${NORMAL}' => '${YELLOW}${MOUNTPOINT}${NORMAL}' was not successful." + return 7 + +} + #------------------------------------------------------------------------------ perform_mirror() { @@ -639,6 +674,14 @@ perform_mirror() { return 1 fi + if mount_image ; then + : + else + trap - INT TERM EXIT ABRT + cleanup_image + return 1 + fi + trap - INT TERM EXIT ABRT cleanup_image