Posted on 11-17-2020 02:16 PM
I have the following setup to update Google Backup and Sync app.
Run before - Quit Backup and Sync
#!/bin/bash
osascript -e 'tell application "Backup and Sync" to quit'
Run after - Install Backup and Sync
#!/bin/bash
# script pulled from JamfNation by Adam T
bundle="Backup and Sync.app"
tmp="/private/tmp/GoogleBackupAndSync"
echo "$(date): Create temporary directory"
mkdir -p "${tmp}"
echo "$(date): Download 'https://dl.google.com/drive/InstallBackupAndSync.dmg'"
curl -s -o "${tmp}"/"InstallBackupAndSync.dmg" "https://dl.google.com/drive/InstallBackupAndSync.dmg"
echo "$(date): Check downloaded DMG"
volume=$(hdiutil attach -noautoopen -noverify -nobrowse "${tmp}/InstallBackupAndSync.dmg" | egrep "Volumes" | grep -o "/Volumes/.*")
if [ "$(find "${volume}" -name "${bundle}" -execdir echo '{}' ';' -print | sed -n 1p)" == "${bundle}" ]; then
bundlepath=$(find "${volume}" -name "${bundle}" -print | sed -n 1p)
bundlename=$(find "${volume}" -name "${bundle}" -execdir echo '{}' ';' -print | sed -n 1p)
echo "$(date): '${bundle}' was found in '${bundlepath}'"
if [ ! -s "${bundlepath}" ]; then
echo "$(date): No bundle found"
rm -rf "${tmp}"
hdiutil detach $(/bin/df | /usr/bin/grep "${volume}" | awk '{print $1}') -quiet -force
exit 1
else
if [ -s "/Applications/${bundle}" ]; then
echo "$(date): Delete installed '${bundle}'"
rm -rf "/Applications/${bundle}"
fi
echo "$(date): Move '${bundlepath}' to '/Applications'"
rsync -ar "${bundlepath}" "/Applications/"
fi
echo "$(date): Unmount '${volume}'"
hdiutil detach $(/bin/df | /usr/bin/grep "${volume}" | awk '{print $1}') -quiet -force
echo "$(date): Purge temporary directory"
rm -rf "${tmp}"
else
rm -rf "${tmp}"
exit 1
fi
exit 0
~~#!/bin/sh~~
My policy log shows the following:
[STEP 1 of 6]
Executing Policy Google Backup and Sync from the internet - Self Service
[STEP 2 of 6]
Running script Quit Backup and Sync app...
Script exit code: 1
Script result: 38:42: execution error: Backup and Sync got an error: User canceled. (-128)
Error running script: return code was 1.
[STEP 3 of 6]
Running script Install Google Backup and Sync...
Script exit code: 0
Script result: Tue Nov 17 14:31:06 CST 2020: Create temporary directory
Tue Nov 17 14:31:06 CST 2020: Download 'https://dl.google.com/drive/InstallBackupAndSync.dmg'
Tue Nov 17 14:31:09 CST 2020: Check downloaded DMG
Tue Nov 17 14:31:10 CST 2020: 'Backup and Sync.app' was found in '/Volumes/Install Backup and Sync from Google/Backup and Sync.app'
Tue Nov 17 14:31:10 CST 2020: Delete installed 'Backup and Sync.app'
Tue Nov 17 14:31:10 CST 2020: Move '/Volumes/Install Backup and Sync from Google/Backup and Sync.app' to '/Applications'
Tue Nov 17 14:31:21 CST 2020: Unmount '/Volumes/Install Backup and Sync from Google'
Tue Nov 17 14:31:21 CST 2020: Purge temporary directory
[STEP 4 of 6]
Running script Open Backup and Sync...
Script exit code: 0
Script result:
[STEP 5 of 6]
[STEP 6 of 6]
Why won't my osascript close the app?
What alternative do you recommend?