-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnodejs.ps1
148 lines (111 loc) · 4.32 KB
/
nodejs.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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
write-host "`n ## NODEJS INSTALLER ## `n"
### CONFIGURATION
# nodejs
$arc = (Get-CimInstance Win32_operatingsystem).OSArchitecture
$arcfornode = if ($arc -eq "64-bit") { "x64" } else { "x86" }
$version = "22.8.0-$arcfornode"
$url = "https://nodejs.org/dist/latest-v22.x/node-v$version.msi"
# git
$git_version = "2.46.0"
$git_url = "https://github.com/git-for-windows/git/releases/download/v$git_version.windows.1/Git-$git_version-$arc-bit.exe"
# activate / desactivate any install
$install_node = $TRUE
$install_git = $TRUE
write-host "`n----------------------------"
write-host " system requirements checking "
write-host "----------------------------`n"
### require administator rights
if (-NOT ([Security.Principal.WindowsPrincipal] [Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole] "Administrator")) {
write-Warning "This setup needs admin permissions. Please run this file as admin."
break
}
### nodejs version check
if (Get-Command node -errorAction SilentlyContinue) {
$current_version = (node -v)
}
if ($current_version) {
write-host "[NODE] nodejs $current_version already installed"
$confirmation = read-host "Are you sure you want to replace this version ? [y/N]"
if ($confirmation -ne "y") {
$install_node = $FALSE
}
}
write-host "`n"
### git install
if ($install_git) {
if (Get-Command git -errorAction SilentlyContinue) {
$git_current_version = (git --version)
}
if ($git_current_version) {
write-host "[GIT] $git_current_version detected. Proceeding ..."
} else {
$git_exe = "$PSScriptRoot\git-installer.exe"
write-host "No git version dectected"
$download_git = $TRUE
if (Test-Path $git_exe) {
$confirmation = read-host "Local git install file detected. Do you want to use it ? [Y/n]"
if ($confirmation -eq "n") {
$download_git = $FALSE
}
}
if ($download_git) {
write-host "downloading the git for windows installer"
$start_time = Get-Date
$wc = New-Object System.Net.WebClient
$wc.DownloadFile($git_url, $git_exe)
write-Output "git installer downloaded"
write-Output "Time taken: $((Get-Date).Subtract($start_time).Seconds) second(s)"
}
write-host "proceeding with git install ..."
write-host "running $git_exe"
start-Process $git_exe -Wait
write-host "git installation done"
}
}
if ($install_node) {
### download nodejs msi file
# warning : if a node.msi file is already present in the current folder, this script will simply use it
write-host "`n----------------------------"
write-host " nodejs msi file retrieving "
write-host "----------------------------`n"
$filename = "node.msi"
$node_msi = "$PSScriptRoot\$filename"
$download_node = $TRUE
if (Test-Path $node_msi) {
$confirmation = read-host "Local $filename file detected. Do you want to use it ? [Y/n]"
if ($confirmation -eq "n") {
$download_node = $FALSE
}
}
if ($download_node) {
write-host "[NODE] downloading nodejs install"
write-host "url : $url"
$start_time = Get-Date
$wc = New-Object System.Net.WebClient
$wc.DownloadFile($url, $node_msi)
write-Output "$filename downloaded"
write-Output "Time taken: $((Get-Date).Subtract($start_time).Seconds) second(s)"
} else {
write-host "using the existing node.msi file"
}
### nodejs install
write-host "`n----------------------------"
write-host " nodejs installation "
write-host "----------------------------`n"
write-host "[NODE] running $node_msi"
Start-Process $node_msi -Wait
$env:Path = [System.Environment]::GetEnvironmentVariable("Path","Machine") + ";" + [System.Environment]::GetEnvironmentVariable("Path","User")
} else {
write-host "Proceeding with the previously installed nodejs version ..."
}
### clean
write-host "`n----------------------------"
write-host " system cleaning "
write-host "----------------------------`n"
if ($node_msi -and (Test-Path $node_msi)) {
rm $node_msi
}
if ($git_exe -and (Test-Path $git_exe)) {
rm $git_exe
}
write-host "Done !"