DMG unmount issue.

tdenton
Contributor II

Afternoon All 

Hopefully someone has seen this before.

I have recently patched VLC media player the install media is DMG so used Repackage https://bitbucket.org/twocanoes/repackage/src/master/?ref=steemhunt application to create a PKG for deployment.

I have noticed that some devices don't unmout the sparsebundle within pkg package. I though this might have been some issues with creation of the pkg. So I delete the current version and recreated it.

Testing the new package created in same way this doesnt seem to happen.

I though removing the orginal pkg from DP would stop it being mounted seems not. So I have created a policy forcely remove it on login. 

/usr/sbin/diskutil unmount force /Volumes/1010139C-84D6-4178-A17F-D3DD4F424C8C.

This seems to be working fine if the machine is rebooted, I think this should sort itself out overtime as the machines are powered off daily. On restarting a device which has just run the above command it doesnt get mounted on login.

I have two questions?

Why is happening as there a post install script which should unmount it see below. It was being unmounted in my testing. It also seems to be random if it gets mounted or not on a new login.

Is there a better way to remove it for All user who login in. 

 

 

#!/bin/sh

#Copyright 2018-2019 Twocanoes Software, Inc
shopt -s nullglob

install_dir="$2"
target="$3"
diskimage_name="10650355-FEC4-41D9-A563-2AA4133FDCCF.sparsebundle"
echo "mounting sparse image"
mounted_sparse=$(hdiutil attach -plist "${install_dir}/${diskimage_name}" |grep -A 1 mount-point|grep -v mount-point|sed 's|.*<string>\(.*\)</string>.*|\1|')
echo "mounting dmg"
vol=$(hdiutil attach -plist "${mounted_sparse}"/*.dmg |grep -A 1 mount-point|grep -v mount-point|sed 's|.*<string>\(.*\)</string>.*|\1|')

for pkg in "${vol}"/*.pkg; do
    echo "installing ${pkg}"
    /usr/sbin/installer -package "${pkg}" -target "${target}"

done

for app in "${vol}"/*.app; do

    app_name=$(basename "${app}")
    echo "copying ${app_name}"
    /bin/cp -R "${app}" "$3"/Applications/
    echo "changing ownership"
    chown -R root:wheel "$3"/Applications/"${app_name}"

done
diskutil unmount force "${vol}"
diskutil unmount force "${mounted_sparse}"

exit 0

 

 

Thanks





3 REPLIES 3

jamf-42
Valued Contributor II

Way too complex.. 

mount Dmg.. drag to /Applications, do a modified files in composer, bin all the content, drag VLC in, check permissions.. build.. 

AJPinto
Honored Contributor III

I suggest just using composer, cut out all the needless steps. You can also deploy the dmg from VNC directly if you cache it and run it with a script.

 

The script below is something I wrote recently to install something from a .dmg, it could be adjusted to change the dmg location to the Jamf waiting room and have the file paths changed as needed if you wanted to deploy the vendor provided VNC dmg directly.

 

#!/bin/bash

#*=============================================================================
#* FUNCTION LISTINGS
#*=============================================================================

ActiveUser=`ls -l /dev/console \
    | awk '{ print $3 }' \
    | tr "[a-z]" "[A-Z]"`
ActiveUserRealName=`dscl . -read /Users/$ActiveUser \
    | grep RealName: \
    | cut -c11-`
if [[ -z $ActiveUserRealName ]]; then
    ActiveUserRealName=`dscl . -read /Users/$ActiveUser \
    | awk '/^RealName:/,/^RecordName:/' \
    |sed -n 2p | cut -c 2-`
fi

echo "$ActiveUser"

## Define global Variables

    dmgName="/users/$ActiveUser/desktop/Apple_Xcode_15.4.dmg" #Name of the DMG to be mounted
    dmgPath="/users/$ActiveUser/desktop/Apple_Xcode_15.4.dmg" #Location of the DMG to be mounted, if deployed by JAMF it will be in /Library/Application Support/JAMF/Waiting Room
    intallerPath="/Volumes/Apple_Xcode_15.4/private/tmp/RGBK/Xcode_15.4.app" #Path to the MacOS Installer App within the DMG
    installerDestination="/Applications/" #Path to where the MacOS Installer App is to be moved
    volumeName="/Volumes/Apple_Xcode_15.4" #Name of the mounted volume

## Mount DMG file with no browse to hide the desktop icon
    echo "...Mounting $dmgName in sudo hdiutil attach /users/$ActiveUser/desktop/Apple_Xcode_15.4.dmg"
    sudo hdiutil attach "$dmgName" -nobrowse
    

## Install PKG
    echo "Copying XCode to /Applications"
    sudo cp -R  "$intallerPath" "$installerDestination"

## Wait 20 seconds to allow for package to transfer
    #sleep 360 Not cu

## Unmount DMG
    echo "Unmounting $volumeName"
    sudo hdiutil unmount "$volumeName"

## Wait 20 sec to make sure DMG unmounts
    sleep 20 

## Delete DMG
    sudo rm -rfv "$dmgPath"
    
echo "finished"

 

sdagley
Esteemed Contributor II

@tdenton If you're looking to create VLC packages for distribution via Jamf Pro do yourself a favor and check out the combination of AutoPkg and AutoPkgr to automate creation of new packages as new versions of apps are released.