Worklet: Ensuring Firefox is installed on Mac devices

This worklet will evaluate Mac devices to ensure the latest version of Firefox is installed. If the worklet finds the Firefox applications is not installed, the remediation code will install it on the device.

Evaluation:

#!/bin/bash
#example script for installing Firefox on Mac devices

#evaluate the device to see if Firefox is currently installed.  
if [ -d "/Applications/firefox.app" ]; then
        exit 0
else
        exit 1
fi

Remediation:

#!/bin/bash
#example script for installing Firefox on Mac devices

#create a temporary directory to download Firefox install file
set -e
tempfile=$(mktemp)

#download the latest version of Firefox to the temp file
echo "Downloading Firefox..."
curl -L "https://download.mozilla.org/?product=firefox-latest&os=osx&lang=en-US" -o "$tempfile"
echo "Installing Firefox..."

#mount the firefox dmg file to a volume 
hdiutil attach /tmp/Firefox.dmg

#copy the firefox app to the devices applications 
cp -R /Volumes/Firefox/Firefox.app/ /Applications/Firefox.app

#remove tmp file and unmount the image from the volume
echo "Cleaning up..."

hdiutil detach /Volumes/Firefox/ -quiet
sleep 2

rm -f "$tempfile"
4 Likes

Two things caught my eye:

“Google firefox.app” looks wrong?

And the URL to get the most recent version of Firefox for OS X would be something like so: https://download.mozilla.org/?product=firefox-latest&os=osx&lang=en-US

2 Likes

It looks like Adam is pulling from their CDN directly, which might explain the different URL.

1 Like

I think you’re right on the “Google firefox.app” - I’ll fix that to just say “firefox.app”

1 Like

I typed that in by accident when adding comments. Please make the change.

2 Likes

Made the change

1 Like

Thanks @awhitman!

1 Like

This is correct, but I can update it to the Mozilla URL

1 Like

I wonder if the CDN has a most recent URL too. I went by the instructions that I found on their FTP server. Old school.

https://ftp.mozilla.org/pub/firefox/releases/latest/README.txt

2 Likes

had issues curling the latest version URL. Direct pull from CDN and I will update the latest URL link

1 Like

This is for the .exe which would work. Just need to change the syntax to run the .exe instead of mounting the .dmg to a volume.

1 Like

It’s already live - people are getting to see the sausage made in real time :slight_smile:

1 Like

This cURL command worked for me. But I did not try it in the sausage machine.

curl “https://download.mozilla.org/?product=firefox-latest&os=osx&lang=en-US” > “Firefox.dmg”

1 Like

Worked for me too! Must have clicked the wrong link. Made the change and tested it. Should be good to go!

3 Likes

And that is how quickly we fix stuff at Automox :slight_smile:

Thanks for the speedy response guys!

3 Likes

Sudo isn’t required in this context as the agent runs as root user. It will actually change the environment if you use it here.

That curl command will return an HTML document as that address is a CDN so you need to follow links with curl -L <address>

hdiutil can return errors if that URL returns a bad value and may not error the way you like.

Shouldn’t the remediation script also return 1 or 0?

3 Likes

Hi, I am trying to use the firefox worklet but I am getting this error:
% Total % Received % Xferd Average Speed Time Time Time Current Dload Upload Total Spent Left Speed 0 0 0 0 0 0 0 0 --:–:-- --:–:-- --:–:-- 0/Library/Application Support/Automox/execDir080237696/execcmd361802207: line 12: 1”: command not found curl: (6) Could not resolve host: “https

That is strange. The error implies that curl is not on the machine, but the output for the first piece is the status in curl.
% Total % Received % Xferd Average Speed Time....
Let me see if I can reproduce this behavior.

Could you check to make sure cURL is installed on the OS?

run the command curl --help and see if it returns with the help option for curl. If not, then it isn’t installed on your Mac’s OS.

To install curl follow these instructions

Once installed, try to run the Firefox install Worklet again.

If that does not work, It maybe a bad cURL install, which is why it shows the curl output in the first piece. Try to uninstall, and reinstall.

I also see Could not resolve host: “https at the end of the stderr snippet you have. This usually means that there is an issue connecting to the host provided in the curl. Can you confirm your mac device can connect to https://download.mozilla.org/?product=firefox-latest&os=osx&lang=en-US and see if it download the Firefox .dmg?

Hi Yes curl is installed.
the mac os version is 10.15.4
and yes I can run the curl download manually just fine.
thank you