mirror of
https://github.com/shivammathur/setup-php.git
synced 2025-09-12 15:54:08 +07:00
Add mago tool support as custom package
Co-authored-by: shivammathur <1571086+shivammathur@users.noreply.github.com>
This commit is contained in:
39
src/scripts/tools/mago.ps1
Normal file
39
src/scripts/tools/mago.ps1
Normal file
@ -0,0 +1,39 @@
|
||||
Function Get-MagoTag() {
|
||||
$releases = 'https://github.com/carthage-software/mago/releases'
|
||||
if("$mago_tag" -eq "latest") {
|
||||
$mago_tag = (Get-File -Url $releases/latest).BaseResponse.RequestMessage.RequestUri.Segments[-1]
|
||||
} else {
|
||||
try {
|
||||
[net.httpWebRequest] $request = [net.webRequest]::create("$releases/tag/$mago_tag")
|
||||
$request.Method = "HEAD"
|
||||
[net.httpWebResponse] $response = $request.getResponse()
|
||||
$response.Close()
|
||||
$mago_tag = "$mago_tag"
|
||||
} catch {
|
||||
$mago_tag = (Get-File -Url $releases/latest).BaseResponse.RequestMessage.RequestUri.Segments[-1]
|
||||
}
|
||||
}
|
||||
return $mago_tag
|
||||
}
|
||||
|
||||
Function Add-Mago() {
|
||||
param(
|
||||
[Parameter(Mandatory = $true, Position = 0, HelpMessage = 'The mago version to be installed')]
|
||||
[ValidatePattern('^latest$|^(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(?:-((?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\.(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\+([0-9a-zA-Z-]+(?:\.[0-9a-zA-Z-]+)*))?$')]
|
||||
[string] $mago_tag
|
||||
)
|
||||
$mago_tag = Get-MagoTag
|
||||
$arch_name = 'x86_64'
|
||||
if(-not([Environment]::Is64BitOperatingSystem)) {
|
||||
$arch_name = 'i686'
|
||||
}
|
||||
$url = "https://github.com/carthage-software/mago/releases/download/$mago_tag/mago-$mago_tag-$arch_name-pc-windows-msvc.zip"
|
||||
Get-File -Url $url -OutFile $bin_dir\mago.zip >$null 2>&1
|
||||
Expand-Archive -Path $bin_dir\mago.zip -DestinationPath $bin_dir\mago -Force >$null 2>&1
|
||||
Move-Item -Path $bin_dir\mago\mago.exe -Destination $bin_dir\mago.exe
|
||||
Add-ToProfile $current_profile 'mago' "New-Alias mago $bin_dir\mago.exe"
|
||||
Add-Log $tick "mago" "Added mago $mago_tag"
|
||||
printf "$env:GROUP\033[34;1m%s \033[0m\033[90;1m%s \033[0m\n" "mago" "Click to read the mago related license information"
|
||||
Write-Output (Invoke-WebRequest https://raw.githubusercontent.com/carthage-software/mago/main/LICENSE).Content
|
||||
Write-Output "$env:END_GROUP"
|
||||
}
|
Reference in New Issue
Block a user