Last active
February 20, 2017 19:24
-
-
Save justusiv/bb3ca5ab44bdd9095296d5d6daa8f793 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#requires -version 2 | |
<# | |
.SYNOPSIS | |
Installs latest rclone beta | |
.INPUTS | |
Location to install. | |
If you only want to deal with the exe. | |
Temp location to use. | |
.OUTPUTS | |
Outputs rclone version for verification | |
.NOTES | |
Author:JustusIV | |
.EXAMPLE | |
install-rclonebeta -location "$env:USERPROFILE\Desktop" | |
install-rclonebeta -location "c:\rclone" -execonly $true -temp "c:\mytemp" | |
#> | |
Add-Type -AssemblyName System.IO.Compression.FileSystem | |
function Unzip{ | |
param([string]$zipfile, [string]$outpath) | |
[System.IO.Compression.ZipFile]::ExtractToDirectory($zipfile, $outpath) | |
} | |
Function Test-write{ | |
param ( | |
[Parameter(Mandatory=$True,Position=1)] | |
[string]$path) | |
$random = -join ((48..57) + (65..90) + (97..122) | Get-Random -Count 25 | % {[char]$_}) | |
try{"TESTWRITE" | Out-File -FilePath $path\$random -ErrorAction SilentlyContinue}catch{} | |
$wrote = (Test-Path $path\$random -ErrorAction SilentlyContinue) | |
if ($wrote){Remove-Item $path\$random -ErrorAction SilentlyContinue;return $true}else{return $false} | |
} | |
Function install-rclonebeta{ | |
param ([Parameter(Mandatory=$true,Position=1)] | |
[string]$location, | |
[Parameter(Mandatory=$false)] | |
[boolean]$exeonly=$false, | |
[string]$temp=$env:TEMP) | |
if (!(Test-write $location)){write-warning "Unable to write to location.";return} | |
if (!(Test-write $temp)){write-warning "Unable to write to temp location.";return} | |
if ([IntPtr]::Size -eq 8){$64 = $true} | |
$version = curl http://beta.rclone.org | |
$data = $null | |
$data = @() | |
foreach ($item in $version.Links){$data += $item.innerHTML} | |
$array = $null | |
$array = @() | |
foreach ($item in $data){ | |
$a,$b,$c = $item.split('-') | |
$c = $c -replace '/','' | |
$integer = [int]$b | |
$info = @{ | |
"Major" = $a | |
"Minor" = $integer | |
"Micro" = $c | |
} | |
$Object = New-Object -TypeName psobject -Property $info | |
$array += $Object | |
} | |
$array = $array | Where-Object {($_.Minor -ne 0)} | |
$Major = ($array | Sort-Object Major,Minor,Micro | Select-Object -Last 1).Major | |
$Minor = ($array | Sort-Object Major,Minor,Micro | Select-Object -Last 1).Minor | |
$Micro = ($array | Sort-Object Major,Minor,Micro | Select-Object -Last 1).Micro | |
if($64){$url = "http://beta.rclone.org/$Major-$Minor-$Micro/rclone-$Major-$Minor-$Micro%CE%B2-windows-amd64.zip"}else | |
{$url = "http://beta.rclone.org/$Major-$Minor-$Micro/rclone-$Major-$Minor-$Micro%CE%B2-windows-386.zip"} | |
Invoke-WebRequest -Uri $url -OutFile "$temp\rclone-latestbeta-windows.zip" | |
Unzip "$temp\rclone-latestbeta-windows.zip" "$temp\rclone-latestbeta-windows" | |
$items = (Get-ChildItem (Get-ChildItem "$temp\rclone-latestbeta-windows").FullName) | |
if ($exeonly){foreach ($item in $items | Where-Object {($_.name -eq "rclone.exe") -or ($_.name -eq "rclone")}){Move-Item $item.FullName -Destination $location -Force}}else{ | |
foreach ($item in $items){Move-Item $item.FullName -Destination $location -Force}} | |
Remove-Item $temp\rclone-latestbeta-windows -Recurse | |
Remove-Item $temp\rclone-latestbeta-windows.zip | |
Move-Item $location\rclone $location\rclone.exe -Force -ErrorAction SilentlyContinue | |
& $location\rclone.exe --version | |
} |
The parsing part of this script is no longer needed use.
https://gist.githubusercontent.com/justusiv/1ff2ad273cea3e33ca4acc5cab24c8e0/
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Fun little side project to install the latest version of rclone via powershell.