Skip to content

Commit

Permalink
Adjust UpdateSelf function to reset PSGallery to original state if it…
Browse files Browse the repository at this point in the history
… was not trusted.
  • Loading branch information
asheroto committed Feb 15, 2024
1 parent 6986340 commit ff5a1ef
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 12 deletions.
26 changes: 15 additions & 11 deletions Install-WindowsTerminal.ps1
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<#PSScriptInfo
.VERSION 0.0.1
.VERSION 0.0.2
.GUID 98cb59b3-0489-4609-9c31-4f85be9433ea
Expand All @@ -14,6 +14,7 @@
.RELEASENOTES
[Version 0.0.1] - Initial Release.
[Version 0.0.2] - Adjust UpdateSelf function to reset PSGallery to original state if it was not trusted.
#>

Expand All @@ -35,7 +36,7 @@
.PARAMETER Help
Displays the full help information for the script.
.NOTES
Version : 0.0.1
Version : 0.0.2
Created by : asheroto
.LINK
Project Site: https://github.com/asheroto/Install-WindowsTerminal
Expand All @@ -50,7 +51,7 @@ param (
)

# Version
$CurrentVersion = '0.0.1'
$CurrentVersion = '0.0.2'
$RepoOwner = 'asheroto'
$RepoName = 'Install-WindowsTerminal'
$PowerShellGalleryName = 'Install-WindowsTerminal'
Expand Down Expand Up @@ -289,19 +290,22 @@ function UpdateSelf {
Write-Output "Updating script to version $psGalleryScriptVersion..."

# Install NuGet PackageProvider if not already installed
if (-not (Get-PackageProvider -Name NuGet -ErrorAction SilentlyContinue)) {
Install-PackageProvider -Name "NuGet" -Force
}
Install-PackageProvider -Name "NuGet" -Force

# Trust the PSGallery if not already trusted
$repo = Get-PSRepository -Name 'PSGallery'
if ($repo.InstallationPolicy -ne 'Trusted') {
Set-PSRepository -Name 'PSGallery' -InstallationPolicy Trusted
$psRepoInstallationPolicy = (Get-PSRepository -Name 'PSGallery').InstallationPolicy
if ($psRepoInstallationPolicy -ne 'Trusted') {
Set-PSRepository -Name 'PSGallery' -InstallationPolicy Trusted | Out-Null
}

# Update the script
Install-Script $PowerShellGalleryName -Force

# If PSGallery was not trusted, reset it to its original state
if ($psRepoInstallationPolicy -ne 'Trusted') {
Set-PSRepository -Name 'PSGallery' -InstallationPolicy $psRepoInstallationPolicy | Out-Null
}

Write-Output "Script updated to version $psGalleryScriptVersion."
exit 0
} else {
Expand Down Expand Up @@ -599,7 +603,7 @@ if ((-not (Get-WindowsTerminalStatus)) -or $Force) {

# Indent the process
Strip-ProgressIndent -ScriptBlock {
winget install Microsoft.WindowsTerminal --accept-package-agreements --accept-source-agreements --force
winget install Microsoft.WindowsTerminal --accept-package-agreements --accept-source-agreements --force --silent --disable-interactivity
}

# Confirm Windows Terminal is installed
Expand All @@ -611,7 +615,7 @@ if ((-not (Get-WindowsTerminalStatus)) -or $Force) {

# Indent the process
Strip-ProgressIndent -ScriptBlock {
winget install "windows terminal" --source "msstore" --accept-package-agreements --accept-source-agreements --force
winget install "windows terminal" --source "msstore" --accept-package-agreements --accept-source-agreements --force --silent --disable-interactivity
}

if (Get-WindowsTerminalStatus) {
Expand Down
7 changes: 6 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -104,4 +104,9 @@ As a more conventional approach, download the latest [Install-WindowsTerminal.ps

```powershell
Install-WindowsTerminal -Force
```
```

## Troubleshooting
- I'm seeing a bunch of characters like `ΓûêΓûêΓûêΓûêΓûê` on step 2.
- This is a [known issue](https://github.com/microsoft/winget-cli/issues/2582) of `winget` and has to due with the inability to turn off winget output, despite using `--silent` and `--disable-interactivity`.
- To help avoid this, the `Strip-Progress` function has been implemented, and although it works for step 1, it doesn't work as well as hoped in step 2.

0 comments on commit ff5a1ef

Please sign in to comment.