Commit 33a87b28 authored by Jos Lieben's avatar Jos Lieben

move to user-driven installation vs machine-driven

parent d4d1b813
......@@ -25,6 +25,7 @@ $listOfFoldersToRedirectToOnedriveForBusiness = @(#One line for each folder you
#OPTIONAL CONFIGURATION:
$xmlDownloadURL = "https://g.live.com/1rewlive5skydrive/ODSUInsider"
$minimumOfflineVersionRequired = 17
$temporaryInstallerPath = Join-Path $Env:TEMP -ChildPath "OnedriveInstaller.EXE"
$logFileX64 = Join-Path $Env:TEMP -ChildPath "OnedriveAutoConfigx64.log"
$logFileX86 = Join-Path $Env:TEMP -ChildPath "OnedriveAutoConfigx86.log"
......@@ -76,55 +77,6 @@ if(![System.IO.Directory]::($desiredBootScriptFolder)){
$vbsSilentPSRunner | Out-File $desiredVBSScriptPath -Force
function returnEnclosedValue{
Param(
[Parameter(Mandatory = $True)]$sourceString,
[Parameter(Mandatory = $True)]$searchString
)
try{
$endString = "`""
$start = $searchString
$startLoc = $sourceString.IndexOf($start)+$start.Length
if($startLoc -eq $start.Length-1){
Throw "Not Found"
}
$searchLength = $sourceString.IndexOf($endString,$startLoc)-$startLoc
if($searchLength -eq $startLoc-1){
Throw "Not Found"
}
return($sourceString.Substring($startLoc,$searchLength))
}catch{Throw}
}
function runProcess ($cmd, $params, $windowStyle=1) {
$p = new-object System.Diagnostics.Process
$p.StartInfo = new-object System.Diagnostics.ProcessStartInfo
$exitcode = $false
$p.StartInfo.FileName = $cmd
$p.StartInfo.Arguments = $params
$p.StartInfo.UseShellExecute = $False
$p.StartInfo.RedirectStandardError = $True
$p.StartInfo.RedirectStandardOutput = $True
$p.StartInfo.WindowStyle = $windowStyle; #1 = hidden, 2 =maximized, 3=minimized, 4=normal
$null = $p.Start()
$output = $p.StandardOutput.ReadToEnd()
$exitcode = $p.ExitCode
$p.Dispose()
$exitcode
$output
}
#GET ONLINE VERSION INFO
try{
$xmlInfo = Invoke-WebRequest -UseBasicParsing -Uri $xmlDownloadURL -Method GET
$version = returnEnclosedValue -sourceString $xmlInfo.Content -searchString "currentversion=`""
$downloadURL = returnEnclosedValue -sourceString $xmlInfo.Content -searchString "url=`""
write-output "Microsoft's XML shows the latest Onedrive version is $version and can be downloaded from $downloadURL"
}catch{
write-error "Failed to download / read version info for Onedrive from $xmlDownloadURL" -ErrorAction Continue
write-error $_ -ErrorAction Continue
}
#ENSURE CONFIG REGISTRY KEYS ARE CREATED
try{
Write-Output "Adding registry keys for Onedrive"
......@@ -136,26 +88,6 @@ try{
Write-Error $_ -ErrorAction Continue
}
#DOWNLOAD ONEDRIVE INSTALLER AND RUN IT
try{
if($downloadURL){
Write-Output "downloading from download URL: $downloadURL"
Invoke-WebRequest -UseBasicParsing -Uri $downloadURL -Method GET -OutFile $temporaryInstallerPath
Write-Output "downloaded finished from download URL: $downloadURL"
if([System.IO.File]::Exists($temporaryInstallerPath)){
Write-Output "Starting client installer"
#first kill existing instances
get-process | where {$_.ProcessName -like "onedrive*"} | Stop-Process -Force -Confirm:$False
runProcess $temporaryInstallerPath "/silent"
Sleep -s 5
Write-Output "Install finished"
}
}
}catch{
Write-Error "Failed to download or install from $downloadURL" -ErrorAction Continue
Write-Error $_ -ErrorAction Continue
}
#REGISTER SCRIPT TO RUN AT LOGON
$wscriptPath = Join-Path $env:SystemRoot -ChildPath "System32\wscript.exe"
$fullRunPath = "$wscriptPath `"$desiredVBSScriptPath`" `"$desiredBootScriptPath`""
......@@ -192,29 +124,14 @@ $listOfFoldersToRedirectToOnedriveForBusiness | % {
$localScriptContent = $localScriptContent -replace ".$"
$localScriptContent += ")
`$logFile = Join-Path `$Env:TEMP -ChildPath `"OnedriveAutoConfig.log`"
`$xmlDownloadURL = `"$xmlDownloadURL`"
`$temporaryInstallerPath = `"$temporaryInstallerPath`"
`$minimumOfflineVersionRequired = `"$minimumOfflineVersionRequired`"
`$onedriveRootKey = `"HKCU:\Software\Microsoft\OneDrive\Accounts\Business`"
`$desiredBootScriptFolder = `"$desiredBootScriptFolder`"
`$desiredBootScriptPath = `"$desiredBootScriptPath`"
Start-Transcript -Path `$logFile
function runProcess (`$cmd, `$params, `$windowStyle=1) {
`$p = new-object System.Diagnostics.Process
`$p.StartInfo = new-object System.Diagnostics.ProcessStartInfo
`$exitcode = `$false
`$p.StartInfo.FileName = `$cmd
`$p.StartInfo.Arguments = `$params
`$p.StartInfo.UseShellExecute = `$False
`$p.StartInfo.RedirectStandardError = `$True
`$p.StartInfo.RedirectStandardOutput = `$True
`$p.StartInfo.WindowStyle = `$windowStyle; #1 = hidden, 2 =maximized, 3=minimized, 4=normal
`$null = `$p.Start()
`$output = `$p.StandardOutput.ReadToEnd()
`$exitcode = `$p.ExitCode
`$p.Dispose()
`$exitcode
`$output
}
#ENSURE CONFIG REGISTRY KEYS ARE CREATED
try{
Write-Output `"Adding registry keys for Onedrive`"
......@@ -229,33 +146,93 @@ try{
Write-Error `$_ -ErrorAction Continue
}
function returnEnclosedValue{
Param(
[Parameter(Mandatory = `$True)]`$sourceString,
[Parameter(Mandatory = `$True)]`$searchString
)
try{
`$endString = `"```"`"
`$start = `$searchString
`$startLoc = `$sourceString.IndexOf(`$start)+`$start.Length
if(`$startLoc -eq `$start.Length-1){
Throw `"Not Found`"
}
`$searchLength = `$sourceString.IndexOf(`$endString,`$startLoc)-`$startLoc
if(`$searchLength -eq `$startLoc-1){
Throw `"Not Found`"
}
return(`$sourceString.Substring(`$startLoc,`$searchLength))
}catch{Throw}
}
function runProcess (`$cmd, `$params, `$windowStyle=1) {
`$p = new-object System.Diagnostics.Process
`$p.StartInfo = new-object System.Diagnostics.ProcessStartInfo
`$exitcode = `$false
`$p.StartInfo.FileName = `$cmd
`$p.StartInfo.Arguments = `$params
`$p.StartInfo.UseShellExecute = `$False
`$p.StartInfo.RedirectStandardError = `$True
`$p.StartInfo.RedirectStandardOutput = `$True
`$p.StartInfo.WindowStyle = `$windowStyle; #1 = hidden, 2 =maximized, 3=minimized, 4=normal
`$null = `$p.Start()
`$output = `$p.StandardOutput.ReadToEnd()
`$exitcode = `$p.ExitCode
`$p.Dispose()
`$exitcode
`$output
}
`$isOnedriveUpToDate = `$False
#GET ONLINE VERSION INFO
try{
`$xmlInfo = Invoke-WebRequest -UseBasicParsing -Uri `$xmlDownloadURL -Method GET
`$version = returnEnclosedValue -sourceString `$xmlInfo.Content -searchString `"currentversion=```"`"
`$downloadURL = returnEnclosedValue -sourceString `$xmlInfo.Content -searchString `"url=```"`"
write-output `"Microsoft's XML shows the latest Onedrive version is `$version and can be downloaded from `$downloadURL`"
}catch{
write-error `"Failed to download / read version info for Onedrive from `$xmlDownloadURL`" -ErrorAction Continue
write-error `$_ -ErrorAction Continue
}
#GET LOCAL INSTALL STATUS AND VERSION
try{
`$updaterPath = Join-Path `$Env:LOCALAPPDATA -ChildPath `"Microsoft\OneDrive\OneDriveStandaloneUpdater.exe`"
`$installedVersion = (Get-ItemProperty -Path `"HKCU:\Software\Microsoft\OneDrive`" -Name `"Version`" -ErrorAction Stop).Version
`$installedVersionPath = (Get-ItemProperty -Path `"HKCU:\Software\Microsoft\OneDrive`" -Name `"OneDriveTrigger`" -ErrorAction Stop).OneDriveTrigger
Write-Output `"Detected Onedrive at `$installedVersionPath`"
Write-Output `"Detected `$installedVersion in registry`"
if(`$installedVersion -le `$minimumOfflineVersionRequired -or (`$version -and `$version -gt `$installedVersion)){
Write-Output `"Onedrive is not up to date!`"
}else{
`$isOnedriveUpToDate = `$True
Write-Output `"Installed version of Onedrive is newer or the same as advertised version`"
}
}catch{
write-error `"Failed to read Onedrive version information from the registry`" -ErrorAction Continue
`$installedVersionPath = Join-Path `$Env:LOCALAPPDATA -ChildPath `"Microsoft\OneDrive\OneDrive.exe`"
Write-output `"Will use auto-guessed value of `$installedVersionPath, but first running updater...`"
runProcess `$updaterPath
Write-output `"Updated has finished! Checking remaining processes...`"
Sleep -s 15
`$waited = 0
while(`$true){
if(get-process | where {`$_.ProcessName -like `"onedrivesetup*`"}){
Write-Output `"Installer still running in the background..`"
Sleep -S 30
`$waited += 30
if(`$waited -gt 600){
break
}
}else{
Write-Output `"Installer finished`"
Sleep -s 30
break
write-error `"Failed to read Onedrive version information from the registry, assuming Onedrive is not installed`" -ErrorAction Continue
write-error `$_ -ErrorAction Continue
}
#DOWNLOAD ONEDRIVE INSTALLER AND RUN IT
try{
if(!`$isOnedriveUpToDate -and `$downloadURL){
Write-Output `"downloading from download URL: `$downloadURL`"
Invoke-WebRequest -UseBasicParsing -Uri `$downloadURL -Method GET -OutFile `$temporaryInstallerPath
Write-Output `"downloaded finished from download URL: `$downloadURL`"
if([System.IO.File]::Exists(`$temporaryInstallerPath)){
Write-Output `"Starting client installer`"
Sleep -s 5 #let A/V scan the file so it isn't locked
#first kill existing instances
get-process | where {`$_.ProcessName -like `"onedrive*`"} | Stop-Process -Force -Confirm:`$False
Sleep -s 5
runProcess `$temporaryInstallerPath `"/silent`"
Sleep -s 5
Write-Output `"Install finished`"
}
`$installedVersionPath = (Get-ItemProperty -Path `"HKCU:\Software\Microsoft\OneDrive`" -Name `"OneDriveTrigger`" -ErrorAction Stop).OneDriveTrigger
}
}catch{
Write-Error `"Failed to download or install from `$downloadURL`" -ErrorAction Continue
Write-Error `$_ -ErrorAction Continue
}
#WAIT FOR CLIENT CONFIGURATION AND REDETERMINE PATH
......@@ -264,19 +241,12 @@ try{
Write-Output `"Checking existence of client folder`"
:detectO4B while(`$true){
if(`$waited -gt `$maxWaitTime){
Write-Output `"Waited too long for client folder to appear. Running auto updater, then exiting`"
`$updaterPath = Join-Path `$Env:LOCALAPPDATA -ChildPath `"Microsoft\OneDrive\OneDriveStandaloneUpdater.exe`"
runProcess `$updaterPath
Sleep -s 60
& `$installedVersionPath
break
}
#GET LOCAL INSTALL STATUS AND VERSION
try{
`$installedVersionPath = (Get-ItemProperty -Path `"HKCU:\Software\Microsoft\OneDrive`" -Name `"OneDriveTrigger`" -ErrorAction Stop).OneDriveTrigger
Write-Output `"Detected Onedrive at `$installedVersionPath`"
}catch{
write-error `"Failed to read Onedrive version information from the registry`" -ErrorAction Continue
`$installedVersionPath = Join-Path `$Env:LOCALAPPDATA -ChildPath `"Microsoft\OneDrive\OneDrive.exe`"
Write-output `"Will use auto-guessed value of `$installedVersionPath`"
runProcess `$installedVersionPath
Sleep -s 60
}
`$checks = 5
......@@ -293,9 +263,23 @@ Write-Output `"Checking existence of client folder`"
}
}
}
if(`$waited -gt `$maxWaitTime){
break
}
Write-Output `"failed to detect user folder! Sleeping for 30 seconds`"
Sleep -Seconds 30
`$waited+=30
`$waited+=30
#GET LOCAL INSTALL PATH
try{
`$installedVersionPath = (Get-ItemProperty -Path `"HKCU:\Software\Microsoft\OneDrive`" -Name `"OneDriveTrigger`" -ErrorAction Stop).OneDriveTrigger
Write-Output `"Detected Onedrive at `$installedVersionPath`"
}catch{
write-error `"Failed to read Onedrive version information from the registry`" -ErrorAction Continue
`$installedVersionPath = Join-Path `$Env:LOCALAPPDATA -ChildPath `"Microsoft\OneDrive\OneDrive.exe`"
Write-output `"Will use auto-guessed value of `$installedVersionPath`"
}
#RUN THE LOCAL CLIENT IF ALREADY INSTALLED
Write-Output `"Starting client...`"
& `$installedVersionPath
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment