-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathelk.nsi
420 lines (306 loc) · 12.2 KB
/
elk.nsi
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
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
; ELK (elasticsearch - kibana) windows installer nsis script
; Copyright (c) 2016 Luigi Grilli
;
; basic script template for NSIS installers
;
; Written by Philip Chu
; Copyright (c) 2004-2005 Technicat, LLC
;
; This software is provided 'as-is', without any express or implied warranty.
; In no event will the authors be held liable for any damages arising from the use of this software.
; Permission is granted to anyone to use this software for any purpose,
; including commercial applications, and to alter it ; and redistribute
; it freely, subject to the following restrictions:
; 1. The origin of this software must not be misrepresented; you must not claim that
; you wrote the original software. If you use this software in a product, an
; acknowledgment in the product documentation would be appreciated but is not required.
; 2. Altered source versions must be plainly marked as such, and must not be
; misrepresented as being the original software.
; 3. This notice may not be removed or altered from any source distribution.
; Command line options for ElasticSearch
; /DATADIR= specify ElasticSearch data directory
; /LOGSDIR= specify ElasticSearch logs directory
; /REPODIR= specify ElasticSearch repository directory
; include for some of the windows messages defines
!include "winmessages.nsh"
!include MUI.nsh
!include Sections.nsh
!include LogicLib.nsh
!include "FileFunc.nsh"
!include "x64.nsh"
; HKLM (all users) vs HKCU (current user) defines
!define env_hklm 'HKLM "SYSTEM\CurrentControlSet\Control\Session Manager\Environment"'
!define env_hkcu 'HKCU "Environment"'
;version is passed as a parameter during makensis invocation
!define setup "dist\elk-x64-${version}-OpenJDKfriendly.exe"
; change this to wherever the files to be packaged reside
!define srcdir "temp"
!define company "Elasticsearch"
!define prodname "ELK"
; optional stuff
; Set the text which prompts the user to enter the installation directory
; DirText "My Description Here."
; text file to open in notepad after installation
!define notefile "elasticsearch\README.textile"
; license text file
!define licensefile elasticsearch\license.txt
; icons must be Microsoft .ICO files
; !define icon "icon.ico"
; installer background screen
; !define screenimage background.bmp
; file containing list of file-installation commands
; !define files "files.nsi"
; file containing list of file-uninstall commands
; !define unfiles "unfiles.nsi"
; registry stuff
!define regkey "Software\${company}\${prodname}"
!define uninstkey "Software\Microsoft\Windows\CurrentVersion\Uninstall\${prodname}"
!define startmenu "$SMPROGRAMS\${company}\${prodname}"
!define uninstaller "uninstall.exe"
!define CONFIG_TOOL_PATH "$INSTDIR\configurationtool"
!define SNAPSHOT_REPO_NAME "AllSnapshots"
;--------------------------------
XPStyle on
ShowInstDetails hide
ShowUninstDetails hide
Name "${prodname}"
Caption "${prodname}"
!ifdef icon
Icon "${icon}"
!endif
OutFile "${setup}"
SetDateSave on
SetDatablockOptimize on
CRCCheck on
SilentInstall normal
InstallDir "C:\Elk"
InstallDirRegKey HKLM "${regkey}" ""
!ifdef licensefile
LicenseText "License"
LicenseData "${srcdir}\${licensefile}"
!endif
; pages
; we keep it simple - leave out selectable installation types
!ifdef licensefile
Page license
!endif
; Page components
Page components
Page directory
Page Custom PageElasticSearchConfigurationShow PageElasticSearchConfigurationLeave
Page instfiles
UninstPage uninstConfirm
UninstPage instfiles
ReserveFile "PageElasticSearchConfiguration.ini"
;--------------------------------
AutoCloseWindow false
ShowInstDetails show
Var ElasticSearchDataDirectory
Var ElasticSearchLogsDirectory
Var ElasticSearchRepositoryDirectory
!macro PowerShellExecFile1Macro PSFile Params
!define PSExecID ${__LINE__}
${If} ${RunningX64}
${DisableX64FSRedirection}
${EndIf}
nsExec::ExecToStack 'powershell -noprofile -inputformat none -ExecutionPolicy RemoteSigned -File "${PSFile}" ${Params} '
${If} ${RunningX64}
${EnableX64FSRedirection}
${EndIf}
!undef PSExecID
!macroend
!define PowerShellExecFile1 `!insertmacro PowerShellExecFile1Macro`
Function .onInit
Call GetCmdLineElasticConfiguration
FunctionEnd
!ifdef screenimage
; set up background image
; uses BgImage plugin
Function .onGUIInit
; extract background BMP into temp plugin directory
InitPluginsDir
File /oname=$PLUGINSDIR\1.bmp "${screenimage}"
BgImage::SetBg /NOUNLOAD /FILLSCREEN $PLUGINSDIR\1.bmp
BgImage::Redraw /NOUNLOAD
FunctionEnd
Function .onGUIEnd
; Destroy must not have /NOUNLOAD so NSIS will be able to unload and delete BgImage before it exits
BgImage::Destroy
FunctionEnd
!endif
; ---- ConfigureElasticSearch ----
Function GetCmdLineElasticConfiguration
Push $R0
DetailPrint "Setting Initial ElasticSearch Configuration Values"
${GetParameters} $R0
${GetOptions} $R0 /DATADIR= $ElasticSearchDataDirectory
${If} $ElasticSearchDataDirectory == ''
StrCpy $ElasticSearchDataDirectory '$INSTDIR/elasticsearch/data'
${EndIf}
${GetOptions} $R0 /LOGSDIR= $ElasticSearchLogsDirectory
${If} $ElasticSearchLogsDirectory == ''
StrCpy $ElasticSearchLogsDirectory '$INSTDIR/elasticsearch/logs'
${EndIf}
${GetOptions} $R0 /REPODIR= $ElasticSearchRepositoryDirectory
${If} $ElasticSearchRepositoryDirectory == ''
StrCpy $ElasticSearchRepositoryDirectory '$INSTDIR/elasticsearch/${SNAPSHOT_REPO_NAME}'
${EndIf}
FunctionEnd
Function PageElasticSearchConfigurationShow
${Unless} ${SectionIsSelected} "Elasticsearch"
Abort
${EndUnless}
SetOutPath $INSTDIR
!insertmacro MUI_INSTALLOPTIONS_EXTRACT_AS "PageElasticSearchConfiguration.ini" "PageElasticSearchConfiguration.ini"
!insertmacro MUI_HEADER_TEXT "$(PageElasticSearch_TITLE)" "$(PageElasticSearch_SUBTITLE)"
!insertmacro MUI_INSTALLOPTIONS_WRITE "PageElasticSearchConfiguration.ini" "Field 8" "State" $ElasticSearchDataDirectory
!insertmacro MUI_INSTALLOPTIONS_WRITE "PageElasticSearchConfiguration.ini" "Field 10" "State" $ElasticSearchLogsDirectory
!insertmacro MUI_INSTALLOPTIONS_WRITE "PageElasticSearchConfiguration.ini" "Field 12" "State" $ElasticSearchRepositoryDirectory
!insertmacro MUI_INSTALLOPTIONS_DISPLAY "PageElasticSearchConfiguration.ini"
FunctionEnd
Function PageElasticSearchConfigurationLeave
!insertmacro MUI_INSTALLOPTIONS_READ $ElasticSearchDataDirectory "PageElasticSearchConfiguration.ini" "Field 8" "State"
!insertmacro MUI_INSTALLOPTIONS_READ $ElasticSearchLogsDirectory "PageElasticSearchConfiguration.ini" "Field 10" "State"
!insertmacro MUI_INSTALLOPTIONS_READ $ElasticSearchRepositoryDirectory "PageElasticSearchConfiguration.ini" "Field 12" "State"
FunctionEnd
Function ConfigureElasticSearch
Push $R0
Push $R1
DetailPrint "--- Configuring ElasticSearch"
DetailPrint "ConfigFilePath '$INSTDIR\elasticsearch\config\elasticsearch.yml'"
DetailPrint "DataPath '$ElasticSearchDataDirectory'"
DetailPrint "LogsPath '$ElasticSearchLogsDirectory'"
DetailPrint "RepoPath '$ElasticSearchRepositoryDirectory'"
DetailPrint "${CONFIG_TOOL_PATH}\ElasticSearchConfiguration.ps1 -ConfigFilePath '$INSTDIR\elasticsearch\config\elasticsearch.yml' -DataPath '$ElasticSearchDataDirectory' -LogsPath '$ElasticSearchLogsDirectory' -RepoPath '$ElasticSearchRepositoryDirectory'"
${PowerShellExecFile1} "${CONFIG_TOOL_PATH}\ElasticSearchConfiguration.ps1" '-ConfigFilePath "$INSTDIR\elasticsearch\config\elasticsearch.yml" -DataPath "$ElasticSearchDataDirectory" -LogsPath "$ElasticSearchLogsDirectory" -RepoPath "$ElasticSearchRepositoryDirectory"'
Pop $R0
Pop $R1
DetailPrint "PowerShell Script returned: $R0"
DetailPrint "PowerShell Script result:"
DetailPrint "'$R1'"
DetailPrint "--- Configuring ElasticSearch completed."
FunctionEnd
Function ConfigureKibana
Push $R0
Push $R1
DetailPrint "--- Configuring Kibana"
DetailPrint "ConfigFilePath '$INSTDIR\kibana\config\kibana.yml'"
DetailPrint "${CONFIG_TOOL_PATH}\KibanaConfiguration.ps1 -ConfigFilePath '$INSTDIR\kibana\config\kibana.yml'"
${PowerShellExecFile1} "${CONFIG_TOOL_PATH}\KibanaConfiguration.ps1" '-ConfigFilePath "$INSTDIR\kibana\config\kibana.yml"'
Pop $R0
Pop $R1
DetailPrint "PowerShell Script returned: $R0"
DetailPrint "PowerShell Script result:"
DetailPrint "'$R1'"
DetailPrint "--- Configuring Kibana completed."
FunctionEnd
; beginning (invisible) section
Section
;First look for AdoptOpenJDK
ClearErrors
SetRegView 64
StrCpy $0 0
loop:
EnumRegKey $1 HKLM SOFTWARE\AdoptOpenJDK\JDK\ $0
StrCmp $1 "" notFoundOpenJDK
IntOp $0 $0 + 1
;Check if the first characters correspond to version 8
StrCpy $2 $1 2 0
StrCmp $2 "8." foundOpenJDK loop
foundOpenJDK:
ReadRegStr $2 HKLM "SOFTWARE\AdoptOpenJDK\JDK\$1\hotspot\MSI" "Path"
DetailPrint "$2"
IfErrors 0 NoAbort
DetailPrint "Couldn't find AdoptOpenJDK v8 installed. Checking for Java SDK next."
notFoundOpenJDK:
;Look for JDK
ClearErrors
ReadRegStr $1 HKLM "SOFTWARE\JavaSoft\Java Development Kit" "CurrentVersion"
ReadRegStr $2 HKLM "SOFTWARE\JavaSoft\Java Development Kit\$1" "JavaHome"
DetailPrint "$1 $2"
IfErrors 0 NoAbort
MessageBox MB_OK "Couldn't find AdoptOpenJDK v8 or a Java Development Kit installed. Setup will exit now."
Quit
NoAbort:
DetailPrint "Found JDK in path $2"
StrCpy $R0 "$2"
System::Call 'Kernel32::SetEnvironmentVariable(t, t) i("JAVA_HOME", R0).r0'
; set environment variable
WriteRegExpandStr ${env_hklm} JAVA_HOME $R0
; make sure windows knows about the change
SendMessage ${HWND_BROADCAST} ${WM_WININICHANGE} 0 "STR:Environment" /TIMEOUT=5000
WriteRegStr HKLM "${regkey}" "Install_Dir" "$INSTDIR"
; write uninstall strings
WriteRegStr HKLM "${uninstkey}" "DisplayName" "${prodname} (remove only)"
WriteRegStr HKLM "${uninstkey}" "UninstallString" '"$INSTDIR\${uninstaller}"'
!ifdef filetype
WriteRegStr HKCR "${filetype}" "" "${prodname}"
!endif
!ifdef icon
WriteRegStr HKCR "${prodname}\DefaultIcon" "" "$INSTDIR\${icon}"
!endif
SetOutPath $INSTDIR
; package all files, recursively, preserving attributes
; assume files are in the correct places
!ifdef licensefile
File /a "${srcdir}\${licensefile}"
!endif
!ifdef notefile
File /a "${srcdir}\${notefile}"
!endif
!ifdef icon
File /a "${srcdir}\${icon}"
!endif
SetOutPath $INSTDIR\nssm
File /r "tools\nssm\*"
SetOutPath $INSTDIR\scripts
File /r "scripts\*"
CreateDirectory "${CONFIG_TOOL_PATH}"
SetOutPath "${CONFIG_TOOL_PATH}"
File ElasticSearchConfiguration.ps1
File KibanaConfiguration.ps1
WriteUninstaller "${uninstaller}"
SectionEnd
Section "Elasticsearch" Elasticsearch
SetOutPath $INSTDIR\elasticsearch
File /r "${srcdir}\elasticsearch\*"
Call ConfigureElasticSearch
; install elasticsearch service
ExecWait "$INSTDIR\elasticsearch\bin\elasticsearch-service.bat install" $0
; set service to start automatically (delayed)
ExecWait "sc config elasticsearch-service-x64 start=delayed-auto" $0
StrCpy $R0 "$INSTDIR"
System::Call 'Kernel32::SetEnvironmentVariable(t, t) i("INSTDIR", R0).r0'
StrCpy $R0 "$INSTDIR\nssm\win64\nssm.exe"
System::Call 'Kernel32::SetEnvironmentVariable(t, t) i("NSSM", R0).r0'
; start services
ExecWait "net start elasticsearch-service-x64" $0
SectionEnd
Section "Kibana" Kibana
SetOutPath $INSTDIR\kibana
File /r "${srcdir}\kibana\*"
Call ConfigureKibana
ExecWait "$INSTDIR\scripts\kibana-install.bat" $0
ExecWait "net start kibana" $0
SectionEnd
; Uninstaller
; All section names prefixed by "Un" will be in the uninstaller
UninstallText "This will uninstall ${prodname}."
!ifdef icon
UninstallIcon "${icon}"
!endif
Section "Uninstall"
; stop services
ExecWait "net stop kibana"
ExecWait "net stop elasticsearch-service-x64"
StrCpy $R0 "$INSTDIR"
System::Call 'Kernel32::SetEnvironmentVariable(t, t) i("INSTDIR", R0).r0'
StrCpy $R0 "$INSTDIR\nssm\win64\nssm.exe"
System::Call 'Kernel32::SetEnvironmentVariable(t, t) i("NSSM", R0).r0'
ExecWait "$INSTDIR\scripts\kibana-uninstall.bat" $0
; uninstall elasticsearch service
ExecWait "$INSTDIR\elasticsearch\bin\elasticsearch-service.bat remove"
DeleteRegKey HKLM "${uninstkey}"
DeleteRegKey HKLM "${regkey}"
RmDir /r "$INSTDIR"
SectionEnd