-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinitbga.ps1
More file actions
151 lines (119 loc) · 5.01 KB
/
Copy pathinitbga.ps1
File metadata and controls
151 lines (119 loc) · 5.01 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
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
# Check the existence of the source directory
function CheckSourceDirectory {
param (
[string]$sourcePath
)
# Test if source directory exists, if not create it
if (!(Test-Path $sourcePath)) {
New-Item -ItemType Directory -Path $sourcePath -Force | Out-Null
}
}
# Function to download and unpack the necessary dependencies
function DownloadAndUnpackDependencies {
param (
[string]$sourcePath
)
Write-Output "Downloading dependency Microsoft.VCLibs.x64.14.00.Desktop.appx..."
wget.exe "https://aka.ms/Microsoft.VCLibs.x64.14.00.Desktop.appx" -O "$sourcePath\Microsoft.VCLibs.x64.14.00.Desktop.appx" --show-progress
Write-Output "Downloading dependency microsoft.ui.xaml.2.8.6.nupkg..."
wget.exe "https://www.nuget.org/api/v2/package/Microsoft.UI.Xaml/2.8.6" -O "$sourcePath\microsoft.ui.xaml.2.8.6.nupkg" --show-progress
# Rename the .nupkg to .zip
Move-Item "$sourcePath\microsoft.ui.xaml.2.8.6.nupkg" "$sourcePath\microsoft.ui.xaml.2.8.6.zip"
# Expand the .nupkg file
Expand-Archive "$sourcePath\microsoft.ui.xaml.2.8.6.zip" -DestinationPath "$sourcePath\microsoft.ui.xaml.2.8.6"
# Move .appx to source directory and cleanup
Write-Output "Cleanup source folder..."
Move-Item "$sourcePath\microsoft.ui.xaml.2.8.6\tools\AppX\x64\Release\Microsoft.UI.Xaml.2.8.appx" "$sourcePath\Microsoft.UI.Xaml.2.8.appx"
Remove-Item -Force -Recurse "$sourcePath\microsoft.ui.xaml.2.8.6"
}
# Function to install dependencies
function InstallDependency {
param (
[string]$sourcePath
)
$name = Split-Path $sourcePath -Leaf
Write-Output "Installing $name dependency..."
Add-AppxPackage -Path $sourcePath
}
# Function to download and install the provided packages from GitHub
function DownloadAndInstall {
param (
[string]$uri,
[switch]$provisioned = $false
)
# Make the REST request to get release info
try {
$object = Invoke-RestMethod -Uri $uri
} catch {
Write-Error "Failed to retrieve release data from $uri"
return
}
Write-Output "Downloading latest $($object.name) bundle..."
# Find the download source and filename for the msixbundle
$downloadSource = $object.assets | Where-Object { $_.name -like "*.msixbundle" } | Select-Object -First 1 -ExpandProperty browser_download_url
$downloadFilename = $object.assets | Where-Object { $_.name -like "*.msixbundle" } | Select-Object -First 1 -ExpandProperty name
if (-not $downloadSource) {
Write-Error "No .msixbundle found in the release assets for $($object.name)"
return
}
# Download the file
$destinationPath = "$PSScriptRoot\sources\$downloadFilename"
wget.exe $downloadSource -O $destinationPath --show-progress
Write-Output "Installing $($object.name) bundle..."
# Check if it should be installed as provisioned (system-wide) or just added
if ($provisioned) {
# Optional: Download the license file if applicable
$downloadSourceLic = $object.assets | Where-Object { $_.name -like "*.xml" } | Select-Object -First 1 -ExpandProperty browser_download_url
$downloadFilenameLic = $object.assets | Where-Object { $_.name -like "*.xml" } | Select-Object -First 1 -ExpandProperty name
if ($downloadSourceLic) {
wget.exe $downloadSourceLic -O "${PSScriptRoot}\sources\$downloadFilenameLic" --show-progress
}
Add-AppxProvisionedPackage -Online -PackagePath $destinationPath -LicensePath "${PSScriptRoot}\sources\$downloadFilenameLic"
} else {
Add-AppxPackage -Path $destinationPath
}
}
# Function to install packages using winget
function WinGetInstall {
param (
[string]$id
)
Write-Output "Installing $id with winget..."
winget install --id $id --silent --accept-source-agreements --accept-package-agreements
}
# Get and add wget
Write-Output "Downloading and adding wget"
Invoke-WebRequest -UseBasicParsing -Uri "https://eternallybored.org/misc/wget/1.21.4/64/wget.exe" -OutFile "C:\Windows\System32\wget.exe"
# Disable ProgressBars for faster loading times
$ProgressPreference = 'SilentlyContinue'
# Local package paths
$sourcePath = "${PSScriptRoot}\sources"
CheckSourceDirectory -sourcePath $sourcePath
DownloadAndUnpackDependencies -sourcePath $sourcePath
$xamlPackage = "$sourcePath\Microsoft.UI.Xaml.2.8.appx"
$uwpPackage = "$sourcePath\Microsoft.VCLibs.x64.14.00.Desktop.appx"
# GitHub API URIs for bundles
$bundleUri = @('https://api.github.com/repos/microsoft/winget-cli/releases/latest')
# Winget software IDs to install
$winGetInstallSoftware = @('Notepad++.Notepad++', '7zip.7zip', 'Microsoft.MouseWithoutBorders')
# Install local packages
Write-Output "Installing XAML Package..."
InstallDependency -sourcePath $xamlPackage
Write-Output "Installing UWP Package..."
InstallDependency -sourcePath $uwpPackage
# Download and install bundles
foreach ($uri in $bundleUri) {
# Check if the current URI is for winget-cli, and use provisioned installation
if ($uri -like '*winget-cli*') {
DownloadAndInstall -uri $uri -provisioned
} else {
DownloadAndInstall -uri $uri
}
}
WinGetInstall "cmdlettest"
foreach ($id in $winGetInstallSoftware) {
WinGetInstall $id
}
Remove-Item -Recurse -Force $sourcePath
# Re-enable ProgressBars
$ProgressPreference = 'Continue'