forked from aaronparker/evergreen
-
Notifications
You must be signed in to change notification settings - Fork 0
/
New-WinGetManifest.ps1
155 lines (126 loc) · 5.48 KB
/
New-WinGetManifest.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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
#Requires -Module Evergreen
<#
.SYNOPSIS
Creates a Windows Package Manager manifest from an Evergreen function output.
The intent of this script is to help you generate a YAML file for publishing to the Windows Package Manager repository.
.NOTES
Author: Aaron Parker
Twitter: @stealthpuppy
.LINK
https://github.com/aaronparker/Evergreen
.EXAMPLE
New-WinGetManifest -Package MicrosoftFSLogixApps -Path C:\Manifests
Description:
Creates a Windows Package Manager manifest for Microsoft FSLogix Apps and outputs the manifest in C:\Manifests
#>
[CmdletBinding()]
Param(
[Parameter(Mandatory, Position = 0)]
[System.String] $PackageName,
[Parameter(Mandatory, Position = 1)]
[System.String] $Path
)
# define variables
[Console]::OutputEncoding = [System.Text.Encoding]::UTF8
# Get details from the target Evergreen package
If (Get-Command -Name "Get-$PackageName") {
try {
$Packages = Invoke-Expression -Command "Get-$PackageName"
}
catch {
Throw "Failed to return package details from Get-$PackageName."
Break
}
try {
$Manifest = Invoke-Expression -Command "Export-EvergreenFunctionStrings -AppName $PackageName"
}
catch {
Write-Warning -Message "Failed to return package details from Get-$PackageName."
}
# Get the package properties
$id = "$($Manifest.Name.Split(" ")[0]).$($Manifest.Name.Split(" ")[1,2,3] -join '')"
$publisher = $Manifest.Name.Split(" ")[0]
$AppName = $Manifest.Name.Split(" ")[1, 2, 3] -join ""
$WinGetManifestFile = Join-Path -Path $Path -ChildPath "$($Packages[0].Version).yaml"
# Read metadata
While ($License.Length -eq 0) {
$License = Read-Host -Prompt 'Enter the License, For example: MIT, or Copyright (c) Microsoft Corporation'
}
While ($InstallerType.Length -eq 0) {
$InstallerType = Read-Host -Prompt 'Enter the InstallerType. For example: exe, msi, msix, inno, nullsoft'
}
$LicenseUrl = Read-Host -Prompt '[OPTIONAL] Enter the license URL'
$AppMoniker = Read-Host -Prompt '[OPTIONAL] Enter the AppMoniker (friendly name). For example: vscode'
$Tags = Read-Host -Prompt '[OPTIONAL] Enter any tags that would be useful to discover this tool. For example: zip, c++'
$Description = Read-Host -Prompt '[OPTIONAL] Enter a description of the application'
#region Write metadata
$string = "Id: $id"
Write-Output $string | Out-File -Path $WinGetManifestFile
$string = "Version: $($Packages[0].Version)"
Write-Output $string | Out-File -Path $WinGetManifestFile -Append
$string = "Name: $AppName"
Write-Output $string | Out-File -Path $WinGetManifestFile -Append
$string = "Publisher: $Publisher"
Write-Output $string | Out-File -Path $WinGetManifestFile -Append
$string = "Homepage: $($Manifest.Source)"
Write-Output $string | Out-File -Path $WinGetManifestFile -Append
$string = "License: $License"
Write-Output $string | Out-File -Path $WinGetManifestFile -Append
if (!($LicenseUrl.length -eq 0)) {
$string = "LicenseUrl: $LicenseUrl"
Write-Output $string | Out-File -Path $WinGetManifestFile -Append
}
if (!($AppMoniker.length -eq 0)) {
$string = "AppMoniker: $AppMoniker"
Write-Output $string | Out-File -Path $WinGetManifestFile -Append
}
if (!($Commands.length -eq 0)) {
$string = "Commands: $Commands"
Write-Output $string | Out-File -Path $WinGetManifestFile -Append
}
if (!($Tags.length -eq 0)) {
$string = "Tags: $Tags"
Write-Output $string | Out-File -Path $WinGetManifestFile -Append
}
if (!($Description.length -eq 0)) {
$string = "Description: $Description"
Write-Output $string | Out-File -Path $WinGetManifestFile -Append
}
#endregion
# Write output for each architecture
Write-Output "Installers:" | Out-File -Path $WinGetManifestFile -Append
# Walk through each package in output from the Evergreen function
ForEach ($Package in $Packages) {
# Download the target file
try {
# Create a temporary file to generate a sha256 value.
#If (Test-Path -Path env:TEMP) { $tempFolder = $env:TEMP } Else { $tempFolder = $env:TMPDIR }
$Hashfile = New-TemporaryFile
Write-Host "Downloading URL: $($Package.URI)." -ForegroundColor Blue
$WebClient = New-Object -TypeName "System.Net.WebClient"
$WebClient.DownloadFile($Package.URI, $Hashfile)
}
catch {
Throw $_
Break
}
# Get the file hash
$Hash = Get-FileHash -Path $Hashfile
Remove-Item -Path $Hashfile
#region Write metadata
$string = " - Arch: " + $Package.Architecture
Write-Output $string | Out-File -Path $WinGetManifestFile -Append
$string = " Url: " + $Package.URI
Write-Output $string | Out-File -Path $WinGetManifestFile -Append
$string = " Sha256: " + $Hash.Hash
Write-Output $string | Out-File -Path $WinGetManifestFile -Append
$string = " InstallerType: " + $InstallerType
Write-Output $string | Out-File -Path $WinGetManifestFile -Append
#endregion
}
Write-Host "Manifest saved to: $WinGetManifestFile."
Write-Host "Now place this file in the following location: \manifests\$publisher\$AppName"
}
Else {
Write-Warning -Message "Evergeen function Get-$PackageName does not exist."
}