Script to always download the latest version of dropbox???

ooshnoo
Valued Contributor

Anyone gotta script that will automatically download the latest version of Dropbox?

As the app is constantly updated, I'd like to have self service and enrollment policy that will always grab the latest version, but their download link does not lead to a specific DMG or package. With other apps I do this via CURL, but that doesn't seem to be an option here.

https://www.dropbox.com/download?os=mac

3 ACCEPTED SOLUTIONS

mm2270
Legendary Contributor III

@ooshnoo Try the syntax below. Like many vendor sites, the URL they provide is a redirect link, so you need to use the -L or --location option to have curl redirect to the actual link. Also, in my quick experimentation it seems to need an agent string so it believes the request is coming from a browser and not the Terminal. It will download without that, but the dmg comes down corrupt and won't open unless I add the agent string.

curl -A "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_4) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/12.1 Safari/605.1.15" -L https://www.dropbox.com/download?os=mac > /private/tmp/DropBoxInstaller.dmg

Using the above I was able to get the dmg to download into /private/tmp/ and was able to successfully mount it.

View solution in original post

tdclark
Contributor

So based on @mm2270's curl above I had a couple minutes and went out and made this... It's not pretty but it does work in Self Service

#!/bin/sh curl -A "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_4) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/12.1 Safari/605.1.15" -L https://www.dropbox.com/download?os=mac > /Users/Shared/DropBoxInstaller.dmg hdiutil attach /Users/Shared/DropBoxInstaller.dmg open -g "/Volumes/Dropbox Installer/Dropbox.app" hdiutil detach /Volumes/Dropbox Installer/ rm -rf /Users/Shared/DropBoxInstaller.dmg exit 0

View solution in original post

ooshnoo
Valued Contributor

Thanks guys! worked perfectly!!!

#!/bin/sh
curl -A "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_4) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/12.1 Safari/605.1.15" -L https://www.dropbox.com/download?os=mac > /var/tmp/DropBoxInstaller.dmg
hdiutil attach /var/tmp/DropBoxInstaller.dmg
cd /Volumes/Dropbox Installer/Dropbox.app/Contents/MacOS/
./Dropbox Installer
hdiutil detach /Volumes/Dropbox Installer/
rm -rf /var/tmp/DropBoxInstaller.dmg
exit 0

View solution in original post

39 REPLIES 39

Danko
New Contributor III

I guess Dropbox will update itself after the initial install. No admin rights needed for this process - it will be done in the background.

mm2270
Legendary Contributor III

@ooshnoo Try the syntax below. Like many vendor sites, the URL they provide is a redirect link, so you need to use the -L or --location option to have curl redirect to the actual link. Also, in my quick experimentation it seems to need an agent string so it believes the request is coming from a browser and not the Terminal. It will download without that, but the dmg comes down corrupt and won't open unless I add the agent string.

curl -A "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_4) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/12.1 Safari/605.1.15" -L https://www.dropbox.com/download?os=mac > /private/tmp/DropBoxInstaller.dmg

Using the above I was able to get the dmg to download into /private/tmp/ and was able to successfully mount it.

tdclark
Contributor

So based on @mm2270's curl above I had a couple minutes and went out and made this... It's not pretty but it does work in Self Service

#!/bin/sh curl -A "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_4) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/12.1 Safari/605.1.15" -L https://www.dropbox.com/download?os=mac > /Users/Shared/DropBoxInstaller.dmg hdiutil attach /Users/Shared/DropBoxInstaller.dmg open -g "/Volumes/Dropbox Installer/Dropbox.app" hdiutil detach /Volumes/Dropbox Installer/ rm -rf /Users/Shared/DropBoxInstaller.dmg exit 0

ooshnoo
Valued Contributor

Thanks guys! worked perfectly!!!

#!/bin/sh
curl -A "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_4) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/12.1 Safari/605.1.15" -L https://www.dropbox.com/download?os=mac > /var/tmp/DropBoxInstaller.dmg
hdiutil attach /var/tmp/DropBoxInstaller.dmg
cd /Volumes/Dropbox Installer/Dropbox.app/Contents/MacOS/
./Dropbox Installer
hdiutil detach /Volumes/Dropbox Installer/
rm -rf /var/tmp/DropBoxInstaller.dmg
exit 0

This article is a bit old. Only know if this still works for Mac OS 12 and/or  M1 machines? 

 

Check the script posted by KretZoR on ‎08-03-2021 01:45 PM.  That version was tested on M1s and Big Sur, and will probably work on Monterey as well.

CoMb0BrEaKeR
New Contributor II

Hi. Tying these scripts on our standard users and during execution in self service diskutil asks for the admin password. Dropbox does seem to install then the Dropbox disk image also cannot be unmounted unless you enter the admin password. We are on Jamf 15 and MacOS 10.14.6

fcfbe7a0346b4bf89b860d2d228224d1

ctw
New Contributor III

I'm also getting the diskutil error or the installer is just crashing and not letting me continue.

agetz
Contributor

I think there is an issue with trying to install with the self updating version. I am currently working on using the 'offline' installer which looks to be the full app so I have it packaged up to put it in the applications folder. Happened upon the windows version and dug around for the mac version. Hope this is helpful.

https://www.dropbox.com/downloading?full=1&os=mac

Senthil_kumar
New Contributor II

Hi,

I tried the same script it doesn't work

KretZoR
New Contributor III

I tried the script too and it didn't work. I added another URL to the full app:
"https://www.dropbox.com/download?full=1&plat=mac"

I changed download URL, unmount behavior and added functions and checks

The script works as an Dropbox updater too (if the built in updater doesn't work)!

#!/bin/bash

###############################################################################################################################################
#
#                   Install or Update Dropbox
#
# Created By:   Jamf Nation
# Description:  Installs or updates Dropbox
# Prerequisites: None
#
###############################################################################################################################################
#
# HISTORY
#   
#   Version: 1.1
#
#   - v1.0 Jamf Nation, 2019-11-07 : https://www.jamf.com/jamf-nation/discussions/32726/script-to-always-download-the-latest-version-of-dropbox
#   - v1.1 Martin Kretz, 2020-02-27 : Changed download URL, unmount behavior and added functions and checks
# 
################################################################################################################################################

# Get current user
currentUser=$(scutil <<< "show State:/Users/ConsoleUser" | awk '/Name :/ && ! /loginwindow/ { print $3 }')

# Curl variables
DownloadURL="https://www.dropbox.com/download?full=1&plat=mac"
MountPath="/var/tmp/DropBox Installer.dmg"
UserAgent="Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_3) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/12.1 Safari/605.1.15"

# Function to copy application from mounted DMG to local Applications folder
CopyApp ()
{
    rm -fR "/Applications/Dropbox.app"
    Copy=$(cp -R "/Volumes/Dropbox Offline Installer/Dropbox.app" "/Applications/Dropbox.app")
    if $Copy;then
        echo "INFO - Application copied to local Applications folder"
    else 
        echo "ERROR- Could not copy files from mounted DMG to local Applications folder"
        exit 1
    fi
}

# Function to check if application is running
CheckRunning ()
{
    # If Dropbox is running kill its processes
    if pgrep "Dropbox";then
        echo "INFO - Application is currently running, trying to kill application processes"
        AppKill=$(killall "Dropbox";sleep 5)

        # If Dropbox kill successfull function "CopyApp" will run else script will stop with error
        if $AppKill;then
            echo "INFO - Application kill confirmed!"
            CopyApp
        else
            echo "ERROR - Could not kill application"
            exit 1
        fi
    else
        echo "INFO - Application is not running. Proceeding with install/update..."
        CopyApp
    fi
}

# Function to check if application is installed
CheckInstalled ()
{
    if [ -e "/Applications/Dropbox.app" ]; then
        echo "INFO - Application installed, checking versions."

        # Get current version of Dropbox
        DropboxCurrentVersion=$(defaults read "/Applications/Dropbox.app/Contents/Info.plist" CFBundleShortVersionString | sed -e 's/.//g')
        echo "INFO - Current version is: $DropboxCurrentVersion"

        # Get latest version of Dropbox
        DropboxLatestVersion=$(defaults read "/Volumes/Dropbox Offline Installer/Dropbox.app/Contents/Info.plist" CFBundleShortVersionString | sed -e 's/.//g')
        echo "INFO - Latest version is: $DropboxLatestVersion"

        # If current version is lower than latest version run function "CheckRunning" else end script successfull
        if [ "$DropboxCurrentVersion" -lt "$DropboxLatestVersion" ]; then
            # Copy application from mounted DMG to local Applications folder
            echo "INFO - Latest version newer than current version. Update will begin!"
            CheckRunning
        else
            echo "INFO - Current version same or higher than latest stable version. No update needed!"
            exit 0
        fi

    else
        echo "INFO - Appication not installed. Installation will begin!"
        CheckRunning
    fi

}

# Download DMG from vendor
echo "INFO - Downloading DMG"
curl -A "$UserAgent" -L "$DownloadURL" > "$MountPath"

# Mount DMG
echo "INFO - Mounting DMG"
hdiutil attach "$MountPath" -nobrowse

# Check if application is already installed
echo "INFO - Checking if application is installed"
CheckInstalled

# Change to other directory than installer to prevent unmount to fail
echo "INFO - Changing to other directory than installer to prevent unmount to fail"
cd /var/tmp/

# Unmount DMG
echo "INFO - Unmounting DMG"
hdiutil detach /Volumes/Dropbox Offline Installer/ -force

# Remove temporary files
echo "INFO - Removing temporary files"
rm -rf "$MountPath"

# Start application
echo "INFO - Starting application"
open -a /Applications/Dropbox.app

exit 0

Fuentes
New Contributor

Hey KretZoR,

First and foremost - thanks a bunch for the share of your script! I'm trying to implement it, however, I get the following log returned when I try to execute it:

The application /Applications/Dropbox.app cannot be opened for an unexpected reason, error=Error Domain=NSCocoaErrorDomain Code=260 "The file “Dropbox.app” couldn’t be opened because there is no such file." UserInfo={NSURL=file:///Applications/Dropbox.app, NSFilePath=/Applications/Dropbox.app, NSUnderlyingError=0x13ce1c330 {Error Domain=NSPOSIXErrorDomain Code=2 "No such file or directory"}}

I tried going through your script to see if there's anything obvious that I may have overlooked, however, I'm either blind or simply can't find what's wrong that is preventing from locating the directory in question.

Any suggestions?

Thanks in advance!

mburchett-zymer
New Contributor II

For clarification, if you're trying this on an M1 on Big Sur, this is the error that I got which is why the rest of the script isn't able to complete the install.

INFO - Mounting DMG
hdiutil: attach failed - image not recognized

So it's not mounting the DMG correctly or at all. Since there was no DMG mounted, there was no way to proceed forward with copying the .app and thus the final portion of the script is unable to open the application as it can't find it.

I tested to see if the DMG being downloaded was the problem and it looks like it might be. I replaced the dropbox URL in the script to uploaded file to JCDS server and used the URL generated from that to download from our Jamf cloud repo. The DMG mounted fine and installed correctly. Not ideal, but maybe it's something to do with Dropbox?

KretZoR
New Contributor III

Hi @Fuentes and @mburchett-zymergen,

I've checked the script again and the reason that it doesn't work is because of how Dropbox publishes the dmg, the URL has changed. I've changed the script to make it work, how I get the latest stable version number is not pretty but it works. It should work on both Intel and M1 processors. Try it and come back to me if there are any issues. :)

#!/bin/bash

###############################################################################################################################################
#
#                   Install or Update Dropbox
#
# Created By:   Jamf Nation
# Description:  Installs or updates Dropbox
# Prerequisites: None
#
###############################################################################################################################################
#
# HISTORY
#   
#   Version: 1.2
#
#   - v1.0 Jamf Nation, 2019-11-07 : https://www.jamf.com/jamf-nation/discussions/32726/script-to-always-download-the-latest-version-of-dropbox
#   - v1.1 Martin Kretz, 2020-02-27 : Changed download URL, unmount behavior and added functions and checks
#   - v1.2 Martin Kretz, 2021-03-24 : Added StableVersion variable to populate the new download URL
# 
################################################################################################################################################

# Get current user
currentUser=$(scutil <<< "show State:/Users/ConsoleUser" | awk '/Name :/ && ! /loginwindow/ { print $3 }')

# Get latest stable Dropbox version
StableVersion=$(curl -s 'https://www.dropboxforum.com/t5/forums/filteredbylabelpage/board-id/101003016/label-name/stable%20build' | grep -m "1" -a "Stable Build" | sed -e 's/.*Build(.*).*/1/' | sed -e 's/<[^>]*>//g' | sed 's/^ *//g')

# Curl variables
DownloadURL="https://clientupdates.dropboxstatic.com/dbx-releng/client/Dropbox%20$StableVersion.dmg"
MountPath="/var/tmp/DropBox Installer.dmg"
UserAgent="Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_3) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/12.1 Safari/605.1.15"

# Function to copy application from mounted DMG to local Applications folder
CopyApp ()
{
    rm -fR "/Applications/Dropbox.app"
    Copy=$(cp -R "/Volumes/Dropbox Offline Installer/Dropbox.app" "/Applications/Dropbox.app")
    if $Copy;then
        echo "INFO - Application copied to local Applications folder"
    else 
        echo "ERROR- Could not copy files from mounted DMG to local Applications folder"
        exit 1
    fi
}

# Function to check if application is running
CheckRunning ()
{
    # If Dropbox is running kill its processes
    if pgrep "Dropbox";then
        echo "INFO - Application is currently running, trying to kill application processes"
        AppKill=$(killall "Dropbox";sleep 5)

        # If Dropbox kill successfull function "CopyApp" will run else script will stop with error
        if $AppKill;then
            echo "INFO - Application kill confirmed!"
            CopyApp
        else
            echo "ERROR - Could not kill application"
            exit 1
        fi
    else
        echo "INFO - Application is not running. Proceeding with install/update..."
        CopyApp
    fi
}

# Function to check if application is installed
CheckInstalled ()
{
    if [ -e "/Applications/Dropbox.app" ]; then
        echo "INFO - Application installed, checking versions."

        # Get current version of Dropbox
        DropboxCurrentVersion=$(defaults read "/Applications/Dropbox.app/Contents/Info.plist" CFBundleShortVersionString | sed -e 's/.//g')
        echo "INFO - Current version is: $DropboxCurrentVersion"

        # Get latest version of Dropbox
        DropboxLatestVersion=$(defaults read "/Volumes/Dropbox Offline Installer/Dropbox.app/Contents/Info.plist" CFBundleShortVersionString | sed -e 's/.//g')
        echo "INFO - Latest version is: $DropboxLatestVersion"

        # If current version is lower than latest version run function "CheckRunning" else end script successfull
        if [ "$DropboxCurrentVersion" -lt "$DropboxLatestVersion" ]; then
            # Copy application from mounted DMG to local Applications folder
            echo "INFO - Latest version newer than current version. Update will begin!"
            CheckRunning
        else
            echo "INFO - Current version same or higher than latest stable version. No update needed!"
            exit 0
        fi

    else
        echo "INFO - Appication not installed. Installation will begin!"
        CheckRunning
    fi

}

# Download DMG from vendor
echo "INFO - Downloading DMG"
curl -A "$UserAgent" -L "$DownloadURL" > "$MountPath"

# Mount DMG
echo "INFO - Mounting DMG"
hdiutil attach "$MountPath" -nobrowse

# Check if application is already installed
echo "INFO - Checking if application is installed"
CheckInstalled

# Change to other directory than installer to prevent unmount to fail
echo "INFO - Changing to other directory than installer to prevent unmount to fail"
cd /var/tmp/

# Unmount DMG
echo "INFO - Unmounting DMG"
hdiutil detach /Volumes/Dropbox Offline Installer/ -force

# Remove temporary files
echo "INFO - Removing temporary files"
rm -rf "$MountPath"

# Start application
echo "INFO - Starting application"
open -a /Applications/Dropbox.app

exit 0

RobL
New Contributor
New Contributor

@KretZoR
I'm going thru this process as a training exercise and I hit the same issue as amorrisuk below.  I figured out that the issue is that the $StableVersion variable has "Stable Build" on the front end of it, which isn't part of the URL for the download path.  I fixed it for myself by adding another line to remove Stable Build from the variable (it might be better to prevent the grep from appending it to the variable in the first place, but my bash-fu is weak.

StableVersion=${StableVersion//"Stable Build "/}

julienvs
New Contributor III

Thanks a lot @KretZoR !

amorrisuk
New Contributor II

When i try and run the above script i get these errors:

hdiutil: attach failed - image not recognized
INFO - Checking if application is installed
INFO - Appication not installed. Installation will begin!
INFO - Application is not running. Proceeding with install/update...
cp: /Volumes/Dropbox Offline Installer/Dropbox.app: No such file or directory
INFO - Application copied to local Applications folder
INFO - Changing to other directory than installer to prevent unmount to fail
INFO - Unmounting DMG
hdiutil: detach failed - No such file or directory
INFO - Removing temporary files
INFO - Starting application
The application /Applications/Dropbox.app cannot be opened for an unexpected reason, error=Error Domain=NSCocoaErrorDomain Code=260 "The file “Dropbox.app” couldn’t be opened because there is no such file." UserInfo={NSURL=file:///Applications/Dropbox.app, NSFilePath=/Applications/Dropbox.app, NSUnderlyingError=0x7ffd98d08590 {Error Domain=NSPOSIXErrorDomain Code=2 "No such file or directory"}}

DennisMX
Contributor II

@amorrisuk Apparently DB changed the download location.
If you use the script provided by @KretZoR a few post above (posted 3/24/2021) it will work again

sam_clark
New Contributor III

It's possible to download the full offline installer for macOS with the following link: https://www.dropbox.com/download?full=1&plat=mac

Copying the contents without launching as root user (from the install script) avoids the need to enter admin creds to complete the installation in my experience. If a user launches, things work fine.

techgeek
New Contributor III

@sam_clark is there any chance you could share your script? This could be version 1.3 of the present script (last modified by @KretZoR)

I'm seeing the same issue in our environment where we use the v1.2 Dropbox script but end user are still getting a prompt for admin rights "Please enter your computer password for Dropbox to work properly"

Screenshot 2021-07-28 at 10.47.38.png

KretZoR
New Contributor III

Hi!

Are you running the script directly on a Mac or through a policy with Jamf? What OS version are you trying to run on?

/ Martin

sam_clark
New Contributor III

@techgeek , sure thing, this is a general purpose script so you will need to tailor it to your liking. It works in my environment so be sure to test first in yours 😉

 

#!/bin/zsh
#
# Created Aug 26 2020 by J Samuel Clark
# - Downloads a DMG file to extract an app or PKG and install on the user's computer
#
# Updated Oct 21 2020 by J Samuel Clark
# - Added support to quit application before installing
#
# Updated Mar 11 2021 by J Samuel Clark
# - Added support to verify retry download upon failure
# 
########################################################################
# About this program
#
# Variables which must be defined in Jamf Pro 
#
# "$4" Represents the URL from where the DMG will be downloaded
# "$5" Represents what the DMG will be named after being downloaded
# "$6" The exact name of a .app file within the downloaded DMG
# "$7" The exact name of a .pkg within the downloaded DMG
#  
# NOTE: A parameter must be set in either "$6" OR "$7", the script will
# fail otherwise. Enjoy!
#
########################################################################
# Defining variables - DO NOT MODIFY
########################################################################
downloadUrl="$4"	# The URL must return a file
dmgName="$5"	# The name of the file after it's downloaded
appName="$6"	# Name of the .app file within the DMG
pkgName="$7"	# Name of the .pkg file within the DMG
downloadLocation="/private/tmp"		# Where the file gets downloaded
applicationDmg="${downloadLocation}/${dmgName}"	# The location and name of the downloaded file
mountPoint="/Volumes/${dmgName}"
loggedInUser=$(/usr/bin/stat -f%Su /dev/console)

# Preliminary checks
if [[ -n "${appName}" ]] && [[ -z "${pkgName}" ]]; then 	
	installApp="$6"
elif [[ -n "${pkgName}" ]] && [[ -z "${appName}" ]]; then
	installApp="$7"
elif [[ -z "${appName}" ]] && [[ -z "${pkgName}" ]]; then
	echo "Nothing found in parameters, exiting"
	exit 1
elif [[ -n "${appName}" ]] && [[ -n "${pkgName}" ]]; then 
	echo "Too many parameters set, exiting"
	exit 1
fi

function downloadAndMount() {
# Attempt to download and mount DMG up to 3 times
	local TRY=1
	local downloadSuccessful=1
	while [[ ${downloadSuccessful} -ne 0 ]] && [[ ${TRY} -le 3 ]]; do
		#Remove old download if present
		if [[ -a "${applicationDmg}" ]]; then
			/bin/rm "${applicationDmg}"
		fi

		#Download application
		echo "Downloading ${appName}, attempt ${TRY}"
		/usr/bin/curl -sL "${downloadUrl}" -o "${applicationDmg}"

		#Attempt to mount
		/usr/bin/hdiutil attach "${applicationDmg}" -mountpoint "${mountPoint}" -nobrowse
		
		#Verify download integrity
		local downloadSuccessful=$(/bin/ls "${mountPoint}" | grep "${appName}" &>/dev/null; echo $?)
		
		#Check download contents
		if [[ ${downloadSuccessful} == "0" ]]; then
			echo "Application downloaded successfully, installing"
			return
		else
			#Add to counter
			(( TRY++ ))
			if [[ ${TRY} -le "2" ]]; then
				echo "Application ${appName} invalid on attempt ${TRY}, trying again"
				/usr/bin/hdiutil detach "${mountPoint}"
			elif [[ ${TRY} -eq "3" ]]; then
				echo "Attempting one last time to download ${appName}"
				/usr/bin/hdiutil detach "${mountPoint}"
			else 
				continue
			fi
		fi
		
	done

	echo "Download failed, exiting with error code 1"
	/bin/rm "${applicationDmg}"
	exit 1
	
}

########################################################################
# Begin program - HOLD ONTO BUTTS
########################################################################
# Download and attempt to mount DMG
downloadAndMount

# Choose which installation to run
installType=$( echo "$installApp" | cut -d '.' -f2 )
case "${installType}" in
	app )
		# Killing and copying .app to /Applications folder
		killApp=$(echo "$installApp" | cut -d '.' -f1 )
		if [[ -n $(pgrep "${killApp}") ]]; then
			echo "Killing process ${killApp}"
			/usr/bin/killall "${killApp}"
		fi

		echo "Copying ${appName} to Applications folder"

		#Remove old instance of application
		if [[ -a "/Applications/${appName}" ]]; then
			echo "Removing old instance of ${appName}"
			/bin/rm -r "/Applications/${appName}"
		fi

		#Checking if user is admin or standard and setting permissions
		if [[ -n $(id -Gn "${loggedInUser}" | grep "admin") ]]; then
			echo "Installing app with admin rights"
			/bin/cp -pR "${mountPoint}/${appName}" "/Applications"
        	/bin/chmod 755 "/Applications/${appName}"
        	/usr/sbin/chown -R root:wheel "/Applications/${appName}"

        else
        	echo "Installing ${appName} with rights for standard user"
        	/bin/cp -pR "${mountPoint}/${appName}" "/Applications"
        	/bin/chmod 755 "/Applications/${appName}"
        	/usr/sbin/chown -R "${loggedInUser}":wheel "/Applications/${appName}"

        fi
		;;

	pkg )
		# Installing .pkg within DMG to /
		echo "Installing ${pkgName}"
		installer -pkg "${mountPoint}/${pkgName}" -target /
		;;
	* )
		echo "Nothing to install"
		;;
esac

# Cleanup
/usr/bin/hdiutil detach "${mountPoint}"
/bin/rm "${applicationDmg}"

exit $?

techgeek
New Contributor III

Thanks @sam_clark, that will help greatly.

I noticed you are not incorporating a version check, as the script simply does an install if run. Whereas the earlier script can be used for both new-install and update environments and only installs the latest when necessary (useful on Macs when Dropbox hasn't been run in a long time and can't auto update itself).

I'll see if I can incorporate both scripts into what I need to achieve.

Many thanks again! 👍

techgeek
New Contributor III

@

KretZoR
New Contributor III

Hi everyone,

I have after your input created a new version of the script (version 1.3) to handle the issues that @RobL and @techgeek found. I have "borrowed" some code from your general purpose script @sam_clark  to solve one of the issues 😉

#!/bin/bash

###############################################################################################################################################
#
#               	Install or Update Dropbox
#
# Created By: 	Jamf Nation
# Description: 	Installs or updates Dropbox
# Prerequisites: None
#
###############################################################################################################################################
#
# HISTORY
#	
#	Version: 1.3
#
# 	- v1.0 Jamf Nation, 2019-11-07 : https://www.jamf.com/jamf-nation/discussions/32726/script-to-always-download-the-latest-version-of-dropbox
#	- v1.1 Martin Kretz, 2020-02-27 : Changed download URL, unmount behavior and added functions and checks
#	- v1.2 Martin Kretz, 2021-03-24 : Added StableVersion variable to populate the new download URL
#	- v1.3 Martin Kretz, 2021-08-03 : Fixed issue with variable "StableVersion" having text "Stable Build" in front (thanks "RobL" at Jamf Nation for finding the issue). Fixed issue with standard user not being able to open app without authentication (thanks "sam_clark" at Jamf Nation for solving the issue in your general purpose install script)
# 
################################################################################################################################################

# Get current user
currentUser=$(scutil <<< "show State:/Users/ConsoleUser" | awk '/Name 😕 && ! /loginwindow/ { print $3 }')

# Get latest stable Dropbox version
StableVersion=$(curl -s 'https://www.dropboxforum.com/t5/forums/filteredbylabelpage/board-id/101003016/label-name/stable%20build' | grep -m "1" -a "Stable Build" | sed -e 's/.*Build\(.*\).*/\1/' | sed -e 's/<[^>]*>//g' | sed 's/^ *//g')

# Curl variables
DownloadURL="https://clientupdates.dropboxstatic.com/dbx-releng/client/Dropbox%20$StableVersion.dmg"
MountPath="/var/tmp/DropBox Installer.dmg"
UserAgent="Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_3) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/12.1 Safari/605.1.15"

# Empty variable to populate with "yes" if current user is admin user
Admin=""

# Function to check if user is admin user
CheckAdmin ()
{
	# Checking if user is admin
	if [[ -n $(id -Gn "${currentUser}" | grep "admin") ]]; then
		Admin="$Admin yes"
	fi
}	
	
# Function to copy application from mounted DMG to local Applications folder
CopyApp ()
{
	# Checking if user is admin
	CheckAdmin
	
	# Remove earlier versions of Dropbox
	rm -fR "/Applications/Dropbox.app"
	
	# Copy app file to applications folder
	Copy=$(cp -R "/Volumes/Dropbox Offline Installer/Dropbox.app" "/Applications/Dropbox.app")
	if $Copy;then
		echo "INFO - Application copied to local Applications folder"
	else 
		echo "ERROR- Could not copy files from mounted DMG to local Applications folder"
		exit 1
	fi
	
	# Set perimssions to app file
	/bin/chmod 755 "/Applications/Dropbox.app" && echo "INFO - Permissions set"
	
	# Set owner to app file depending on user type
	if /bin/echo "$Admin" | grep yes;then
		echo "INFO - User is admin, setting admin rights to app"
		/usr/sbin/chown -R root:wheel "/Applications/Dropbox.app"
	else
		echo "INFO - User is standard, setting standard rights to app"
		/usr/sbin/chown -R "${currentUser}":wheel "/Applications/Dropbox.app"
	fi
}

# Function to check if application is running
CheckRunning ()
{
	# If Dropbox is running kill its processes
	if pgrep "Dropbox";then
		echo "INFO - Application is currently running, trying to kill application processes"
		AppKill=$(killall "Dropbox";sleep 5)
		
		# If Dropbox kill successfull function "CopyApp" will run else script will stop with error
		if $AppKill;then
			echo "INFO - Application kill confirmed!"
			CopyApp
		else
			echo "ERROR - Could not kill application"
			exit 1
		fi
	else
		echo "INFO - Application is not running. Proceeding with install/update..."
		CopyApp
	fi
}

# Function to check if application is installed
CheckInstalled ()
{
	if [ -e "/Applications/Dropbox.app" ]; then
		echo "INFO - Application installed, checking versions."

		# Get current version of Dropbox
		DropboxCurrentVersion=$(defaults read "/Applications/Dropbox.app/Contents/Info.plist" CFBundleShortVersionString | sed -e 's/\.//g')
		echo "INFO - Current version is: $DropboxCurrentVersion"

		# Get latest version of Dropbox
	    DropboxLatestVersion=$(defaults read "/Volumes/Dropbox Offline Installer/Dropbox.app/Contents/Info.plist" CFBundleShortVersionString | sed -e 's/\.//g')
		echo "INFO - Latest version is: $DropboxLatestVersion"
		
		# If current version is lower than latest version run function "CheckRunning" else end script successfull
	    if [ "$DropboxCurrentVersion" -lt "$DropboxLatestVersion" ]; then
	    	# Copy application from mounted DMG to local Applications folder
			echo "INFO - Latest version newer than current version. Update will begin!"
			CheckRunning
	    else
			echo "INFO - Current version same or higher than latest stable version. No update needed!"
			exit 0
	    fi

	else
		echo "INFO - Appication not installed. Installation will begin!"
		CheckRunning
	fi

}

# Download DMG from vendor
echo "INFO - Downloading DMG"
curl -A "$UserAgent" -L "$DownloadURL" > "$MountPath"

# Mount DMG
echo "INFO - Mounting DMG"
hdiutil attach "$MountPath" -nobrowse

# Check if application is already installed
echo "INFO - Checking if application is installed"
CheckInstalled

# Change to other directory than installer to prevent unmount to fail
echo "INFO - Changing to other directory than installer to prevent unmount to fail"
cd /var/tmp/

# Unmount DMG
echo "INFO - Unmounting DMG"
hdiutil detach /Volumes/Dropbox\ Offline\ Installer/ -force

# Remove temporary files
echo "INFO - Removing temporary files"
rm -rf "$MountPath"

# Start application
echo "INFO - Starting application"
open -a /Applications/Dropbox.app

exit 0

 

Please try it out and let me know if it works or there are any issues.
 

Ed
New Contributor II

This is a great script, but it downloads the Intel version of the app and I need the Universal version. Has anyone else reported this?

Ed
New Contributor II

version 1.3 no longer returns the latest dropbox build - the board id has changed. Are you updating this script?

 

Ed
New Contributor II

the curl command to find the latest version of Dropbox with this URL works - 

'https://www.dropboxforum.com/t5/user/viewprofilepage/user-id/308787'

KretZoR
New Contributor III

Hi all,

I have started using Installomator instead of updating this script, I suggest you do the same. It is my new go-to script for installing applications directly from the developers. It support hundreds of other applications aswell!

GitHub - Installomator/Installomator: Installation script to deploy standard software on Macs

jeremya
New Contributor II

@Krem  I just tried this and it worked perfectly. Thanks for your hard work! Also, you could change the download link to a parameter, then if they change the link you could update the parameter and not have to modify the script. Just a thought!

Great work! 

cjavallas
New Contributor

@KretZoR   I am using your sctip during provisioning with depnotify and notice a pop up claiming :

Dropbox needs to change permissions for the Folder: /var/root/.dropbox

I understand the script is running as root and assume dropbox is trying to setup for Root user...  but wondering if there is a way around this?

KretZoR
New Contributor III

Hi all,

I have started using Installomator instead of updating this script, I suggest you do the same. It is my new go-to script for installing applications directly from the developers. It support hundreds of other applications aswell!

GitHub - Installomator/Installomator: Installation script to deploy standard software on Macs

agetz
Contributor

Dredging this one back up. Here's a simple script that is working for us in Ventura. Running from Self Service with standard users.

 

 

#!/bin/sh
#Written by Aaron Getz 2/10/23

loggedInUser=$(stat -f%Su /dev/console)
loggedInUID=$(id -u "$loggedInUser")

dmgfile="DropBoxInstaller.dmg"
logfile="/Library/Logs/DropboxInstallScript.log"
url="https://www.dropbox.com/download?full=1&plat=mac"


echo "`date`: Download URL: $url" >> ${logfile}
        
/bin/echo "`date`: Downloading latest version." >> ${logfile}
curl -L "$url" > /Users/Shared/${dmgfile}        
        
/bin/echo "`date`: Mounting DMG..." >> ${logfile}   
hdiutil attach -nobrowse /Users/Shared/${dmgfile}
        
sleep 5
        
/bin/echo "`date`: Installing App..." >> ${logfile}            
cd /Volumes/Dropbox\ Offline\ Installer/Dropbox.app/Contents/MacOS/
./Dropbox
 
#Set hidden dropbox folder permissions 
chown  ${loggedInUser} /Users/${loggedInUser}/.dropbox    
chown -R  ${loggedInUser} /Users/${loggedInUser}/.dropbox        
chmod  755 /Users/${loggedInUser}/.dropbox 
chmod -R  755 /Users/${loggedInUser}/.dropbox

/bin/echo "`date`: Unmounting DMG..." >> ${logfile}
hdiutil detach /Volumes/Dropbox\ Offline\ Installer/ -force

/bin/echo "`date`: Deleting downloaded DMG..." >> ${logfile}
/bin/rm /Users/Shared/${dmgfile}
        
exit 0       

 

 

VR
New Contributor

Thanks! This script works fine on intel macs, however it installs the same intel version on Apple silicon devices as well. Have you updated the script to identify the processor and install the correct to the target?

agetz
Contributor

I added an updated version. It looks to be working for me but haven't tested it extensively.

VR
New Contributor

Hi Agetz, Thanks for your quick turn around. It works for me. I can confirm that Apple Silicon version installed to Apple silicon devices and intel version installed to intel devices respectively. Thanks again!

agetz
Contributor

Here is an updated script to include the Apple Silicon version

#!/bin/sh
#Written by Aaron Getz 2/10/23
#Updated to support native Apple Silicon installer 7/13/23

loggedInUser=$(stat -f%Su /dev/console)
loggedInUID=$(id -u "$loggedInUser")

dmgfile="DropBoxInstaller.dmg"
logfile="/Library/Logs/DropboxInstallScript.log"


# is this an ARM Mac?
arch=$(/usr/bin/arch)
if [ "$arch" == "arm64" ]; then
echo "Apple Silicon Identified"
url="https://www.dropbox.com/download?full=1&plat=mac&arch=arm64"
else
echo "Intel Based Mac Identified"
url="https://www.dropbox.com/download?full=1&plat=mac"
fi


echo "`date`: Download URL: $url" >> ${logfile}
        
/bin/echo "`date`: Downloading latest version." >> ${logfile}
curl -L "$url" > /Users/Shared/${dmgfile}            
        
/bin/echo "`date`: Mounting DMG..." >> ${logfile}   
hdiutil attach -nobrowse /Users/Shared/${dmgfile}
        
sleep 5
        
/bin/echo "`date`: Installing App..." >> ${logfile}            
cd /Volumes/Dropbox\ Offline\ Installer/Dropbox.app/Contents/MacOS/
./Dropbox
 
#Set hidden dropbox folder permissions 
chown  ${loggedInUser} /Users/${loggedInUser}/.dropbox    
chown -R  ${loggedInUser} /Users/${loggedInUser}/.dropbox        
chmod  755 /Users/${loggedInUser}/.dropbox 
chmod -R  755 /Users/${loggedInUser}/.dropbox

/bin/echo "`date`: Unmounting DMG..." >> ${logfile}
hdiutil detach /Volumes/Dropbox\ Offline\ Installer/ -force

/bin/echo "`date`: Deleting downloaded DMG..." >> ${logfile}
/bin/rm /Users/Shared/${dmgfile}
        
exit 0        

mline
New Contributor

This one prompts me for admin credentials post installing and launching :(

KretZoR
New Contributor III

Hi @mline , please use Installomator script instead. It works and supports a lot of other applications also. 
GitHub - Installomator/Installomator: Installation script to deploy standard software on Macs