Escaping Spaces in Path Name for Mac OS X for Software Deployment

Hello everyone,

I have been tasked with deploying an Avaya application for Mac and placing a config file under the User’s Library folder. The software in question in an .app package. I reused an old task and found some older posts online to craft my action script to what is shown below. My problem is that the action script fails at the line where I incorporated some error handling. I believe the issue has to do with the file name having spaces. I tried wrapping the continue if in double quotes (“”) and trying to escape the spaces with . Does the Bigfix agent utiltize a different escape character that the standard backslash? Thanks.

prefetch Avayazip.tmp sha1:9cdb9ca16ab516dd93956d8ba005c27f6dafa8a0 size:10319623 http://mybigfixserver.corp:443/Uploads/9cdb9ca16ab516dd93956d8ba005c27f6dafa8a0/Avayazip.tmp sha256:8830ddcf83e7e49f1815fb0a0dcbac01e8818c10062741a5ab4d30484b92ad62

extract Avayazip.tmp

move “{posix path of file “Avaya.zip” of folder “__Download” of client folder of current site}” “/tmp/Avaya.zip”

wait sh -c “cd /tmp”
wait sh -c “unzip Avaya.zip”
wait sh -c “mkdir -p {posix path of users folder & “/” & name of current user & “/Library/Preferences/”}Avaya”
wait /usr/bin/hdiutil attach -quiet -nobrowse -mountpoint “/tmp/AvayaInstall” “/tmp/Avaya/ASC2.0.2.3-3.dmg”

continue if {exists folder “/tmp/AvayaInstall/Avaya\ one-X\ Communicator.app”}
wait sh -c “cp /tmp/AvayaInstall/Avaya\ one-X\ Communicator.app” “/Applications”
wait sh -c “cp /tmp/Avaya/config.xml” “{posix path of users folder & “/” & name of current user & “/Library/Preferences/”}Avaya”
wait /usr/bin/hdiutil detach -force “/tmp/AvayaInstall”

wait sh -c "rm -rf /tmp/Avaya

This part will never work. You must use absolute paths and you can’t do cd /tmp because that only works in the context of that exact moment, and the following statement does not run in /tmp but rather in / since that is where all commands run by default.

In BigFix, every wait statement is like launching a brand new shell with no context from the previous executions whatsoever. This may seem annoying, but it is actually very much on purpose. If you have one wait statement change directory somewhere but forget to change it back, then you could have all kinds of cascading effects that are not intended.

You need to step through every part of the script on a computer but executing from /

Hi @jgstew,

Thanks for the reply. The clarification with the wait statements clears up some confusion I had with the correct usage. I will go back incorporate absolute paths and try again.

Also, I would recommend downloading the DMG and the config file separately instead of wrapping them up into a zip file. You may need to make many changes to the config file, or deploy a different config file to different systems.

You are wrapping a DMG in a ZIP, and then uploading it to BigFix using some sort of upload wizard that then wraps it up into a TMP file (BESAchive). This is a lot layers that are not needed. You are better off downloading the DMG directly from the vendor using a prefetch statement if possible, or otherwise placing the DMG on a webserver that the root server can access and prefetch it from there.

The config file could be sent using a create file command, or a separate prefetch statement.

This sounds more complicated, but if you are doing something like this frequently, you will be much better off in the long run figuring this out. It might not be needed in this case, since I’m sure you just want to get it to work with as little effort as possible, but it is something to keep in mind for the next time around.

I personally prefer to install the software with 1 action and configure the software with a different one. This is because I don’t always apply the same config to every install and I may want to make further config changes in the future without them being overwritten by the install or update task in the future. I also like to be able to configure the software even if it wasn’t installed by BigFix.

Quoting your paths is a good thing to do when dealing with spaces, however you’ll need to remove any of the shell escapes for spaces. Your paths current escape the space after “Avaya”

Try:

continue if {exists folder "/tmp/AvayaInstall/Avaya one-X Communicator.app"}
"cp /tmp/AvayaInstall/Avaya one-X Communicator.app" "/Applications"

@jgstew, normally I would grab the DMG directly from the vendor but this software is not freeware so I don’t have an account to directly grab the file. If I was able to get access to grab the link, what tool would you recommend to calculate the SHA values for the prefetch command?

There are many many ways to do this.

You can actually use BigFix QnA to do it using relevance: https://bigfix.me/relevance/details/2998744

I have a bookmarklet which allows me to upload files under a certain size to VirusTotal.com and then click the bookmarklet and it puts together all of the prefetch data from the VirusTotal results. See the last 2 entries on this post: Prefetch Statement (Powershell 4.0) for local files

@hansen_m has an automator action for this: Prefetch Automator Services for OS X

@rustymyer, @jgstew, I appreciate all of your help with this. In the end,I decided to follow your suggestion of separating the task of deploying the config file. After spending much of the day battling the task I finally came up with a working action script to deploy the config file ahead of of the actual software deployment. This is what I ended up using in case someone finds themselves in a similar situation.

wait sh -c “mkdir -p {posix path of users folder & “/” & name of current user & “/Library/Preferences/”}Avaya”
move “__Download/config.xml” “{posix path of users folder & “/” & name of current user & “/Library/Preferences/Avaya/”}config.xml”

You could use “folder create” in place of the wait command

https://developer.bigfix.com/action-script/reference/file/folder-create.html

2 Likes

Additionally as the other is just text replacement you could have done

move "__Download/config.xml" "{posix path of users folder & "/" & name of current user}/Library/Preferences/Avaya/config.xml"

but that wouldn’t work if the folder doesn’t already exist

Which folder? Wasn’t obvious what you’re responding to

Does folder create create the parent directories if they don’t exist like the -p flag does? Although in this case I think ~/Library/Preferences is a safe bet if it is limited to logged in GUI users.

The actionscript “folder create” will create the whole path if needed.