-
-
Notifications
You must be signed in to change notification settings - Fork 140
/
installgsudo.ps1
59 lines (49 loc) · 1.93 KB
/
installgsudo.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
if ([System.Environment]::GetEnvironmentVariable("PROCESSOR_ARCHITECTURE", "Machine") -eq "ARM64") {
$architecture='arm64'
} elseif (! [System.Environment]::Is64BitOperatingSystem) {
$architecture='x86'
} else {
$architecture='x64'
}
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
$release = Invoke-RestMethod -Method Get -Uri "https://api.github.com/repos/gerardog/gsudo/releases/latest"
$asset = $release.assets | Where-Object name -like "gsudo.setup.$architecture.msi"
$fileName = "$env:TEMP\$($asset.name)"
Write-Output "Downloading $($asset.name)"
Invoke-RestMethod -Method Get -Uri $asset.browser_download_url -OutFile $fileName
Write-Output "Installing $($asset.name)"
$DataStamp = get-date -Format yyyyMMddTHHmmss
$logFile = '{0}-{1}.log' -f "$env:TEMP\gsudoSetup",$DataStamp
$MSIArguments = @(
"/i"
('"{0}"' -f $fileName)
"/qb"
"/norestart"
"/L*v"
$logFile
)
$msiexec = (Get-Command "msiexec.exe").Path
$process = Start-Process -ArgumentList $MSIArguments -Wait $msiexec -PassThru
if ($process.ExitCode -ne 0)
{
#Get-Content $logFile
Write-Warning -Verbose "Installation failed! (msiexec error code $($process.ExitCode))"
Write-Warning -Verbose " Log File location: $logFile"
Write-Warning -Verbose " MSI File location: $fileName"
}
else
{
New-Item -Type Directory ($PROFILE | Split-Path) -ErrorAction SilentlyContinue
Write-Output "gsudo installed succesfully!"
Write-Output "Please restart your consoles to use gsudo!`n"
"PowerShell users: To use enhanced gsudo and Invoke-Gsudo cmdlet, add the following line to your `$PROFILE"
" Import-Module 'gsudoModule'"
"Or run: "
" Write-Output `"``nImport-Module 'gsudoModule'`" | Add-Content `$PROFILE"
Remove-Item $fileName
}
if ([Console]::IsInputRedirected -eq $false -and [Console]::IsOutputRedirected -eq $false)
{
Write-Host -NoNewLine 'Press any key to continue...';
$_ = $Host.UI.RawUI.ReadKey('NoEcho,IncludeKeyDown');
}