Our thinking


Post-installation script for Dropbox on macOS

If you’re deploying Dropbox to multiple systems, there’s now an Enterprise Installer available from Dropbox which has a postinstall script to properly initialise the Dropbox Updater.

I’ve been deploying Dropbox and using an old script that seems to be working, however now we have an official script from Dropbox to perform this task.

You can now grab Enterprise Installers from the Dropbox Desktop Client Builds page that have the script included in the installer package:
https://www.dropboxforum.com/category/101007/discussions/101003016

Or, if for whatever reason you want to continue deploying the app from a dmg file, then you can use this as a postinstall script in your deployment workflow:

#!/bin/bash -p

set -eu

# The parameters to a pkg postinstall script are not well documented, so for the
# reader's clarification:
#
# $1 is the top-level package path
# $2 is the target (installation) location
# $3 is the target (installation) volume
# $4 is the startup disk root
readonly INSTALLATION_PATH=${2}

readonly APP_DIR="Dropbox.app"

# Uses "defaults read" to obtain the value of a key in a property list.
infoplist_read() {
  __CFPREFERENCES_AVOID_DAEMON=1 defaults read "${@}"
}

# 1. Install DropboxUpdater.

echo "Installing DropboxUpdater."

"${INSTALLATION_PATH}/${APP_DIR}/Contents/Helpers/DropboxUpdater.app/Contents/MacOS/DropboxUpdater" "--install" "--system"

# 2. Register app with DropboxUpdater via its ksadmin shim.

echo "Registering app with DropboxUpdater."

readonly APP_LOCATION="${INSTALLATION_PATH}/${APP_DIR}"
readonly APP_INFO_PLIST="${APP_LOCATION}/Contents/Info.plist"
readonly KS_VERSION_KEY="KSVersion"
readonly KS_PRODUCT_KEY="KSProductID"
readonly KS_ADMIN="/Library/Dropbox/DropboxSoftwareUpdate/DropboxSoftwareUpdate.bundle/Contents/Helpers/ksadmin"

product="$(infoplist_read "${APP_INFO_PLIST}" \
                          "${KS_PRODUCT_KEY}")"
version="$(infoplist_read "${APP_INFO_PLIST}" \
                          "${KS_VERSION_KEY}")"

ksadmin_args=(
  --register
  --productid "${product}"
  --version "${version}"
  --xcpath "${APP_LOCATION}"
  --version-path "${APP_INFO_PLIST}"
  --version-key "${KS_VERSION_KEY}"
)

"${KS_ADMIN}" "${ksadmin_args[@]}"

# 3. Disable dual installation so that Dropbox doesn't update to "~/Library/Application Support/Dropbox.app".
if [[ "${product}" == "com.getdropbox.dropbox" ]]; then
  touch "/Library/Application Support/Dropbox/disable_dual_install.dbx"
  chmod 644 "/Library/Application Support/Dropbox/disable_dual_install.dbx"
fi

Leave a Reply