Hi,
I'm publishing VirtualBox and separate OS Appliance OVA's in Self Service. VirtualBox is installed nicely on client machines, but the OS Appliance is not. In the script it seems to get stuck at the stage where the appliance is imported and the script returns an error. I'd appreciate if anyone could take a look and give me some pointers on what is wrong?
OS appliance is packaged inside a DMG.
Funny thing is that the command "sudo -u $USER VBoxManage import "path to ova...." is working fine when running it when the dmg is mounted manually and visible under /Volumes.
#!/bin/bash
########################################################################################
# DEFINE VARIABLES & READ IN PARAMETERS
#########################################################################################
# HARDCODED VALUES SET HERE
Variables set by Casper - To manually override, remove the comment for the given variable
targetDrive="" # Casper will pass this parameter as "Target Drive" if left commented out
computerName="" # Casper will pass this parameter as "Computer Name" if left commented out
userName="" # Casper will pass this parameter as "User Name" if left commented out. Usernames
can only be passed if the script is triggered at login, logout, or by Self Service
Variables used for logging
logFile="/private/var/log/importOSApplianceToVBox.log"
Variables used by this script.
dmgName=""
CHECK TO SEE IF A VALUE WERE PASSED IN FOR PARAMETERS AND ASSIGN THEM
if [ "$1" != "" ] && [ "$targetDrive" == "" ]; then
targetDrive="$1"
fi
if [ "$2" != "" ] && [ "$computerName" == "" ]; then
computerName="$2"
fi
if [ "$3" != "" ] && [ "$userName" == "" ]; then
userName="$3"
fi
if [ "$4" != "" ] && [ "$dmgName" == "" ]; then
dmgName="$4"
fi
########################################################################################
# LOGGING FUNCTION
########################################################################################
log () { echo $1 echo $(date "+%Y-%m-%d %H:%M:%S: ") $1 >> $logFile }
########################################################################################
# VARIABLE VERIFICATION FUNCTION
########################################################################################
verifyVariable () {
eval variableValue=$$1
if [ "$variableValue" != "" ]; then
echo "Variable "$1" value is set to: $variableValue"
else
echo "Variable "$1" is blank. Please assign a value to the variable."
exit 1
fi
}
########################################################################################
# SCRIPT CONTENTS - DO NOT MODIFY BELOW THIS LINE
########################################################################################
Verify Variables
verifyVariable dmgName
Mount the DMG
log "Mounting the DMG $dmgName..."
mountResult=/usr/bin/hdiutil attach -noautoopen -noverify -nobrowse /Library/Application Support/JAMF/Waiting Room/$dmgName
mountVolume=echo "$mountResult" | grep Volumes | awk '{print $3}'
mountDevice=echo "$mountResult" | grep disk | head -1 | awk '{print $1}'
if [ $? == 0 ]; then
log " DMG mounted successfully as volume $mountVolume on device $mountDevice."
else
log "There was an error mounting the DMG. Exit Code: $?"
fi
Find the OVA in the DMG
ovaName=ls $mountVolume | grep "ova"
if [ $? == 0 ]; then
log " Found OVA file $ovaName on $mountVolume."
else
log "No OVA file found. Exit Code: $?"
fi
Import the OVA wrapped inside the DMG
echo "Importing OS appliance $ovaName from mount path $mountVolume..."
sudo -u $USER VBoxManage import $mountVolume/$ovaName
if [ $? == 0 ]; then
log " OS Appliance successfully imported."
else
log "There was an error importing the OS appliance. Exit Code: $?"
fi
Unmount the DMG
echo "Unmounting disk $mountDevice..."
hdiutil detach $mountDevice -force
Delete the DMG
echo "Deleting $dmgName..."
/bin/rm /Library/Application Support/JAMF/Waiting Room/$dmgName
exit