Update all Google Apps Bash Script

ToriAnneke
Contributor II

Hey all,
Long time no post!

I got a Bash script and got a snag I can't figure out.

There is a .command file that can be launched (either double clicking or called from Terminal) named CheckForUpdatesNow.command

Pending on a few a things, this file can be located either:
/Library/Google/GoogleSoftwareUpdate/GoogleSoftwareUpdate.bundle/Contents/Resources/CheckForUpdatesNow.command
or
~/Library/Google/GoogleSoftwareUpdate/GoogleSoftwareUpdate.bundle/Contents/Resources/CheckForUpdatesNow.command
or
Doesn't exist (provided Google Chrome has never been launched)

Ideally, would like to run a weekly policy that updates all our Google Apps at log out by targeting this command.

So I made a script (below) that works, however, if the above .command file is in ~/Library/ then the script hangs and hangs and hangs.
Otherwise, it works.

Really have no idea why it hangs in the user space.

Any thoughts?
Thanks in advance as always
-pat

#!/bin/sh -x
#Capture the logged in user
consoleUser=`ls -la /dev/console | cut -d " " -f 4`

#the variable of the user path
userPath=/Users/$consoleUser

#Locations of the Google Update Agent can be either root or user based
gooUpdateRootAgent=/Library/Google/GoogleSoftwareUpdate/GoogleSoftwareUpdate.bundle/Contents/Resources/CheckForUpdatesNow.command
gooUpdateUserAgent=$userPath/Library/Google/GoogleSoftwareUpdate/GoogleSoftwareUpdate.bundle/Contents/Resources/CheckForUpdatesNow.command

if [ -f $gooUpdateRootAgent ];
    then
    sudo -u $consoleUser $gooUpdateRootAgent
elif [ -f $gooUpdateUserAgent ];
    then 
    sudo -u $consoleUser $gooUpdateUserAgent

else
echo "Google Chrome has never been launched on this machine"

fi
4 REPLIES 4

sean
Valued Contributor

You say you are running it at logout. How is that triggered? If the console no longer belongs to the user that was logged in, the console user will be root. Based on your script, if the /Library one doesn't exist, it may want to run

/Users/root/Library/Google/GoogleSoftwareUpdate/GoogleSoftwareUpdate.bundle/Contents/Resources/CheckForUpdatesNow.command

So it should just echo the never launched message and won't get to the elif statement.

ToriAnneke
Contributor II

Hey Sean,

Thanks for the reply.

I think I know what you mean.
The policy to run the script (stored in the JSS) is being triggered by Logout.

To my understanding, policies that are triggered by Login, Logout or Self Service run as the user logging in, the user logging out or currently logged in user respectively. The others triggers run as root.

Unfortunately, the script also hangs if it's run locally on the machine as a Shell.sh file
-p

mm2270
Legendary Contributor III

Back when I created something to do this, I ran across a different approach. You need to call the GoogleSoftwareUpdateAgent with specific flags to have it update Google apps. The .command file is intended to be run in the GUI by a user, not really called in a script. Google actually has documentation on all this out there somewhere.

Basic idea (again, this comes directly from one of Google's support pages)

"/Library/Google/GoogleSoftwareUpdate/GoogleSoftwareUpdate.bundle/Contents/Resources/GoogleSoftwareUpdateAgent.app/Contents/MacOS/GoogleSoftwareUpdateAgent" -runMode oneshot -userInitiated YES "$@"

Or, if its in the user's Library directory, you'd adjust the above path. I'll leave you to figure out how to run that as the user, since there are like a hundred different threads that talk about how to do that.

ToriAnneke
Contributor II

I'll look into that and will follow up.

Thanks for the reply Mike.

-p