Skip to main content
Answer

Google Backup and Sync Install Script

  • September 27, 2017
  • 12 replies
  • 27 views

Forum|alt.badge.img+9

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.

Best answer by anverhousseini

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

12 replies

anverhousseini
Forum|alt.badge.img+11
  • Valued Contributor
  • Answer
  • September 27, 2017

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

Forum|alt.badge.img+9
  • Author
  • Valued Contributor
  • September 27, 2017

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


anverhousseini
Forum|alt.badge.img+11
  • Valued Contributor
  • September 27, 2017

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


Forum|alt.badge.img+9
  • Author
  • Valued Contributor
  • September 27, 2017

@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.


anverhousseini
Forum|alt.badge.img+11
  • Valued Contributor
  • September 27, 2017

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


Forum|alt.badge.img+9
  • Author
  • Valued Contributor
  • September 28, 2017

@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!!


Forum|alt.badge.img+2
  • New Contributor
  • November 1, 2017

@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?


Forum|alt.badge.img+18
  • Esteemed Contributor
  • November 27, 2017

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


damienbarrett
Forum|alt.badge.img+19
  • Honored Contributor
  • February 28, 2019

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


Forum|alt.badge.img
  • New Contributor
  • October 17, 2019

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.


Forum|alt.badge.img+6
  • Contributor
  • October 18, 2019

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


Forum|alt.badge.img+22
  • Honored Contributor
  • July 21, 2021

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