-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathessentials.ps1
More file actions
165 lines (133 loc) · 5.55 KB
/
essentials.ps1
File metadata and controls
165 lines (133 loc) · 5.55 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
152
153
154
155
156
157
158
159
160
161
162
163
164
165
# 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..."
Invoke-WebRequest -UseBasicParsing -Uri "https://aka.ms/Microsoft.VCLibs.x64.14.00.Desktop.appx" -OutFile "$sourcePath\Microsoft.VCLibs.x64.14.00.Desktop.appx"
Write-Output "Downloading dependency microsoft.ui.xaml.2.8.6.nupkg..."
Invoke-WebRequest -UseBasicParsing -Uri "https://www.nuget.org/api/v2/package/Microsoft.UI.Xaml/2.8.6" -OutFile "$sourcePath\microsoft.ui.xaml.2.8.6.nupkg"
# 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"
Invoke-WebRequest -UseBasicParsing -Uri $downloadSource -OutFile $destinationPath
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) {
Invoke-WebRequest -UseBasicParsing -Uri $downloadSourceLic -OutFile "${PSScriptRoot}\sources\$downloadFilenameLic"
}
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
}
# 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/terminal/releases/latest',
'https://api.github.com/repos/microsoft/winget-cli/releases/latest')
# Winget software IDs to install
$winGetInstallSoftware = @('Microsoft.PowerShell', '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
}
}
# Check if winget command exists
if (-not (Get-Command winget -ErrorAction SilentlyContinue)) {
Write-Host "winget command not found. Attempting to refresh the PowerShell session..."
# Refresh the PowerShell session environment
. $profile
# Recheck if winget command is now available
if (-not (Get-Command winget -ErrorAction SilentlyContinue)) {
Write-Host "Failed to recognize winget command after refresh. Please restart PowerShell."
} else {
Write-Host "winget command recognized after refresh."
# Install with winget
foreach ($id in $winGetInstallSoftware) {
WinGetInstall $id
}
}
} else {
# Install with winget
foreach ($id in $winGetInstallSoftware) {
WinGetInstall $id
}
}
# Re-enable ProgressBars
$ProgressPreference = 'Continue'