]> Frank Brehm's Git Trees - pixelpark/create-vmware-tpl.git/commitdiff
Mounting and unmounting iSO image
authorFrank Brehm <frank.brehm@pixelpark.com>
Tue, 8 Jun 2021 09:37:01 +0000 (11:37 +0200)
committerFrank Brehm <frank.brehm@pixelpark.com>
Tue, 8 Jun 2021 09:37:01 +0000 (11:37 +0200)
bin/get-centos8-streams-boot

index 415cab15d327950a41529a84170dfb0aca895c8b..5f869548d1036380c3b45cd917524be38dd07a2f 100755 (executable)
@@ -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