Google Backup and Sync Install Script

LovelessinSEA
Contributor II

Is someone willing to help me out? I've been using a similar script for google drive for sometime now. But with the release of backup and sync I can't seem to make this work.

#!/bin/sh -x
logfile="/Library/Logs/jss.log"
user=`ls -l /dev/console | cut -d " " -f 4`
PRODUCT="Backup and Sync from Google"
# installation

    /bin/echo "`date`: Installing Backup and Sync for $user..."  >> ${logfile} 
    dmgfile="image.dmg" 
    volname="Install Backup andy Sync for Google" 
    url="https://dl.google.com/drive/InstallBackupAndSync.dmg" 
    /bin/echo "`date`: Downloading $PRODUCT." >> ${logfile} 
    /usr/bin/curl -k -o /tmp/image.dmg $url 
    /bin/echo "`date`: Mounting installer disk image." >> ${logfile} 
    /usr/bin/hdiutil attach /tmp/image.dmg -nobrowse -quiet 
    /bin/echo "`date`: Installing..." >> ${logfile} 
    cp -R /Volumes/Install Backup and Sync from Google/Backup and Sync from Google.app /Applications/ 
    /bin/sleep 3 
    /bin/echo "`date`: Unmounting installer disk image." >> ${logfile} 
    /usr/bin/hdiutil detach $(/bin/df | /usr/bin/grep ${volname} | awk '{print $1}') -quiet 
    /bin/sleep 3 
    open -a /Applications/Google Backup and Sync from Google.app/

From the failure log it appears that it's downloading and mounting but the installation is failing because it can't find the file needed:

Installing...'<br/> cp -R '/Volumes/Install Backup and Sync from Google/Backup and Sync from Google.app' /Applications/<br/>cp: /Volumes/Install Backup and Sync from Google/Backup and Sync from Google.app: No such file or directory<br/> /bin/sleep 3<br/>+ date<br/> /bin/echo 'Wed Sep 27 10:41:24 PDT 2017: Unmounting installer disk image.'<br/>+ /bin/df<br/> /usr/bin/grep Install Backup andy Sync for Google<br/> awk '{print $1}'<br/>grep: Backup: No such file or directory<br/>grep: andy: No such file or directory<br/>grep: Sync: No such file or directory<br/>grep: for: No such file or directory<br/>grep: Google: No such file or directory<br/> /usr/bin/hdiutil detach -quiet<br/> /bin/sleep 3<br/> open -a '/Applications/Google Backup and Sync from Google.app/'<br/>FSPathMakeRef(/Applications/Google Backup and Sync from Google.app) failed with error -43.<br/>

Any help would be appreciated.

1 ACCEPTED SOLUTION

anverhousseini
Contributor II

Try this:

#!/bin/bash

    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

View solution in original post

12 REPLIES 12

anverhousseini
Contributor II

Try this:

#!/bin/bash

    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

LovelessinSEA
Contributor II

Tried running your script from JSS and it just stalls out.

anverhousseini
Contributor II

@LovelessinSEA It works for me. Can you send me the log?

LovelessinSEA
Contributor II

@anverhousseini What log are you looking for? The install doesn't get past this point, it just sits here for as long as i would let it. Since the policy is pending it never gives a failure log in JSS. af8633503d70424d9448c8963ddfbc32

anverhousseini
Contributor II

@LovelessinSEA I can't help you if I don't see the logs. Can you run the script outside of JSS?

LovelessinSEA
Contributor II

@anverhousseini apologies for not responding earlier, your script is perfect, I had some bogus code left over from testing that was causing an issue. Thanks for your help! only thing i would mention is it would be nice to open the application after the install. so i added

open -a /Applications/Backup and Sync.app

to the script.

Thanks again!!

kbrichardson
New Contributor

@LovelessinSEA Do you know of a way to modify this script. To point to a local shared drive on the network to pull from instead of downloading backup & sync to each device I push the script to?

GabeShack
Valued Contributor III

I'd love to find a way to further automate this using our single sign on so it can auto login to backup and sync.

Gabe Shackney
Princeton Public Schools

Gabe Shackney
Princeton Public Schools

damienbarrett
Valued Contributor

Just tested this script against 10.14.3 on a new MacBook Air and it still works as advertised. Thanks!

dave_brubaker
New Contributor

Does this script manage any updates to Backup & Sync? A laptop displayed the message to install the upgraded version of Backup & Sync, so wondering the best method to manage this.

pbileci
Contributor

Does this still work since the app name is now Backup and Sync from Google.app ?

TomDay
Release Candidate Programs Tester

Does anyone have the updated script for "Drive for Desktop"?