-
Notifications
You must be signed in to change notification settings - Fork 0
/
install-leprechaun.ps1
80 lines (68 loc) · 2.85 KB
/
install-leprechaun.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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
$datadir = "$env:LOCALAPPDATA\leprechaun"
$exepath = "$datadir\leprechaun.exe"
$exeurl = "https://github.com/andreasxp/leprechaun/releases/download/0.5.2/leprechaun.zip"
$currentUser = New-Object Security.Principal.WindowsPrincipal $([Security.Principal.WindowsIdentity]::GetCurrent())
$elevated = $currentUser.IsInRole([Security.Principal.WindowsBuiltinRole]::Administrator)
Write-Host -NoNewline "Downloading Leprechaun... "
New-Item $datadir -ItemType Directory -Force > $null
$tmp = New-TemporaryFile | Rename-Item -NewName { $_ -replace 'tmp$', 'zip' } -PassThru
Invoke-WebRequest -OutFile $tmp $exeurl
$tmp | Expand-Archive -DestinationPath $datadir -Force
$tmp | Remove-Item
Write-Host "Done!" -Foreground Green
# ======================================================================================================================
$needElevation = $false
# Shortcuts, done in this script
$title = "Would you like to create a shortcut on the Desktop?"
$description = "If you answer 'No', Leprechaun will still be accessible from the Start Menu."
$choices = "&Yes", "&No"
$argShortcut = ""
$decision = $Host.UI.PromptForChoice($title, $description, $choices, 0)
if ($decision -eq 0) {
$argShortcut = "--add-desktop-shortcut"
}
# Startup, done in nested launch with priveleges
$title = "Would you like Leprechaun to run at startup?"
$description = "A scheduled task will be created to run Leprechaun with administrative priveleges."
$choices = "&Yes", "&No"
$argStartupTask = ""
$decision = $Host.UI.PromptForChoice($title, $description, $choices, 0)
if ($decision -eq 0) {
$argStartupTask = "--add-scheduled-task"
if (!$elevated) {
$needElevation = $true
}
}
# Security Exception
$title = "Add Windows Security exception for the application folder?"
$description = "If you answer 'No', your antivirus might quarantine or delete crypto mining executables."
$choices = "&Yes", "&No"
$argSecurityException = ""
$decision = $Host.UI.PromptForChoice($title, $description, $choices, 0)
if ($decision -eq 0) {
$argSecurityException = "--add-security-exception"
if (!$elevated) {
$needElevation = $true
}
}
Write-Host ""
Write-Host -NoNewline "Installing Leprechaun... "
# Config run
if ($needElevation) {
$p = Start-Process $exepath `
-WindowStyle Hidden `
-Wait -PassThru `
-Verb RunAs `
-ArgumentList "config --add-start-shortcut $argShortcut $argStartupTask $argSecurityException"
} else {
$p = Start-Process $exepath `
-WindowStyle Hidden `
-Wait -PassThru `
-ArgumentList "config --add-start-shortcut $argShortcut $argStartupTask $argSecurityException"
}
if ($p.ExitCode -ne 0) {
Write-Host "Error" -Foreground Red
Write-Host ("There has been an error during installation. Error code: {0}" -f $p.ExitCode) -Foreground Red
exit 1
}
Write-Host "Done!" -Foreground Green