-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGet-WingetAppFromWinget-pkgs.ps1
More file actions
65 lines (59 loc) · 3 KB
/
Get-WingetAppFromWinget-pkgs.ps1
File metadata and controls
65 lines (59 loc) · 3 KB
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
65
function Get-WingetAppFromWinget-pkgs {
param (
[Parameter(Mandatory=$true)]
[string]$AppName,
[string]$Version
)
$Publisher = $appname -split "\." | Select-Object -First 1
$PackageName = ($appname -split "\.")[1..($appname.Length - 1)] -join "/"
$PublisherFirst = $($Publisher.Substring(0, 1)).ToLower()
If (!($version))
{
$DirUrl = "https://api.github.com/repositories/197275551/contents/manifests/$($PublisherFirst)/$( $Publisher)/$($PackageName)"
$location = New-TemporaryFile
Invoke-WebRequest -Uri $DirUrl -OutFile $location
$jsonData = Get-Content -Raw -Path $location | ConvertFrom-Json
#take the version, exclude Skip Versions
$SkipVersions =@("Alpha","Beta","alpha","beta","Canary","CLI","Dev","Insiders","Preview",".validation")
$Version =$jsondata.name | Where-Object {$SkipVersions -notcontains $_} | Sort-Object { [System.Version]$_ }-Descending | Select-Object -first 1
}
$DirUrl = "https://api.github.com/repositories/197275551/contents/manifests/$($PublisherFirst)/$( $Publisher)/$($PackageName)/$($Version)"
$location = New-TemporaryFile
Invoke-WebRequest -Uri $DirUrl -OutFile $location
$jsonData = Get-Content -Raw -Path $location | ConvertFrom-Json
#Download the files in the Github Winget Manifest folder
Foreach ($file in $jsondata)
{
" File : $($file.name)"
" Path : $($file.path)"
" url : $($file.download_url)"
" Sha : $($file.sha)"
$ManifestFolder = ".\$($file.path | split-path)"
if (!(Test-Path $ManifestFolder)) {New-Item -Path $ManifestFolder -ItemType "Directory"}
Invoke-WebRequest -Uri $($file.download_url) -OutFile "./$($file.path)"
}
#Download the supporting files
$Files = $jsonData | Where-Object { $_.Name -like "*Installer*" }
Foreach ($file in $Files)
{
$yamlContent = Get-Content -Path "./$($file.path)" -Raw
$parsedData = ConvertFrom-Yaml -Yaml $yamlContent
$InstallerUrls = $parseddata.Installers.InstallerUrl
Foreach ($Installer in $parseddata.Installers)
{
$DestinationFile = "$($ManifestFolder)\$($Installer.InstallerUrl | Split-Path -Leaf)"
If (!(Test-Path "$($DestinationFile).SKIP")){
If (!(Test-Path $DestinationFile)) {
"Downloading $DestinationFile"
Invoke-WebRequest -Uri $Installer.InstallerUrl -OutFile $DestinationFile
}
$calculatedHash = Get-FileHash -Path $DestinationFile -Algorithm SHA256
if ($calculatedHash.Hash -eq $Installer.InstallerSha256) {
"$($DestinationFile) hash matches. The file integrity is verified."
} else {
"$($DestinationFile) hash does not match. The file may be corrupted."
}
}
}
}
}