Google Drive File Stream

Andy_McCaskill
Contributor

Has anyone worked in a distribution plan for this?

I am having a little bit of a trouble figuring out a way to package and install on our workstations.

1 ACCEPTED SOLUTION

bmonroe
New Contributor III

Here's what we were using:

#!/bin/sh
################################################################################
#  ABOUT THIS PROGRAM
#
#  NAME
#    InstallGoogleFileStream.sh
#
#  SYNOPSIS
#    ./InstallGoogleFileStream.sh
#
#  DESCRIPTION
#    Downloads latest version of File Stream from Google's servers and installs
#    it for the current user. If Google Drive is detected, the application is
#    stopped and deleted, but user data is not. If data is found, a
#    notification is displayed through JAMF helper.
#
#  HISTORY
#    Version 1.0
#      Brian Monroe, 18.10.2017
################################################################################
# Set some Variables
SupportContactInfo="your system administrator."
dmgfile="GoogleDriveFileStream.dmg"
logfile="/Library/Logs/GoogleFileStreamInstallScript.log"
url="https://dl.google.com/drive-file-stream/GoogleDriveFileStream.dmg"
user=`ls -l /dev/console | cut -d " " -f 4`

# Say what we are doing
/bin/echo "`date`: Installing latest version of File Stream for $user..." >> ${logfile}

# Download All the Things
/bin/echo "`date`: Downloading the latest version of File Stream from Google's servers" >> ${logfile}
/usr/bin/curl -k -o /tmp/$dmgfile $url
/bin/echo "`date`: Mounting dmg file." >> ${logfile}
/usr/bin/hdiutil attach /tmp/$dmgfile -nobrowse -quiet

# Install the things. 
/bin/echo "`date`: Installing pkg" >> ${logfile}
/usr/sbin/installer -pkg /Volumes/Install Google Drive File Stream/GoogleDriveFileStream.pkg -target /

# Look for Google Drive
if [ -d /Applications/Google Drive.app/ ]; then
  /bin/echo "`date`: Found depricated version of Google Drive. Stopping Drive service." >> ${logfile}
  /usr/bin/osascript -e 'tell application "Google Drive" to quit'
  /bin/echo "`date`: Deleting Google Drive Application." >> ${logfile}
  rm -Rf /Applications/Google Drive.app/
  /Library/Application Support/JAMF/bin/jamfHelper.app/Contents/MacOS/jamfHelper  -title "Google Drive Version Found" -windowType hud -description "Google Drive Version Found" -description "While installing Google Drive File Stream we found an older version of Google Drive. Since they are not compatible, we removed the older version. However, you still have data stored in your home folder under Google Drive. These files will no longer be synced, so you should either move them or delete them. If you have any addional questions please reach out to ${SupportContactInfo}." &
fi

# Cleanup Tasks
/bin/echo "`date`: Unmounting installer disk image." >> ${logfile}
/usr/bin/hdiutil detach $(/bin/df | /usr/bin/grep "Install Google File Stream" | awk '{print $1}') -quiet
/bin/echo "`date`: Deleting temp files." >> ${logfile}
rm -fv /tmp/$dmgfile
/bin/sleep 3
/bin/echo "`date`: Launching File Stream" >> ${logfile}
open -a /Applications/Google Drive File Stream.app/
/bin/echo "`date`: Finished." >> ${logfile}

exit 0

View solution in original post

27 REPLIES 27

kld0010
New Contributor II

I did a major deployment in conjunction with a migration from Box to Google Team Drives. In order to make the transition smooth, I did it in stages.

1 - Install Google Drive File Stream via a Check-In Policy (But don't launch it). We did this because we had people using the original Google Drive sync client and didn't want to deal with double sync.

2 - I wrote a script that would run at next login on machines that had completed the Google Drive File Stream Install (Just a smart group looking for the installed app). This script would: quit Google Drive Sync, Delete the App, move ~/Google Drive to ~/Archive/Google Drive and launch Google Drive File Stream. It also did some stuff like prompt them to add a dock shortcut if they wanted etc.

The most annoying part of this was that it relied on users to reboot to kick the script and sometimes the login hooks wouldn't work. If I could do it again, I would do a hard cut and just push the script to everyone at once, but oh well.

Andy_McCaskill
Contributor

@kld0010 The installer itself, how did you package it up? Did you use Composer or just toss the installer in Casper admin?

kld0010
New Contributor II

We did the EAP for File Stream, I got a .pkg from Google, so I just threw that into the JSS

bmonroe
New Contributor III

Here's what we were using:

#!/bin/sh
################################################################################
#  ABOUT THIS PROGRAM
#
#  NAME
#    InstallGoogleFileStream.sh
#
#  SYNOPSIS
#    ./InstallGoogleFileStream.sh
#
#  DESCRIPTION
#    Downloads latest version of File Stream from Google's servers and installs
#    it for the current user. If Google Drive is detected, the application is
#    stopped and deleted, but user data is not. If data is found, a
#    notification is displayed through JAMF helper.
#
#  HISTORY
#    Version 1.0
#      Brian Monroe, 18.10.2017
################################################################################
# Set some Variables
SupportContactInfo="your system administrator."
dmgfile="GoogleDriveFileStream.dmg"
logfile="/Library/Logs/GoogleFileStreamInstallScript.log"
url="https://dl.google.com/drive-file-stream/GoogleDriveFileStream.dmg"
user=`ls -l /dev/console | cut -d " " -f 4`

# Say what we are doing
/bin/echo "`date`: Installing latest version of File Stream for $user..." >> ${logfile}

# Download All the Things
/bin/echo "`date`: Downloading the latest version of File Stream from Google's servers" >> ${logfile}
/usr/bin/curl -k -o /tmp/$dmgfile $url
/bin/echo "`date`: Mounting dmg file." >> ${logfile}
/usr/bin/hdiutil attach /tmp/$dmgfile -nobrowse -quiet

# Install the things. 
/bin/echo "`date`: Installing pkg" >> ${logfile}
/usr/sbin/installer -pkg /Volumes/Install Google Drive File Stream/GoogleDriveFileStream.pkg -target /

# Look for Google Drive
if [ -d /Applications/Google Drive.app/ ]; then
  /bin/echo "`date`: Found depricated version of Google Drive. Stopping Drive service." >> ${logfile}
  /usr/bin/osascript -e 'tell application "Google Drive" to quit'
  /bin/echo "`date`: Deleting Google Drive Application." >> ${logfile}
  rm -Rf /Applications/Google Drive.app/
  /Library/Application Support/JAMF/bin/jamfHelper.app/Contents/MacOS/jamfHelper  -title "Google Drive Version Found" -windowType hud -description "Google Drive Version Found" -description "While installing Google Drive File Stream we found an older version of Google Drive. Since they are not compatible, we removed the older version. However, you still have data stored in your home folder under Google Drive. These files will no longer be synced, so you should either move them or delete them. If you have any addional questions please reach out to ${SupportContactInfo}." &
fi

# Cleanup Tasks
/bin/echo "`date`: Unmounting installer disk image." >> ${logfile}
/usr/bin/hdiutil detach $(/bin/df | /usr/bin/grep "Install Google File Stream" | awk '{print $1}') -quiet
/bin/echo "`date`: Deleting temp files." >> ${logfile}
rm -fv /tmp/$dmgfile
/bin/sleep 3
/bin/echo "`date`: Launching File Stream" >> ${logfile}
open -a /Applications/Google Drive File Stream.app/
/bin/echo "`date`: Finished." >> ${logfile}

exit 0

Andy_McCaskill
Contributor

Great script! This will help a ton with our transition. Thank you for your contribution!

ben_hertenstein
Release Candidate Programs Tester

Thank you @bmonroe Exactly what I have been trying to accomplish. Works great in my testing.
Always got hung up on quitting google drive properly.

bmonroe
New Contributor III

No Problem! @ben.hertenstein and @mccaskill. I also wrote one to use with backup and sync at the same time as File Stream. You can find it here: https://github.com/azusapacificuniversity/scripts for general scripts and right here for the backup and sync script.

musat
Contributor III

Is it just us? When we use Self Service to install the PKG file downloaded from Google, it always automatically launches. This makes it hard to install the program silently. I know there are command-line options for Installer, but as far as I know there are no ways to us those directly without needing to package the package with a separate installer script.

daniel_jones
New Contributor

Brilliant script, thank you.

We are trying to install this silently without the popup once the install has completed, asking the users to sign in.

Does anyone have any parameters that could help me with this?

Thank you in advance

nstrauss
Contributor II

If you're an AutoPkg user here's a recipe I put together. It doesn't auto-launch File Stream after install for those running into that problem. https://github.com/nstrauss/autopkg-recipes/tree/master/Google%20Drive%20File%20Stream

We uninstall Backup and Sync as a postinstall script in our install policy as well. Assumption is the user will use one or the other, and we're pushing heavily towards File Stream.

#!/bin/bash

# Kill the process with fire
killall -HUP "Backup and Sync"

# Remove the app bundle
rm -rf "/Applications/Backup and Sync.app"

# Remove the login item
osascript -e 'tell application "System Events" to delete login item "Backup and Sync from Google"'

exit 0

msnowdon
Contributor

@bmonroe I tried your script and it works great. I was wondering if there was a way to add a section to remove the old Google Drive folder(s). I have some lab machines with Google Drive on them and there would be a Google Drive folder in every user's profile.

Thanks

Mark

bmonroe
New Contributor III

Deleting user data always makes me super nervous.... I'm not going to update the first post for that reason, but you could easily add a single line to do what you're looking for. It would make the most sense here:

# Look for Google Drive
if [ -d /Applications/Google Drive.app/ ]; then
  /bin/echo "`date`: Found depricated version of Google Drive. Stopping Drive service." >> ${logfile}
  /usr/bin/osascript -e 'tell application "Google Drive" to quit'
  /bin/echo "`date`: Deleting Google Drive Application." >> ${logfile}
  rm -Rf /Applications/Google Drive.app/
  for folder in /Users/* ; do /bin/echo "`date`: Deleting User Data in ${folder} !!!" >> ${logfile}; rm -Rf $folder/Drive/; done
  /Library/Application Support/JAMF/bin/jamfHelper.app/Contents/MacOS/jamfHelper  -title "Google Drive Version Found" -windowType hud -description "Google Drive Version Found" -description "While installing Google Drive File Stream we found an older version of Google Drive. Since they are not compatible, we removed the older version. However, you still have data stored in your home folder under Google Drive. These files will no longer be synced, so you should either move them or delete them. If you have any addional questions please reach out to ${SupportContactInfo}." &
fi

I don't have a mac in front of me and I can't remember the default Drive folder name is so...

  for folder in /Users/* ; do /bin/echo "`date`: Deleting User Data in ${folder} !!!" >> ${logfile}; rm -Rf ${folder}/Drive/; done

might need to actually be edited to be:

  for folder in /Users/* ; do /bin/echo "`date`: Deleting User Data in ${folder} !!!" >> ${logfile}; rm -Rf $folder/Google Drive/; done

Good luck!

msnowdon
Contributor

Thanks, I'll test it out.

brytox
New Contributor III

Ive spent a little time working on this as well. My approach is quite similar to people above, but rather than rename the google drive folder i locked it, just incase the sync hasn't finished.

I also throw up a internal website telling people the differences, and that we will remove that google drive folder later on down the line.

bryanoneill
New Contributor II

i have made a little change to the script so it wil also delete Backup and Sync

you can past this under Look for Google Drive line

# Look for Backup and Sync if [ -d /Applications/Backup and Sync.app/ ]; then /bin/echo "date: Found depricated version of Backup and Sync. Stopping Drive service." >> ${logfile} /usr/bin/osascript -e 'tell application "Backup and Sync" to quit' /bin/echo "date: Deleting Backup and Sync Application." >> ${logfile} rm -Rf /Applications/Backup and Sync.app/ /Library/Application Support/JAMF/bin/jamfHelper.app/Contents/MacOS/jamfHelper -title "Backup and Sync Version Found" -windowType hud -description "Backup and Sync Version Found" -description "While installing Google Drive File Stream we found an older version of Google Drive. Since they are not compatible, we removed the older version. However, you still have data stored in your home folder under Google Drive. These files will no longer be synced, so you should either move them or delete them. If you have any addional questions please reach out to ${SupportContactInfo}." & fi

mjones
New Contributor

@bmonroe I have been using your script and it worked perfectly when I used it for our staff. However, I am going to now make it available to the students and I would like to have it rename their old Google Drive directory from "Google Drive" to "Old Google Drive" as it makes me nervous to just have it be deleted. But at the same time, I want it to have a different name so they are not confused about which one to use until we delete the old one over the summer. I am admittedly not great at scripting and everything I've tried has failed. Do you think there is a way to do the renaming? Thanks in advance for your input.

bmonroe
New Contributor III

@mjones Basically you do the same thing that was listed in deleting the folder, but you rename it instead.

# Look for Google Drive
if [ -d /Applications/Google Drive.app/ ]; then
  /bin/echo "`date`: Found depricated version of Google Drive. Stopping Drive service." >> ${logfile}
  /usr/bin/osascript -e 'tell application "Google Drive" to quit'
  /bin/echo "`date`: Deleting Google Drive Application." >> ${logfile}
  rm -Rf /Applications/Google Drive.app/
  for folder in /Users/* ; do /bin/echo "`date`: Moving User Data in ${folder} !!!" >> ${logfile}; mv $folder/Drive/ $folder/OLDGoogleDrive/ ; done
  /Library/Application Support/JAMF/bin/jamfHelper.app/Contents/MacOS/jamfHelper  -title "Google Drive Version Found" -windowType hud -description "Google Drive Version Found" -description "While installing Google Drive File Stream we found an older version of Google Drive. Since they are not compatible, we removed the older version. However, you still have data stored in your home folder under a new folder called OLDGoogleDrive. These files will no longer be synced, so you should either move them or delete them. If you have any addional questions please reach out to ${SupportContactInfo}." &
fi

I never looked into whatever the default Drive folder name was but it might need to be

  for folder in /Users/* ; do /bin/echo "`date`: Moving User Data in ${folder} !!!" >> ${logfile}; mv $folder/Google Drive/ $folder/OLD Google Drive/ ; done

jlang_remedy
New Contributor III

@bmonroe or anyone else.

Running into an issue where some users are still saving files to their Drive even thought it stopped syncing earlier this year and hence not being backed up.

While this script will work to install Drive FS and copy/rename their old drive, is it feasible to attempt to copy those files in their OLD drive to the new drive FS after they sign-in and do an initial sync via some scripting magic? We would probably have to roll that script out via a user initiated policy in Self-service to initiate the copy and determine that if duplicate files exist to use the most recent modified version, and also skip native Gdoc files like gsheets, gdocs, gslides, etc which should always be the latest version.

Just curious on thoughts or implications for the end user to try something like that.

jlang_remedy
New Contributor III

.

bmonroe
New Contributor III

@jlang_remedy I have no idea. What I would be worried about is some sort of secret hash file information that Google stores next to the files and when you copy the old files over it hoses the copies that are in the cloud because it thinks you updated them, then you end up with corrupted data.

But maybe? ¯_(ツ)_/¯

I guess I'm just saying I wouldn't want to test it with my data, or anyone in my family. I'd rather just spend the time on the loss of bandwidth while it downloads select new copies.

KieranD79
New Contributor

Great script, this works brilliant from Self Service but I'm having issues running it as a 'Check-In' policy with the latest version of Google Drive File Stream 31.0.19.0.

The download happens, it mounts to DMG, but when the installer is run it returns an error. The apps then appear to be installed but File Stream keeps closing with a "google drive file stream encountered a problem and has stopped" message after you've logged in.

It seems to be linked to a user not being logged in at the time the policy is triggered.

Anyone else had this with the latest version?

fenlon
New Contributor

@KieranD79 I am getting the same error. Did you ever find a solution to resolve this?

bmonroe
New Contributor III

@fenlon I haven't seen this, but you could either trigger it at login instead of checkin, or write an if statement that exits if there's no user currently logged in to quit ahead of time.

bfrench
Contributor III

@bmonroe Once upon a time I found your script to install Google File Stream. Works amazing! Now that they have changed the name to Google Drive for Desktop is your script still working? Does anything need to change? Has anyone else posted a script? Thanks for your help!

robertliebsch
Contributor

The script needs some work.There were lags in GoogleDrive being pushed out, so as the script ran it was removing the new version.

But once you remove the section that removes GoogleDrive (the original name for the desktop app) and change the FileStream references to GoogleDrive you should be good to go.

#!/bin/sh
################################################################################
#  ABOUT THIS PROGRAM
#
#  NAME
#    InstallGoogleFileStream.sh
#
#  SYNOPSIS
#    ./InstallGoogleFileStream.sh
#
#  DESCRIPTION
#    Downloads latest version of File Stream from Google's servers and installs
#    it for the current user. If Google Drive is detected, the application is
#    stopped and deleted, but user data is not. If data is found, a
#    notification is displayed through JAMF helper.
#
#  HISTORY
#    Version 1.0
#      Brian Monroe, 18.10.2017
#       updated for Google Drive v45
################################################################################
# Set some Variables
SupportContactInfo="your system administrator."
dmgfile="GoogleDrive.dmg"
logfile="/Library/Logs/GoogleFileStreamInstallScript.log"
url="https://dl.google.com/drive-file-stream/GoogleDrive.dmg"
user=`ls -l /dev/console | cut -d " " -f 4`

# Say what we are doing
/bin/echo "`date`: Installing latest version of File Stream for $user..." >> ${logfile}

# Download All the Things
/bin/echo "`date`: Downloading the latest version of File Stream from Google's servers" >> ${logfile}
/usr/bin/curl -k -o /tmp/$dmgfile $url
/bin/echo "`date`: Mounting dmg file." >> ${logfile}
/usr/bin/hdiutil attach /tmp/$dmgfile -nobrowse -quiet

# Install the things. 
/bin/echo "`date`: Installing pkg" >> ${logfile}
/usr/sbin/installer -pkg /Volumes/Install Google Drive/GoogleDrive.pkg -target /

# Look for Google Drive 
#commented this section out since the name is back to Google Drive
#if [ -d /Applications/Google Drive.app/ ]; then
#  /bin/echo "`date`: Found depricated version of Google Drive. Stopping Drive service." >> ${logfile}
#  /usr/bin/osascript -e 'tell application "Google Drive" to quit'
#  /bin/echo "`date`: Deleting Google Drive Application." >> ${logfile}
#  rm -Rf /Applications/Google Drive.app/
#  /Library/Application Support/JAMF/bin/jamfHelper.app/Contents/MacOS/jamfHelper  -title "Google Drive Version Found" -windowType hud -description "Google Drive Version Found" -description "While installing Google Drive File Stream we found an older version of Google Drive. Since they are not compatible, we removed the older version. However, you still have data stored in your home folder under Google Drive. These files will no longer be synced, so you should either move them or delete them. If you have any addional questions please reach out to ${SupportContactInfo}." &
#fi

# Cleanup Tasks
/bin/echo "`date`: Unmounting installer disk image." >> ${logfile}
/usr/bin/hdiutil detach $(/bin/df | /usr/bin/grep "Install Google Drive" | awk '{print $1}') -quiet
/bin/echo "`date`: Deleting temp files." >> ${logfile}
rm -fv /tmp/$dmgfile
/bin/sleep 3
/bin/echo "`date`: Finished." >> ${logfile}

exit 0
#!/bin/sh

echave
New Contributor III

Thanks for sharing your updated script. One small note is that in line 50 the name of the package needs \  to escape the SPACE character

/usr/sbin/installer -pkg /Volumes/Install Google Drive/GoogleDrive.pkg -target /

/usr/sbin/installer -pkg /Volumes/Install\ Google\ Drive/GoogleDrive.pkg -target /

robertliebsch
Contributor

Also of note, if you were using the old script and smart groups. You may find that some of your users have 10-100 mounted dmgs.