-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
install_node.ps1
95 lines (71 loc) · 2.32 KB
/
install_node.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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
# Function to test if the script is running with adminstrative privileges
function Administrator-Test {
$CurrentUser = [Security.Principal.WindowsIdentity]::GetCurrent();
(New-Object Security.Principal.WindowsPrincipal $CurrentUser).IsInRole([Security.Principal.WindowsBuiltinRole]::Administrator)
}
# Check whether the installer has administrative privileges.
# If not, run it as administrator.
if ((Administrator-Test) -eq $False) {
# Not running with elevated perms, so let's run it as administrator.
PowerShell -NoProfile -ExecutionPolicy Unrestricted -Command "& {Start-Process PowerShell -ArgumentList '-NoProfile -NoExit -ExecutionPolicy Unrestricted -File "$MyInvocation.MyCommand.Definition"' -Verb RunAs}";
# We need to exit it otherwise the rest of the script will keep on running.
Exit 0
}
# Function to print message from Installer
# Params:
# $1 The message string
Function Print::Installer($1) {
$NC = $host.ui.RawUI.ForegroundColor
$host.ui.RawUI.ForegroundColor = "Cyan"
Write-Host "[Installer]: " -NoNewline
$host.ui.RawUI.ForegroundColor = $NC
Write-Host "$1"
}
# Function to print error
# Params:
# $1 The error string
Function Print::Error($1) {
$NC = $host.ui.RawUI.ForegroundColor
$host.ui.RawUI.ForegroundColor = "Red"
Write-Host "[ERROR]: " -NoNewline
$host.ui.RawUI.ForegroundColor = $NC
Write-Host "$1"
Write-Host
Exit 1
}
# Function to print 'Done' after a step is complete
Function Print::Done() {
Print::Installer "Done."
Write-Host
}
# Function to install any given package(s) from the package manager
# Params:
# $1 The list of package names
Function Install::Package($1) {
choco install $1 -y
If (-Not ($?)) {
Print::Error "Unable to download and install $1."
}
refreshenv
}
# Function to install system packages required by Lavalink
# List of packages:
# 1. Chocolatey
# 2. Java (Zulu 13.29.9)
Function Install::Packages() {
Print::Installer "Installing required system packages..."
Set-ExecutionPolicy Bypass -Scope Process -Force; iex ((New-Object System.Net.WebClient).DownloadString('https://chocolatey.org/install.ps1'))
If (-Not ($?)) {
Print::Error "Unable to download and install Chocolatey."
}
# Install Java
Install::Package "nodejs-lts"
Print::Done
}
Function Main() {
Install::Packages
Write-Host
}
Main
Exit 0
#EOF