Changes

Jump to: navigation, search

Google drive

12,194 bytes added, 12:12, 4 June 2015
Created page with "'''Google Drive''' To deploy Google Drive, you want to download the file gsync.msi. To get this file you need to know the version of gsync to work out the URL. e.g. version..."
'''Google Drive'''

To deploy Google Drive, you want to download the file gsync.msi. To get this file you need to know the version of gsync to work out the URL. e.g. version 1.22.9403.223 uses the URL http://dl.google.com/drive/1.22.9403.0223/gsync.msi. Note how the extra '0' has been added to '223'. If you try to use http://dl.google.com/drive/1.22.9403.223/gsync.msi you'll get page not found. This extra '0' is needed to make the last group of numbers up to a length of 4.

New versions of Google Drive are released ever two weeks or so so to save my time I run a task schedule on a PC that runs every day, sees if there's a new msi, downloads it and makes a new WPKG XML file. To do this I run a compiled Autoit script and use a template XML file.

Autoit script. Compile as an exe and run this as a Windows task. It will work out the latest version by reading [http://www.filehippo.com/download_google_drive/tech/]. It will save the msi into the directory $wpkg_path\[version number]\. The WPKG template is in the dir $wpkg_tree_file - copy of the template below the Autoit code. The template file is copied locally and the string 'VERSION_NUMBER' replaced with the real Google Driver version number. The edited template file is then copied into the live WPKG tree, in my case $wpkg_tree_file.

<pre>
#region ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_Outfile=gdrive_downloaded.exe
#AutoIt3Wrapper_UseX64=n
#AutoIt3Wrapper_Change2CUI=y
#AutoIt3Wrapper_Res_Fileversion=0.0.0.26
#AutoIt3Wrapper_Res_Fileversion_AutoIncrement=y
#endregion ;**** Directives created by AutoIt3Wrapper_GUI ****
#include <Array.au3>
#include <iNetbios.au3>
#include <LogPrint.au3>
#include <File.au3>

;Script to look for the current version of Google Drive, look to see if we've already downloaded it onto the WPKG programs dir. If we haven't, download it and then create an updated WPKG XML file.
;
;C. Mortimer May 2015

$temp_auction_www_download = @TempDir & "\gdrive_info.html"
$get_www_tech_page = "http://www.filehippo.com/download_google_drive/tech/"
$get_www_msi_page = "http://dl.google.com/drive/"
$msi_www_filename = "gsync.msi"
$netbios_domain = "\\" & _GetNetBIOS("samba server")
$wpkg_path = $netbios_domain & "\wpkg7\server\wpkg\programs\cloud\google_drive\"
$logfile = EnvGet("temp") & "\" & @ScriptName & ".log"
$xml_template = @ScriptDir & "\google_drive_template.xml"
$replace_string = "VERSION_NUMBER"
$wpkg_tree_file = $netbios_domain & "\wpkg7\server\WPKG\packages\google_drive.xml"
$temp_copy_2_wpkg_tree = 0
$temp_copy_2_wpkg_tst_tree = 0

_logPrint($logfile, "***************************************************")
_logPrint($logfile, "------------- " & @ScriptName & " v" & FileGetVersion(@ScriptName) & " Started -------------")
_logPrint($logfile, "***************************************************")

_logPrint($logfile, "$temp_auction_www_download = " & $temp_auction_www_download)
_logPrint($logfile, "$get_www_tech_page = " & $get_www_tech_page)
_logPrint($logfile, "$get_www_msi_page = " & $get_www_msi_page)
_logPrint($logfile, "$msi_www_filename = " & $msi_www_filename)
_logPrint($logfile, "$wpkg_path = " & $wpkg_path)

Local $get_gdrive_tech_www = InetGet($get_www_tech_page, $temp_auction_www_download, 1, 1)
Do
Sleep(250)
Until InetGetInfo($get_gdrive_tech_www, 2) ; Check if the download is complete.
Local $aData = InetGetInfo($get_gdrive_tech_www)
InetClose($get_gdrive_tech_www) ; Close the handle to release resourcs.

If $aData[3] = "True" Then
Sleep(500)
$a_downloaded_html = FileReadToArray($temp_auction_www_download) ; create an array containing the download WWW file
;~ _ArrayDisplay ($a_downloaded_html)
$a_opening_indexes = _ArrayFindAll($a_downloaded_html, "<div class=""program-title"" title=""Google Drive ", "", "", 0, 1)
;~ _ArrayDisplay ($a_opening_indexes)
For $y = 0 To UBound($a_opening_indexes) - 1 Step 1
$version_line = StringReplace(StringReplace($a_downloaded_html[$a_opening_indexes[$y]], "<div class=""program-title"" title=""Google Drive ", ""), """>", "")
$version_line = StringReplace($version_line, " ", "")
;~ ConsoleWrite("$version_line = " & $version_line & @CRLF)
$version_line_no_dec = StringReplace($version_line, ".", "")
If StringIsDigit($version_line_no_dec) = 1 Then
ConsoleWrite("latest gdrive = '" & $version_line & "'" & @CRLF)
_logPrint($logfile, "latest gdrive = '" & $version_line & "'")
;now check to see if we have a directory on \\mathsdom\wpkg7 for this version of gdrive
If FileExists($wpkg_path & $version_line & "\gsync.msi") = 0 Then

;sometimes the version number can not be used for the url download if the last two groups of numbers don't have 4 characters per group i.e. 1.22.9403.223 won't work, it needs to be 1.22.9403.0223. We need to check for this
;~ $version_line_www = "1.22.1103.9923"
$version_line_www = $version_line
$version_array = StringSplit($version_line_www, ".")
;~ _ArrayDisplay ($version_array)
If StringLen($version_array[3]) <> 4 Then
Do
$version_array_3 = $version_array[3]
_ArrayInsert($version_array, 3, "0" & $version_array_3)
;~ _ArrayDisplay ($version_array)
_ArrayDelete($version_array, 4)
;~ _ArrayDisplay ($version_array)
Until StringLen($version_array[3]) = 4
EndIf
;~ _ArrayDisplay ($version_array)
;now check the last group of numbers
If StringLen($version_array[4]) <> 4 Then
Do
$version_array_4 = $version_array[4]
_ArrayDelete($version_array, 4)
;~ _ArrayDisplay ($version_array)
_ArrayAdd($version_array, "0" & $version_array_4)
;~ _ArrayDisplay ($version_array)
Until StringLen($version_array[4]) = 4
EndIf
;~ _ArrayDisplay ($version_array)
$version_line_www = _ArrayToString($version_array, ".", 1)
;~ ConsoleWrite("version_line = '" & $version_line & "'")
;~ Exit

If FileExists($wpkg_path & $version_line) = 0 Then
$dir_mk = DirCreate($wpkg_path & $version_line)
ConsoleWrite("$dir_mk = " & $dir_mk & " [1=success]" & @CRLF)
_logPrint($logfile, "$dir_mk = " & $dir_mk & " [1=success]")
Else
ConsoleWrite("The dir '" & $wpkg_path & $version_line & "' already exists" & @CRLF)
_logPrint($logfile, "The dir '" & $wpkg_path & $version_line & "' already exists")
$dir_mk = 1
EndIf
If $dir_mk = 1 Then

Local $get_gdrive_msi = InetGet($get_www_msi_page & $version_line_www & "/" & $msi_www_filename, $wpkg_path & $version_line & "\" & $msi_www_filename, 1, 1)
ConsoleWrite("$get_gdrive_msi = '" & $get_www_msi_page & $version_line_www & "/" & $msi_www_filename & "'" & @CRLF)
_logPrint($logfile, "$get_gdrive_msi = '" & $get_www_msi_page & $version_line_www & "/" & $msi_www_filename & "'")
Do
Sleep(250)
Until InetGetInfo($get_gdrive_msi, 2) ; Check if the download is complete.
Local $aData = InetGetInfo($get_gdrive_msi)
InetClose($get_gdrive_msi) ; Close the handle to release resourcs.

;~ ConsoleWrite (" $aData[3] = " & $aData[3] & @CRLF)
If $aData[3] = "True" Then
If FileExists($wpkg_path & "\latest.lnk") Then FileDelete($wpkg_path & "\latest.lnk")
$crt_shortcut = FileCreateShortcut($wpkg_path & $version_line & "\" & $msi_www_filename, $wpkg_path & "\latest.lnk")
ConsoleWrite("GDrive downloaded to " & $wpkg_path & $version_line & "\" & @CRLF)
_logPrint($logfile, "GDrive downloaded to " & $wpkg_path & $version_line & "\")
ConsoleWrite("Shortcut to the latest google drive created with result '" & $crt_shortcut & "' [1=success]" & @CRLF)
_logPrint($logfile, "Shortcut to the latest google drive created with result '" & $crt_shortcut & "' [1=success]")
;we'll now make a new WPKG xml file
If FileExists($xml_template) Then
$temp_copy = FileCopy($xml_template, $xml_template_tmp, 8)
ConsoleWrite("A copy of the template file " & $xml_template & " to " & $xml_template_tmp & " completed with '" & $temp_copy & "' [1=success]" & @CRLF)
_logPrint($logfile, "A copy of the template file " & $xml_template & " to " & $xml_template_tmp & " completed with '" & $temp_copy & "' [1=success]")
$replace_ver = _ReplaceStringInFile($xml_template_tmp, $replace_string, $version_line, 0, 1)
ConsoleWrite("There were '" & $replace_ver & "' replacements of the string '" & $replace_string & "' with the version value of '" & $version_line & "' [there should be >=1]" & @CRLF)
_logPrint($logfile, "There were '" & $replace_ver & "' replacements of the string '" & $replace_string & "' with the version value of '" & $version_line & "' [there should be >=1]")
$temp_copy_2_wpkg_tree = FileCopy($xml_template_tmp, $wpkg_tree_file, 1)
ConsoleWrite("A copy of the template file " & $xml_template_tmp & " to " & $wpkg_tree_file & " completed with '" & $temp_copy_2_wpkg_tree & "' [1=success]" & @CRLF)
_logPrint($logfile, "A copy of the template file " & $xml_template_tmp & " to " & $wpkg_tree_file & " completed with '" & $temp_copy_2_wpkg_tree & "' [1=success]")
ConsoleWrite($xml_template_tmp & " was deleted with result '" & $del_tmp_file & "' [1=success]" & @CRLF)
_logPrint($logfile, $xml_template_tmp & " was deleted with result '" & $del_tmp_file & "' [1=success]")
Else
ConsoleWrite("The file '" & $xml_template & "' doesn't exist, ending" & @CRLF)
_logPrint($logfile, "The file '" & $xml_template & "' doesn't exist, ending")
EndIf
$y = UBound($a_opening_indexes) - 1
Else
ConsoleWrite("$aData[3] didn't return 'true', it returned '" & $aData[3] & "', download not available? Ending" & @CRLF)
_logPrint($logfile, "$aData[3] didn't return 'true', it returned '" & $aData[3] & "', download not available? Ending")
EndIf
Else
$dir_mk = 1
ConsoleWrite("$dir_mk <> 1 (" & $dir_mk & ") therefore ending" & @CRLF)
_logPrint($logfile, "$dir_mk <> 1 (" & $dir_mk & ") therefore ending")
EndIf
Else
ConsoleWrite($wpkg_path & $version_line & " already exists, no need to download anything" & @CRLF)
_logPrint($logfile, $wpkg_path & $version_line & " already exists, no need to download anything")
EndIf
EndIf
Next
Else
ConsoleWrite("Failed to obtain the latest Google Drive version. What does '" & $get_www_tech_page & "' show?" & @CRLF)
_logPrint($logfile, "Failed to obtain the latest Google Drive version. What does '" & $get_www_tech_page & "' show?")
EndIf
_logPrint($logfile, "***************************************************")
_logPrint($logfile, "")

</pre>

XML template file

<pre>
<?xml version="1.0" encoding="UTF-8"?>
<packages>

<package id="googledrive" name="Google Drive" revision="%version%" reboot="false" priority="17">
<variable name="VERSION" value="VERSION_NUMBER" />
<check type="uninstall" condition="versionequalto" path="Google Drive" value="%VERSION%" />
<!--<depends package-id="vc-runtime-2008" /> -->

<install cmd='%COMSPEC% /c "%SOFTWARE%\cloud\google_drive\gdrive_install.bat %VERSION%' />
<install cmd='%COMSPEC% /c if exist "%PUBLIC%\desktop\Google Docs.lnk" del /q "%PUBLIC%\desktop\Google Docs.lnk"' />
<install cmd='%COMSPEC% /c if exist "%PUBLIC%\desktop\Google Sheets.lnk" del /q "%PUBLIC%\desktop\Google Sheets.lnk"' />
<install cmd='%COMSPEC% /c if exist "%PUBLIC%\desktop\Google Slides.lnk" del /q "%PUBLIC%\desktop\Google Slides.lnk"' />

<upgrade cmd='%COMSPEC% /c "%SOFTWARE%\cloud\google_drive\gdrive_install.bat %VERSION%' />
<upgrade cmd='%COMSPEC% /c if exist "%PUBLIC%\desktop\Google Docs.lnk" del /q "%PUBLIC%\desktop\Google Docs.lnk"' />
<upgrade cmd='%COMSPEC% /c if exist "%PUBLIC%\desktop\Google Sheets.lnk" del /q "%PUBLIC%\desktop\Google Sheets.lnk"' />
<upgrade cmd='%COMSPEC% /c if exist "%PUBLIC%\desktop\Google Slides.lnk" del /q "%PUBLIC%\desktop\Google Slides.lnk"' />

<remove cmd='%COMSPEC% /c if defined ProgramW6432 ("\\%DOMAIN%\netlogon\scripts\uninstall\wpkg_silent_msi_uninstall.bat" "\\%DOMAIN%\netlogon\scripts\autoit3cmd_64.exe" "\\%DOMAIN%\netlogon\scripts\uninstall\uninstall_value-master.au3" "Google Drive" 1 1)' />

</package>

</packages>
</pre>
15
edits

Navigation menu