Add winget repair helper and remove winget configure --enable prerequisite
Initialize-Winget.ps1 refreshes PATH, re-registers App Installer and falls back to the provisioned package before exiting with a Store link. All scripts that call winget now dot-source this helper instead of failing on a missing winget. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
+2
-8
@@ -31,15 +31,9 @@ Petite boîte à outils Windows pour installer des packs de logiciels libres ave
|
||||
|
||||
## ✅ Prérequis
|
||||
|
||||
Lance les commandes depuis un **terminal administrateur** sous Windows.
|
||||
Lance les commandes depuis un **terminal administrateur** sous Windows. winget doit être disponible (App Installer depuis le Microsoft Store).
|
||||
|
||||
Active d'abord la prise en charge des configurations winget :
|
||||
|
||||
```powershell
|
||||
winget configure --enable
|
||||
```
|
||||
|
||||
Les packs YAML automatisés n'imposent pas de version précise de Windows. Ils nécessitent un système Windows avec la prise en charge des configurations winget activée.
|
||||
Les packs YAML automatisés nécessitent winget 1.6 ou version ultérieure.
|
||||
|
||||
<a id="installateur-interactif"></a>
|
||||
|
||||
|
||||
@@ -31,15 +31,9 @@ Small Windows toolkit to install libre software packs with `winget` and remove s
|
||||
|
||||
## ✅ Requirements
|
||||
|
||||
Run the commands from an **administrator terminal** on Windows.
|
||||
Run the commands from an **administrator terminal** on Windows. winget must be available (App Installer from the Microsoft Store).
|
||||
|
||||
Enable winget configuration support first:
|
||||
|
||||
```powershell
|
||||
winget configure --enable
|
||||
```
|
||||
|
||||
The automated YAML packs do not enforce a specific Windows release. They require a Windows system with winget configuration support enabled.
|
||||
The automated YAML packs require winget 1.6 or later.
|
||||
|
||||
<a id="interactive-installer"></a>
|
||||
|
||||
|
||||
@@ -0,0 +1,72 @@
|
||||
# Shared helper: ensures winget is accessible before use.
|
||||
# Dot-source this script and call Initialize-Winget at startup.
|
||||
# Repair operations require administrator rights.
|
||||
|
||||
function Initialize-Winget {
|
||||
if (Get-Command winget -ErrorAction SilentlyContinue) {
|
||||
return
|
||||
}
|
||||
|
||||
Write-Host "winget not found in PATH. Attempting repair..." -ForegroundColor Yellow
|
||||
|
||||
# Refresh PATH from registry in case a recent install is not yet visible
|
||||
$MachinePath = [System.Environment]::GetEnvironmentVariable("PATH", "Machine")
|
||||
$UserPath = [System.Environment]::GetEnvironmentVariable("PATH", "User")
|
||||
$env:PATH = $MachinePath + ";" + $UserPath
|
||||
|
||||
if (Get-Command winget -ErrorAction SilentlyContinue) {
|
||||
Write-Host "winget available after PATH refresh." -ForegroundColor Green
|
||||
return
|
||||
}
|
||||
|
||||
# Try to re-register the installed App Installer package
|
||||
$AppInstaller = Get-AppxPackage -Name "Microsoft.DesktopAppInstaller" -ErrorAction SilentlyContinue
|
||||
if (-not $AppInstaller) {
|
||||
$AppInstaller = Get-AppxPackage -AllUsers -Name "Microsoft.DesktopAppInstaller" -ErrorAction SilentlyContinue
|
||||
}
|
||||
|
||||
if ($AppInstaller) {
|
||||
Write-Host "Re-registering App Installer..." -ForegroundColor Yellow
|
||||
try {
|
||||
$Manifest = Join-Path $AppInstaller.InstallLocation "AppxManifest.xml"
|
||||
Add-AppxPackage -DisableDevelopmentMode -Register $Manifest -ErrorAction Stop
|
||||
$env:PATH = [System.Environment]::GetEnvironmentVariable("PATH", "Machine") + ";" +
|
||||
[System.Environment]::GetEnvironmentVariable("PATH", "User")
|
||||
|
||||
if (Get-Command winget -ErrorAction SilentlyContinue) {
|
||||
Write-Host "winget repaired." -ForegroundColor Green
|
||||
return
|
||||
}
|
||||
}
|
||||
catch {
|
||||
Write-Warning "Re-registration failed: $_"
|
||||
}
|
||||
}
|
||||
|
||||
# Try to reinstall from the provisioned (staged) package on this machine
|
||||
$StagedPackage = Get-AppxProvisionedPackage -Online -ErrorAction SilentlyContinue |
|
||||
Where-Object { $_.DisplayName -eq "Microsoft.DesktopAppInstaller" } |
|
||||
Select-Object -First 1
|
||||
|
||||
if ($StagedPackage) {
|
||||
Write-Host "Installing App Installer from provisioned package..." -ForegroundColor Yellow
|
||||
try {
|
||||
Add-AppxPackage -Path $StagedPackage.PackagePath -ErrorAction Stop
|
||||
$env:PATH = [System.Environment]::GetEnvironmentVariable("PATH", "Machine") + ";" +
|
||||
[System.Environment]::GetEnvironmentVariable("PATH", "User")
|
||||
|
||||
if (Get-Command winget -ErrorAction SilentlyContinue) {
|
||||
Write-Host "winget installed." -ForegroundColor Green
|
||||
return
|
||||
}
|
||||
}
|
||||
catch {
|
||||
Write-Warning "Installation from provisioned package failed: $_"
|
||||
}
|
||||
}
|
||||
|
||||
Write-Error ("winget is not available and could not be repaired automatically.`n" +
|
||||
"Install App Installer from the Microsoft Store: " +
|
||||
"ms-windows-store://pdp/?productid=9nblggh4nns1")
|
||||
exit 1
|
||||
}
|
||||
@@ -9,6 +9,8 @@ param(
|
||||
|
||||
$ErrorActionPreference = "Stop"
|
||||
|
||||
. (Join-Path $PSScriptRoot "Initialize-Winget.ps1")
|
||||
|
||||
$IsAdministrator = ([Security.Principal.WindowsPrincipal] [Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole(
|
||||
[Security.Principal.WindowsBuiltInRole]::Administrator
|
||||
)
|
||||
@@ -23,10 +25,7 @@ function Install-FirefoxEsr {
|
||||
[string]$PackageId
|
||||
)
|
||||
|
||||
if (-not (Get-Command winget -ErrorAction SilentlyContinue)) {
|
||||
Write-Error "winget was not found. Install App Installer or enable winget before running this script."
|
||||
exit 1
|
||||
}
|
||||
Initialize-Winget
|
||||
|
||||
Write-Host "Installing Firefox ESR with winget: $PackageId" -ForegroundColor Cyan
|
||||
|
||||
|
||||
@@ -1,6 +1,9 @@
|
||||
# Requires running as administrator
|
||||
# Uninstalling Windows applications via winget
|
||||
|
||||
. (Join-Path $PSScriptRoot "Initialize-Winget.ps1")
|
||||
Initialize-Winget
|
||||
|
||||
$Packages = @(
|
||||
"Windows Web Experience Pack",
|
||||
"Xbox",
|
||||
|
||||
@@ -1,12 +1,8 @@
|
||||
# Script d'installation de logiciels avec winget
|
||||
# Permet de choisir les logiciels a installer
|
||||
|
||||
# Verification que winget est installe
|
||||
if (-not (Get-Command winget -ErrorAction SilentlyContinue)) {
|
||||
Write-Host "ERREUR: winget n'est pas installe sur ce systeme." -ForegroundColor Red
|
||||
Write-Host "Veuillez installer le 'App Installer' depuis le Microsoft Store." -ForegroundColor Yellow
|
||||
exit 1
|
||||
}
|
||||
. (Join-Path $PSScriptRoot "Initialize-Winget.ps1")
|
||||
Initialize-Winget
|
||||
|
||||
Write-Host "===========================================================" -ForegroundColor Cyan
|
||||
Write-Host " Script d'installation de logiciels avec winget" -ForegroundColor Cyan
|
||||
|
||||
Reference in New Issue
Block a user