Category filter
Script to install the latest Firefox version on macOS devices
Firefox prioritizes user’s privacy, security, and provides customization options for browsing according to the user’s preferences which makes it ideal for enterprise use. The script in the document ensures that the device is installed with the latest version of Firefox. Administrators can use the script to remotely install the latest Firefox on macOS devices using Hexnode’s Execute Custom Script remote action.
Scripting Language – Shell
File extension – .sh
Shell script
Install the latest Firefox version on macOS devices
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
if [ -d "/Applications/Firefox.app" ]; then echo "Firefox is already installed." exit 0 fi firefox_url="https://download.mozilla.org/?product=firefox-latest&os=osx&lang=en-US" download_dir="$HOME/Applications" mkdir -p "$download_dir" echo "Downloading Firefox..." curl -L -o "$download_dir/Firefox.dmg" "$firefox_url" echo "Mounting the Firefox disk image..." hdiutil attach "$download_dir/Firefox.dmg" echo "Installing Firefox..." cp -r "/Volumes/Firefox/Firefox.app" "/Applications/" echo "Unmounting the Firefox disk image..." hdiutil detach "/Volumes/Firefox" echo "Cleaning up..." rm "$download_dir/Firefox.dmg" echo "Firefox installation complete." exit 0 |
The above script checks whether the directory “/Applications/Firefox.app” exists or not to verify if the app is present on the device. If Firefox is installed already on the device, the script exits with a success status (‘exit 0’). If Firefox is not installed on the device, the script initiates the download of the latest version by fetching the URL stored in the ‘firefox_url’ variable. The ‘download_dir’ variable specifies the path on the device where the Firefox installer will be downloaded. In this case, the installer is downloaded to the user’s home directory under the ‘Applications’ folder.
‘curl’ is a command-line tool used to make network requests through terminal. In this script, ‘curl’ is used to download Firefox from the specified URL. The ‘-L’ parameter instructs the ‘curl’ command to follow any HTTP redirects, ensuring it completes the download. The ‘-o’ parameter specifies the filename for the downloaded content. ‘hdutil’ mounts the downloaded disk image.
‘cp -r “/Volumes/Firefox/Firefox.app” “/Applications/”’ is used for copying the Firefox application from the mounted disk.
After executing the script successfully, the output can be seen from the Action History.