2024-06-28 16:13:12 -05:00
|
|
|
<#
|
|
|
|
.SYNOPSIS
|
|
|
|
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
|
|
|
|
This Script provides a simple way to always start the bleeding edge release even if it's not yet a full release.
|
|
|
|
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
|
2024-06-28 17:15:39 -05:00
|
|
|
irm https://christitus.com/windev | iex
|
2024-06-28 16:13:12 -05:00
|
|
|
OR
|
|
|
|
Run in Admin Powershell > ./windev.ps1
|
|
|
|
#>
|
|
|
|
|
2024-08-28 11:52:53 -05:00
|
|
|
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."
|
2024-08-30 12:46:00 -05:00
|
|
|
# Capture all the arguments passed to the script
|
|
|
|
$argList = $args -join ' '
|
|
|
|
|
|
|
|
$script = if ($MyInvocation.MyCommand.Path) {
|
|
|
|
"& { & '$($MyInvocation.MyCommand.Path)' $argList }"
|
|
|
|
} else {
|
|
|
|
"iex '& { $(irm https://github.com/ChrisTitusTech/winutil/raw/main/windev.ps1) } $argList'"
|
|
|
|
}
|
2024-08-28 11:52:53 -05:00
|
|
|
|
|
|
|
$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 $script" -Verb RunAs
|
|
|
|
|
|
|
|
break
|
|
|
|
}
|
|
|
|
|
2024-06-28 16:13:12 -05:00
|
|
|
# Function to fetch the latest release tag from the GitHub API
|
|
|
|
function Get-LatestRelease {
|
|
|
|
try {
|
|
|
|
$releases = Invoke-RestMethod -Uri 'https://api.github.com/repos/ChrisTitusTech/winutil/releases'
|
2024-06-29 06:46:52 -05:00
|
|
|
$latestRelease = $releases | Where-Object {$_.prerelease -eq $true} | Select-Object -First 1
|
2024-06-28 16:13:12 -05:00
|
|
|
return $latestRelease.tag_name
|
|
|
|
} catch {
|
|
|
|
Write-Host "Error fetching release data: $_" -ForegroundColor Red
|
2024-07-08 15:02:53 -05:00
|
|
|
return $latestRelease.tag_name
|
2024-06-28 16:13:12 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
# Function to redirect to the latest pre-release version
|
|
|
|
function RedirectToLatestPreRelease {
|
|
|
|
$latestRelease = Get-LatestRelease
|
|
|
|
if ($latestRelease) {
|
2024-08-07 21:06:42 -05:00
|
|
|
$url = "https://github.com/ChrisTitusTech/winutil/releases/download/$latestRelease/winutil.ps1"
|
2024-06-28 16:13:12 -05:00
|
|
|
} else {
|
|
|
|
Write-Host 'Unable to determine latest pre-release version.' -ForegroundColor Red
|
2024-07-08 15:02:53 -05:00
|
|
|
Write-Host "Using latest Full Release"
|
|
|
|
$url = "https://github.com/ChrisTitusTech/winutil/releases/latest/download/winutil.ps1"
|
2024-06-28 16:13:12 -05:00
|
|
|
}
|
2024-08-30 12:46:00 -05:00
|
|
|
|
|
|
|
iex "& { $(irm $url) } $argList"
|
2024-06-28 16:13:12 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
# Call the redirect function
|
2024-07-08 15:02:53 -05:00
|
|
|
RedirectToLatestPreRelease
|