-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCreate-WingetRepo.ps1
More file actions
59 lines (48 loc) · 2.57 KB
/
Create-WingetRepo.ps1
File metadata and controls
59 lines (48 loc) · 2.57 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
$folder = "."
$unziplocation = "$($folder)\WinGet.RestSource-Winget.PowerShell.Source"
if (!(Test-Path "$($unziplocation)\Microsoft.WinGet.RestSource.psd1"))
{
$downloadlink = "https://github.com/microsoft/winget-cli-restsource/releases/latest/download/WinGet.RestSource-Winget.PowerShell.Source.zip"
$downloadlocation = "$($folder)\WinGet.RestSource-Winget.PowerShell.Source.zip"
$download = Invoke-WebRequest -Uri $downloadlink -OutFile $downloadlocation
Expand-Archive -Path $downloadlocation -DestinationPath $unziplocation -Force
Get-ChildItem -Path $unziplocation -Recurse | Unblock-File
}
Import-Module "$($unziplocation)\Microsoft.WinGet.RestSource.psd1"
# Read the Config.JSON file
$ConfigJson = Get-Content -Path "$($folder)\config.json" -Raw | ConvertFrom-Json
# Access the parameters
$AzureCloud = $ConfigJson.AzureCloud
$Region = $ConfigJson.Region
$Subscription = $ConfigJson.Subscription
$ResourceGroup = $ConfigJson.ResourceGroup
$Name = $ConfigJson.Name
$implementationperformance = $ConfigJson.implementationperformance
# Check the current version of Azure CLI
$currentVersion = az --version | Select-String -Pattern "azure-cli" | ForEach-Object { $_.Line.Split() }
# Get the latest version of Azure CLI from the official repository
$latestVersion = (Invoke-RestMethod -Uri "https://api.github.com/repos/Azure/azure-cli/releases/latest").tag_name
# Compare the versions
if ($currentVersion -ne $latestVersion) {
Write-Output "An upgrade is needed. Current version: $currentVersion, Latest version: $latestVersion"
} else {
Write-Output "You are using the latest version of Azure CLI: $currentVersion"
}
if(!($(get-azcontext).environment.name -eq $AzureCloud)) {
az cloud set --name $AzureCloud
connect-AzAccount -Environment $AzureCloud
}
if(!($(get-azcontext).Subscription.Id -eq $Subscription)) {
Set-AzContext -SubscriptionId $Subscription
}
new-wingetsource -Name $Name -ResourceGroup $ResourceGroup -Region $Region -ImplementationPerformance $Implementationperformance -ShowConnectionInstructions -InformationAction Continue -Verbose
# Get the API Management service context
$apimContext = Get-AzApiManagement -ResourceGroupName $resourceGroupName -Name $apimServiceName
if ($ConfigJson.WingetURL)
{
$ConfigJson.WingetURL = "$($apimContext.RuntimeUrl)/winget/"
}else{
$ConfigJson | Add-Member -Type NoteProperty -Name "WingetURL" -Value "$($apimContext.RuntimeUrl)/winget/"
}
$json = $ConfigJson | ConvertTo-Json -Depth 32 # Use -Depth if you have nested structures
Set-Content -Path "$($folder)\config.json" -Value $json