-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathsetup.ps1
More file actions
200 lines (168 loc) · 7.41 KB
/
setup.ps1
File metadata and controls
200 lines (168 loc) · 7.41 KB
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
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
Clear-Host
function show-netuno {
Write-Host "
_ _ ______ _______ _ _ _ _ ____
| \ | | ____|__ __| | | | \ | |/ __ \
| \| | |__ | | | | | | \| | | | |
| . | __| | | | | | | . | | | |
| |\ | |____ | | | |__| | |\ | |__| |
|_| \_|______| |_| \____/|_| \_|\____/
" -ForegroundColor Red
}
show-netuno
# -------------------------------
# Silent checks for dependencies
# -------------------------------
Write-Host -ForegroundColor Cyan "Checking installed dependencies..."
Start-Sleep -Seconds 1
$isChocoInstalled = Get-Command choco -ErrorAction SilentlyContinue
$mvnInstalled = Get-Command mvn -ErrorAction SilentlyContinue
$nodejsInstalled = Get-Command node -ErrorAction SilentlyContinue
$javaCmd = Get-Command java -ErrorAction SilentlyContinue
$sevenZipCmd = Get-Command 7z -ErrorAction SilentlyContinue
# -------------------------------
# Robust Java >= 25 check
# -------------------------------
$javaOk = $false
if ($javaCmd) {
try {
Write-Host "Checking Java version..."
$javaRawAll = & java -version 2>&1
foreach ($line in $javaRawAll) {
if ($line -match 'version\s+"(\d+)(\.(\d+))?(\.(\d+))?') {
$javaMajor = [int]$matches[1]
if ($javaMajor -ge 25) {
$javaOk = $true
break
}
}
}
} catch {
$javaOk = $false
}
}
# -------------------------------
# Dependency status
# -------------------------------
Write-Host -ForegroundColor Yellow "`nDependency check results:`n"
Write-Host ("`t[Maven] " + ($(if ($mvnInstalled) { "Installed" } else { "Missing" })))
Write-Host ("`t[Java] " + ($(if ($javaOk) { "Installed" } else { "Missing or < 25" })))
Write-Host ("`t[NodeJS] " + ($(if ($nodejsInstalled){ "Installed" } else { "Missing" })))
Write-Host ("`t[7-Zip] " + ($(if ($sevenZipCmd) { "Installed" } else { "Missing" })))
Start-Sleep -Seconds 2
# -------------------------------
# Install missing dependencies
# -------------------------------
if (!$javaOk -or !$mvnInstalled -or !$nodejsInstalled -or !$sevenZipCmd) {
Write-Host -ForegroundColor Yellow "`nWould you like to automatically install the missing dependencies?"
$installAutomatically = Read-Host "(y - yes | n - no)"
if ($installAutomatically -notin @("y","Y")) {
Write-Host -ForegroundColor Red "All dependencies are required. Exiting script..."
exit
}
# Install Chocolatey if missing
if (-not $isChocoInstalled) {
Write-Host -ForegroundColor Red "Chocolatey is not installed. It is required.`nInstall Chocolatey now?"
$installChoco = Read-Host "(y - yes | n - no)"
if ($installChoco -notin @("y","Y")) {
Write-Host -ForegroundColor Red "Chocolatey is required. Exiting script..."
exit
}
Write-Host -ForegroundColor Yellow "Installing Chocolatey..."
Set-ExecutionPolicy Bypass -Scope Process -Force
[System.Net.ServicePointManager]::SecurityProtocol = [System.Net.ServicePointManager]::SecurityProtocol -bor 3072
iex ((New-Object System.Net.WebClient).DownloadString('https://community.chocolatey.org/install.ps1'))
Write-Host -ForegroundColor Green "Chocolatey installed successfully."
Start-Sleep -Seconds 2
}
# Install missing packages
if (!$javaOk) {
Write-Host -ForegroundColor Yellow "Installing Java (GraalVM 25.0.1)..."
choco install graalvm --version=25.0.1 -y --no-progress
Write-Host -ForegroundColor Green "Java installed."
Start-Sleep -Seconds 2
}
if (!$nodejsInstalled) {
Write-Host -ForegroundColor Yellow "Installing NodeJS LTS..."
choco install nodejs-lts --force -y --no-progress
Write-Host -ForegroundColor Green "NodeJS installed."
Start-Sleep -Seconds 2
}
if (!$mvnInstalled) {
Write-Host -ForegroundColor Yellow "Installing Maven 3.8.1..."
choco install maven --version=3.8.1 --force -y --no-progress
Write-Host -ForegroundColor Green "Maven installed."
Start-Sleep -Seconds 2
}
if (!$sevenZipCmd) {
Write-Host -ForegroundColor Yellow "Installing 7-Zip..."
choco install 7zip -y --no-progress
Write-Host -ForegroundColor Green "7-Zip installed."
Start-Sleep -Seconds 2
}
Write-Host -ForegroundColor Yellow "`nInstallation complete. Restart computer now?"
$restart = Read-Host "(y - yes | n - no)"
if ($restart -in @("y","Y")) {
Write-Host -ForegroundColor Yellow "Restarting computer..."
Start-Sleep -Seconds 2
Restart-Computer
}
}
Write-Host -ForegroundColor Yellow "`nAll dependencies are installed.`nContinuing with the script..."
Start-Sleep -Seconds 2
# -------------------------------
# Main menu loop
# -------------------------------
do {
Clear-Host
show-netuno
Write-Host -ForegroundColor Yellow "1. Setting Project."
Write-Host -ForegroundColor Yellow "2. Generate Bundle."
Write-Host -ForegroundColor White "`nQ. Press Q to quit."
$selection = Read-Host "Select option"
switch ($selection) {
'1' {
Write-Host -ForegroundColor Cyan "`nSetting up project..."
Start-Sleep -Seconds 3
& ./build.ps1
Get-ChildItem -Filter "*.ps1" | ForEach-Object {
Unblock-File $_.FullName -ErrorAction SilentlyContinue
}
Get-ChildItem -Path "bundle" -Filter "*.ps1" -Recurse | ForEach-Object {
Unblock-File $_.FullName -ErrorAction SilentlyContinue
}
Push-Location "bundle"
Write-Host -ForegroundColor Cyan "Running npm install in bundle folder..."
npm install
Pop-Location
Write-Host -ForegroundColor Cyan "Creating necessary directories and symbolic links..."
if(!(Test-Path -Path ".\bundle\base\core\web\WEB-INF\classes\org\netuno")){
New-Item ".\bundle\base\core\web\WEB-INF\classes\org\netuno" -ItemType Directory
}
if(!(Test-Path -Path ".\bundle\base\core\web\WEB-INF\classes\org\netuno\proteu")){
New-Item -ItemType SymbolicLink -Path ".\bundle\base\core\web\WEB-INF\classes\org\netuno\proteu" -Target ".\netuno.proteu\target\classes\org\netuno\proteu"
}
if(!(Test-Path -Path ".\bundle\base\core\web\WEB-INF\classes\org\netuno\tritao")){
New-Item -ItemType SymbolicLink -Path ".\bundle\base\core\web\WEB-INF\classes\org\netuno\tritao" -Target ".\netuno.tritao\target\classes\org\netuno\tritao"
}
Write-Host -ForegroundColor Green "Project setup complete."
Start-Sleep -Seconds 5
}
'2' {
if (Test-Path "bundle\publish.ps1") {
Write-Host -ForegroundColor Cyan "`nGenerating bundle..."
Start-Sleep -Seconds 1
Push-Location "bundle"
.\publish.ps1
Pop-Location
Write-Host -ForegroundColor Green "Bundle generation complete."
Start-Sleep -Seconds 5
} else {
Write-Host -ForegroundColor Red "publish.ps1 not found in bundle folder."
Start-Sleep -Seconds 5
}
}
}
} until ($selection -eq 'q' -or $selection -eq 'Q')
Write-Host -ForegroundColor Yellow "`nExiting script. Goodbye!"
Start-Sleep -Seconds 3