mirror of
https://github.com/ChrisTitusTech/winutil
synced 2026-02-04 06:50:09 +00:00
Update-windev.ps1 (#3843)
* Update windev.ps1 * Update windev.ps1 * Update windev.ps1 * Update windev.ps1 * Update windev.ps1 * Update windev.ps1
This commit is contained in:
48
windev.ps1
48
windev.ps1
@@ -1,55 +1,13 @@
|
|||||||
<#
|
<#
|
||||||
.SYNOPSIS
|
.SYNOPSIS
|
||||||
This Script is used as a target for the https://christitus.com/windev alias.
|
This Script is used as a target for the https://christitus.com/windev alias.
|
||||||
It queries the latest winget release (no matter if Pre-Release, Draft or Full Release) and invokes It
|
|
||||||
.DESCRIPTION
|
.DESCRIPTION
|
||||||
This Script provides a simple way to always start the bleeding edge release even if it's not yet a full release.
|
This Script provides a simple way to start the bleeding edge release of winutil.
|
||||||
This function should be run with administrative privileges.
|
|
||||||
Because this way of recursively invoking scripts via Invoke-Expression it might very well happen that AV Programs flag this because it's a common way of mulitstage exploits to run
|
|
||||||
.EXAMPLE
|
.EXAMPLE
|
||||||
irm https://christitus.com/windev | iex
|
irm https://christitus.com/windev | iex
|
||||||
OR
|
OR
|
||||||
Run in Admin Powershell > ./windev.ps1
|
Run in Admin Powershell > ./windev.ps1
|
||||||
#>
|
#>
|
||||||
|
|
||||||
# Function to fetch the latest release tag from the GitHub API
|
$latestTag = (Invoke-RestMethod 'https://api.github.com/repos/ChrisTitusTech/winutil/releases')[0].tag_name
|
||||||
function Get-LatestRelease {
|
Invoke-RestMethod "https://github.com/ChrisTitusTech/winutil/releases/download/$latestTag/winutil.ps1" | Invoke-Expression
|
||||||
try {
|
|
||||||
$releases = Invoke-RestMethod -Uri 'https://api.github.com/repos/ChrisTitusTech/winutil/releases'
|
|
||||||
$latestRelease = $releases | Where-Object {$_.prerelease -eq $true} | Select-Object -First 1
|
|
||||||
return $latestRelease.tag_name
|
|
||||||
} catch {
|
|
||||||
Write-Host "Error fetching release data: $_" -ForegroundColor Red
|
|
||||||
return $latestRelease.tag_name
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
# Function to redirect to the latest pre-release version
|
|
||||||
function RedirectToLatestPreRelease {
|
|
||||||
$latestRelease = Get-LatestRelease
|
|
||||||
if ($latestRelease) {
|
|
||||||
$url = "https://github.com/ChrisTitusTech/winutil/releases/download/$latestRelease/winutil.ps1"
|
|
||||||
} else {
|
|
||||||
Write-Host 'No pre-release version found. This is most likely because the latest release is a full release and no newer pre-release exists.' -ForegroundColor Yellow
|
|
||||||
Write-Host "Using latest Full Release"
|
|
||||||
$url = "https://github.com/ChrisTitusTech/winutil/releases/latest/download/winutil.ps1"
|
|
||||||
}
|
|
||||||
|
|
||||||
$script = Invoke-RestMethod $url
|
|
||||||
# Elevate Shell if necessary
|
|
||||||
if (!([Security.Principal.WindowsPrincipal][Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator)) {
|
|
||||||
Write-Output "Winutil needs to be run as Administrator. Attempting to relaunch."
|
|
||||||
|
|
||||||
$powershellcmd = if (Get-Command pwsh -ErrorAction SilentlyContinue) { "pwsh" } else { "powershell" }
|
|
||||||
$processCmd = if (Get-Command wt.exe -ErrorAction SilentlyContinue) { "wt.exe" } else { $powershellcmd }
|
|
||||||
|
|
||||||
Start-Process $processCmd -ArgumentList "$powershellcmd -ExecutionPolicy Bypass -NoProfile -Command $(Invoke-Expression $script)" -Verb RunAs
|
|
||||||
}
|
|
||||||
else{
|
|
||||||
Invoke-Expression $script
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
# Call the redirect function
|
|
||||||
|
|
||||||
RedirectToLatestPreRelease
|
|
||||||
|
|||||||
Reference in New Issue
Block a user