-
Notifications
You must be signed in to change notification settings - Fork 44
/
update.ps1
44 lines (36 loc) · 1.68 KB
/
update.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
import-module au
$releases = 'http://www.cpuid.com/softwares/cpu-z.htm'
function global:au_SearchReplace {
@{
".\tools\chocolateyInstall.ps1" = @{
"(?i)(^\s*url\s*=\s*)('.*')" = "`$1'$($Latest.URL32)'"
"(?i)(^\s*checksum\s*=\s*)('.*')" = "`$1'$($Latest.Checksum32)'"
"(?i)(^\s*packageName\s*=\s*)('.*')" = "`$1'$($Latest.PackageName)'"
"(?i)(^\s*fileType\s*=\s*)('.*')" = "`$1'$($Latest.FileType)'"
}
}
}
function global:au_GetLatest {
$re = 'cpu-z.+exe'
$download_page = Invoke-WebRequest -Uri $releases -UseBasicParsing
$url = $download_page.links | ? href -match $re | select -First 1 -Expand href
$download_page = Invoke-WebRequest -Uri "http://www.cpuid.com/$url" -UseBasicParsing
$url = $download_page.links | ? href -match $re | select -First 1 -Expand href
$current_checksum = (gi $PSScriptRoot\tools\chocolateyInstall.ps1 | sls '\bchecksum\b') -split "=|'" | Select -Last 1 -Skip 1
if ($current_checksum.Length -ne 64) { throw "Can't find current checksum" }
$remote_checksum = Get-RemoteChecksum $url
if ($current_checksum -ne $remote_checksum) {
Write-Host 'Remote checksum is different then the current one, forcing update'
$global:au_old_force = $global:au_force
$global:au_force = $true
}
@{
Version = $url -split '[_-]' | select -Last 1 -Skip 1
URL32 = $url
Checksum32 = $remote_checksum
}
}
if ($MyInvocation.InvocationName -ne '.') { # run the update only if script is not sourced
update -ChecksumFor none
if ($global:au_old_force -is [bool]) { $global:au_force = $global:au_old_force }
}