forked from ONLYOFFICE/server
-
Notifications
You must be signed in to change notification settings - Fork 0
/
update-core.ps1
64 lines (56 loc) · 1.6 KB
/
update-core.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
Add-Type -AssemblyName System.IO.Compression.FileSystem
# ----------------------------------------------------------------------------------------------
# download a file
# ----------------------------------------------------------------------------------------------
function Download-File
{
param ([string]$url,[string]$file)
$downloadRequired = $true
if (Test-Path $file)
{
$localModified = (Get-Item $file).LastWriteTime
$webRequest = [System.Net.HttpWebRequest]::Create($url)
$webRequest.Method = "HEAD"
$webResponse = $webRequest.GetResponse()
$remoteLastModified = ($webResponse.LastModified) -as [DateTime]
$webResponse.Close()
if ($remoteLastModified -gt $localModified)
{
Write-Host "$file is out of date"
}
else
{
$downloadRequired = $false
}
}
if ($downloadRequired)
{
$clnt = new-object System.Net.WebClient
Write-Host "Downloading from $url to $file"
$clnt.DownloadFile($url, $file)
}
else
{
Write-Host "$file is up to date."
}
return $downloadRequired
}
# ----------------------------------------------------------------------------------------------
# unzip a file
# ----------------------------------------------------------------------------------------------
function Unzip
{
param([string]$zipfile, [string]$outpath)
if (Test-Path $outpath)
{
Write-Host "Remove folder $outpath"
Remove-Item $outpath -Force -Recurse
}
Write-Host "Unzip from $zipfile to $outpath"
[System.IO.Compression.ZipFile]::ExtractToDirectory($zipfile, $outpath)
}
$output = Download-File -url $args[0] -file $args[1]
if ($output)
{
Unzip -zipfile $args[1] -outpath $args[2]
}