@ -2,19 +2,14 @@ function Test-WinUtilPackageManager {
<#
<#
. SYNOPSIS
. SYNOPSIS
Checks if Winget and / or Choco are installed
Checks if Winget is installed
. PARAMETER winget
. PARAMETER winget
Check if Winget is installed
Check if Winget is installed
. PARAMETER choco
Check if Chocolatey is installed
#>
#>
Param (
Param (
[System.Management.Automation.SwitchParameter] $winget ,
[System.Management.Automation.SwitchParameter] $winget
[System.Management.Automation.SwitchParameter] $choco
)
)
$status = " not-installed "
$status = " not-installed "
@ -78,21 +73,6 @@ function Test-WinUtilPackageManager {
}
}
}
}
if ( $choco ) {
if ( ( Get-Command -Name choco -ErrorAction Ignore ) -and ( $chocoVersion = ( Get-Item " $ env:ChocolateyInstall\choco.exe " -ErrorAction Ignore ) . VersionInfo . ProductVersion ) ) {
Write-Host " =========================================== " -ForegroundColor Green
Write-Host " --- Chocolatey is installed --- " -ForegroundColor Green
Write-Host " =========================================== " -ForegroundColor Green
Write-Host " Version: v $ chocoVersion " -ForegroundColor White
$status = " installed "
} else {
Write-Host " =========================================== " -ForegroundColor Red
Write-Host " --- Chocolatey is not installed --- " -ForegroundColor Red
Write-Host " =========================================== " -ForegroundColor Red
$status = " not-installed "
}
}
return $status
return $status
}
}
@ -206,20 +186,10 @@ function Install-WinUtilWinget {
Write-Output " Refreshing Environment Variables... `n "
Write-Output " Refreshing Environment Variables... `n "
$ENV:PATH = [System.Environment] :: GetEnvironmentVariable ( " Path " , " Machine " ) + " ; " + [System.Environment] :: GetEnvironmentVariable ( " Path " , " User " )
$ENV:PATH = [System.Environment] :: GetEnvironmentVariable ( " Path " , " Machine " ) + " ; " + [System.Environment] :: GetEnvironmentVariable ( " Path " , " User " )
} Catch {
} Catch {
Write-Host " Failure detected while installing via GitHub method. Continuing with Chocolatey method as fallback. " -ForegroundColor Red
Write-Host " Failure detected while installing via GitHub method. Your computer cannot run winget. Please email help@learncodethehardway.com to help find out why. " -ForegroundColor Red
# In case install fails via GitHub method.
Try {
# Install Choco if not already present
Install-WinUtilChoco
Start-Process -Verb runas -FilePath powershell . exe -ArgumentList " choco install winget-cli "
Write-Host " Winget Installed " -ForegroundColor Green
Write-Output " Refreshing Environment Variables... `n "
$ENV:PATH = [System.Environment] :: GetEnvironmentVariable ( " Path " , " Machine " ) + " ; " + [System.Environment] :: GetEnvironmentVariable ( " Path " , " User " )
} Catch {
throw [WingetFailedInstall] :: new ( 'Failed to install!' )
throw [WingetFailedInstall] :: new ( 'Failed to install!' )
}
}
}
}
}
$isAdmin = [System.Security.Principal.WindowsPrincipal] :: new (
$isAdmin = [System.Security.Principal.WindowsPrincipal] :: new (
[System.Security.Principal.WindowsIdentity] :: GetCurrent ( ) ) .
[System.Security.Principal.WindowsIdentity] :: GetCurrent ( ) ) .
@ -235,7 +205,10 @@ if(-not $isAdmin) {
)
)
}
}
Write-Warning " About to install winget "
Write-Warning " About to install winget. Winget is a Microsoft open source package manager. "
Write-Warning " To install Winget this script will temporarily launch in Administrator mode, then get out of it. "
Write-Warning " If you already have Winget then this will only check that you have it, or upgrade it. "
Write-Warning " If you'd prefer to not use it then abort now and good luck getting everything installed. "
Read-Host -Prompt " Press any key to continue, or CTRL-C to abort " | Out-Null
Read-Host -Prompt " Press any key to continue, or CTRL-C to abort " | Out-Null
@ -256,14 +229,11 @@ $installs=@(
'Microsoft.VCRedist.2015+.x64'
'Microsoft.VCRedist.2015+.x64'
)
)
$choco_installs = @ ( )
Write-Warning " About to install the following software: "
Write-Warning " About to install the following software: "
Write-Warning " ----------------------------------------- "
Write-Warning " ----------------------------------------- "
foreach ( $pkg in $installs ) { Write-Host $pkg }
foreach ( $pkg in $installs ) { Write-Host $pkg }
foreach ( $pkg in $choco_installs ) { Write-Host $pkg }
Write-Warning " ----------------------------------------- "
Write-Warning " ----------------------------------------- "
Write-Warning " This will use winget and chocolatey to do the installs . "
Write-Warning " This will use winget to do the installs. If you already have this software installed then winget should only upgrade them. If you don't want this then abort now . "
Read-Host -Prompt " Press any key to continue, or CTRL-C to abort " | Out-Null
Read-Host -Prompt " Press any key to continue, or CTRL-C to abort " | Out-Null
@ -271,13 +241,36 @@ foreach($pkg in $installs) {
Start-Process -NoNewWindow -Wait winget -ArgumentList 'install' , $pkg
Start-Process -NoNewWindow -Wait winget -ArgumentList 'install' , $pkg
}
}
Write-Warning " !! Installing WinLibs in $ env:HOMEPATH\WinLibs "
$winlibsPath = " $ env:HOMEDRIVE $ env:HOMEPATH\WinLibs "
if ( Test-Path -Path $winlibsPath ) {
Write-Warning " #=========================================================# "
Write-Warning " !! The directory $ winlibsPath already exists, which means "
Write-Warning " !! you already have winlibs installed. Here's the version: "
cat " $ winlibsPath\mingw64\version_info.txt "
Write-Warning " #=========================================================# "
Write-Warning " Here's the version that Winget will install: "
winget search BrechtSanders . WinLibs . POSIX . UCRT . LLVM
Write-Warning " --- If you want me to replace your install with this version, then stop and "
Write-Warning " delete the $ winlibsPath directory before hitting ENTER to continue. "
Write-Warning " !!! If you do NOT want to replace this directory then hit CTRL-C now. "
Read-Host -Prompt " Press any key to continue, or CTRL-C to abort " | Out-Null
}
Write-Warning " !! Installing WinLibs in $ winlibsPath "
Write-Warning " This has to be installed this way because winget won't add it to the path so I have to do it manually. If you don't want this, then hit CTRL-C and install WinLibs yourself. "
Write-Warning " This has to be installed this way because winget won't add it to the path so I have to do it manually. If you don't want this, then hit CTRL-C and install WinLibs yourself. "
Read-Host -Prompt " Press any key to continue, or CTRL-C to abort " | Out-Null
Read-Host -Prompt " Press any key to continue, or CTRL-C to abort " | Out-Null
winget install - -location " $ env:HOMEPATH\WinLibs " -e BrechtSanders . WinLibs . POSIX . UCRT . LLVM
winget install - -location " $ winlibsPath " -e BrechtSanders . WinLibs . POSIX . UCRT . LLVM
$newPath = $Env:PATH + " ; $ env:HOMEPATH\WinLibs\mingw64\bin "
if ( $env:PATH . contains ( $winlibsPath ) ) {
Write-Warning " !! Detected $ winLibsPath in your PATH. Will not update your PATH. "
Write-Warning " !! This is probably because you already installed it. You'll have "
Write-Warning " !! to manually remove this part of your path if you want to change it. "
Write-Warning " !! But, it will probably still work since that's where I installed it. "
} else {
$newPath = $Env:PATH + " ; $ winlibsPath\mingw64\bin "
[Environment] :: SetEnvironmentVariable ( " Path " , $newPath , " User " )
[Environment] :: SetEnvironmentVariable ( " Path " , $newPath , " User " )
}
Write-Warning " !!! CLOSE THIS POWERSHELL AND START A NEW ONE TO UPDATE PATH! "
Write-Warning " !!! CLOSE THIS POWERSHELL AND START A NEW ONE TO UPDATE PATH! "