Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <#PSScriptInfo
- .VERSION # 2024-08-28 (Beta)
- .AUTHOR mlot (sr.ht) / beevomit (github)
- .COPYRIGHT 2024
- .LICENSEURI https://opensource.org/licenses/MIT
- #>
- <#
- .SYNOPSIS
- Downloads the latest version of Cleed for Windows based on the system architecture saving it in the user profile "Downloads" folder.
- .NOTES
- https://github.com/radulucut/cleed
- Run "cleed --version" to check your current version against the latest available download.
- #>
- function Get-CleedLastestVersion {
- $url = 'https://github.com/radulucut/cleed/releases/latest'
- $request = [System.Net.WebRequest]::Create($url)
- $response = $request.GetResponse()
- $realTagUrl = $response.ResponseUri.OriginalString
- $version = $realTagUrl.split('/')[-1].Trim('v')
- Return $version, $realTagUrl
- }
- function Request-LatestCleedDownload {
- param (
- # Message about error/success to display in email body
- [Parameter(Mandatory=$true)]
- [string]
- $realTagUrl
- )
- $OsArchitecture = Get-SystemArchitecture
- switch ($OsArchitecture) {
- {$OsArchitecture -match "64-bit"} {$filename = "cleed_Windows_x86_64.zip"; break}
- {$OsArchitecture -match "32-bit"} {$filename = "cleed_Windows_i386.zip"; break}
- {$OsArchitecture -match "ARM64"} {$filename = "cleed_Windows_arm64.zip"; break}
- Default {$filename = "cleed_Windows_x86_64.zip"; break}
- }
- $realDownloadUrl = $realTagUrl.Replace('tag', 'download') + '/' + $fileName
- try {
- Invoke-WebRequest -Uri $realDownloadUrl -OutFile $env:USERPROFILE/Downloads/$fileName -MaximumRedirection 9
- } catch {
- Write-Host -ForegroundColor Red "There was a problem downloading the latest version! Aborting..."
- Exit(1)
- }
- Write-Host -ForegroundColor Green "Downloading complete."
- Return $null
- }
- function Get-SystemArchitecture {
- $Architecture = (Get-ComputerInfo).OsArchitecture
- Return $Architecture
- }
- function Start-Main {
- $LatestVersion,$DownloadURL = Get-CleedLastestVersion
- Write-Host -ForegroundColor Cyan "Cleed Latest Version is: $LatestVersion"
- $continueToDownload = Read-Host -Prompt "Do you want to download the latest version? (y/n)"
- if ($continueToDownload -eq "y") {
- Write-Host -ForegroundColor Green "Downloading latest version of Cleed for Windows..."
- Request-LatestCleedDownload -realTagUrl $DownloadURL
- } else {
- Write-Host -ForegroundColor Red "Downloading aborted by user!"
- Exit(1)
- }
- Return $null
- }
- Start-Main
- Exit(0)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement