geoserver

Форк
0
/
geoserver_winsetup.nsi 
1277 строк · 43.0 Кб
1
; GEOSERVER WINDOWS INSTALLER SCRIPT FOR NSIS
2
;
3
;   NOTE: This script requires the following NSIS plugins:
4
;      -> AccessControl (https://nsis.sourceforge.io/AccessControl_plug-in)
5
;      -> ShellLink (https://nsis.sourceforge.io/ShellLink_plug-in)
6
;
7
; ----------------------------------------------------------------------------
8
; (c) 2021 Open Source Geospatial Foundation - all rights reserved
9
; This code is licensed under the GPL 2.0 license, available at the root
10
; application directory.
11
; ----------------------------------------------------------------------------
12

13
; Treat all warnings as errors, except warnings 6010 and 6020
14
!pragma warning error all
15
!pragma warning disable 6010 ; disable warning about functions not being referenced
16
!pragma warning disable 6020 ; disable warning about unused uninstaller script code
17

18
; Constants (VERSION should be updated by a script!)
19
!define APPNAME "GeoServer"                                     ; application name
20
!ifndef VERSION
21
  !searchparse /file ..\source\VERSION.txt `version = ` VERSION   ; Read version from VERSION.txt
22
!endif
23
!define FULLNAME "${APPNAME} ${VERSION}"                        ; app name and version combined
24
!define FULLKEY "${APPNAME}-${VERSION}"                         ; app name and version combined (delimited)
25
!define INSTNAME "${APPNAME}-${VERSION}-winsetup.exe"           ; installer exe name
26
!define UNINNAME "${APPNAME}-uninstall.exe"                     ; uninstaller exe name
27
!define HOMEPAGE "https://geoserver.org"                        ; resource URL
28
!define TIMESTAMPURL "http://timestamp.comodoca.com/rfc3161"    ; URL used to timestamp certificates
29
!define REQJREVERSION "11.0"                                   ; required Java runtime version (i.e. 11.0)
30
!define REQJREVERSIONNAME "11"                                   ; required Java runtime display version (i.e. 11)
31
!define ALTJREVERSION "17.0"                                    ; alternative Java runtime version (i.e. 17.0)
32
!define ALTJREVERSIONNAME "17"                                  ; alternative Java runtime display version (i.e. 17)
33
!define JDKNAME "Adoptium OpenJDK"                              ; Name of the OpenJDK provider (e.g. AdoptOpenJDK)
34
!define JDKURL "https://adoptium.net"                           ; OpenJDK URL
35
!define EMAIL "geoserver-users@lists.sourceforge.net"           ; support email address
36
!define COPYRIGHT "Copyright (c) 1999-2021 Open Source Geospatial Foundation"
37
!define CERT_DOMAIN "https://www.osgeo.org"                     ; Certificate domain (URL)
38
!define CERT_SUBJECT "The Open Source Geospatial Foundation"    ; Certificate subject
39

40
; CODE SIGNING
41
; ----------------------------------------------------------------------------
42
; Signing requires Windows SIGNTOOL.EXE (32-bits, because NSIS is 32-bits)
43
; This can be installed as a feature of MS Visual Studio (ClickOnce) or as part of the Windows SDK.
44
;
45
; Common directories where the signtool.exe can be found are:
46
; C:\Program Files (x86)\Microsoft SDKs\ClickOnce\SignTool
47
; C:\Program Files (x86)\Windows Kits\10\bin\<version>\<architecture>
48
; C:\Program Files (x86)\Windows Kits\10\App Certification Kit
49
;
50
; IMPORTANT: the signtool.exe directory MUST be added to the Windows PATH environment variable!!
51
!define SIGNCOMMAND "signtool sign  /v /n $\"${CERT_SUBJECT}$\" /sm /d ${APPNAME} /du ${CERT_DOMAIN} /tr ${TIMESTAMPURL} /td sha256"
52

53
; The sign command will be called after the (un)installer.exe files were build successfully.
54
; Make sure that the private certificate (*.pfx) is installed in the certificate store (for user, not machine).
55
; Note: installing the certificate might require a password.
56
; Once the certificate is installed, the finalize steps below should run without issues.
57
!finalize "PING -n 5 127.0.0.1 >nul"                ; Delay next step to ensure file isn't locked by compiler process
58
!ifndef INNER
59
  !finalize "${SIGNCOMMAND} ..\target\${INSTNAME}"  ; Sign installer with SHA1
60
  !finalize 'DEL /F /Q "wrapper\${APPNAME}.exe"'    ; Remove the signed wrapper
61
!endif
62
; ----------------------------------------------------------------------------
63

64
; Global variables
65
Var AppKey
66
Var MenuFolder
67
Var ProgramData
68
Var JavaHome
69
Var JavaExe
70
Var JavaHomeTemp
71
Var JavaHomeHWND
72
Var BrowseJavaHWND
73
Var JavaPathCheck
74
Var LinkHWND
75
Var IsManual
76
Var Manual
77
Var Service
78
Var StartPort
79
Var StopPort
80
Var PortHWND
81
Var LocalUrl
82
Var DataDir
83
Var DataDirTemp
84
Var DataDirHWND
85
Var BrowseDataDirHWND
86
Var DataDirType
87
Var DefaultDataDir
88
Var DataDirPathCheck
89
Var GSUser
90
Var GSPass
91
Var GSUserHWND
92
Var GSPassHWND
93

94
; ----------------------------------------------------------------------------
95
; General settings
96

97
  ; Properly display all languages (if any)
98
  Unicode true
99

100
  ; Project name
101
  Name "${FULLNAME}"
102

103
  ; Default installation folder
104
  InstallDir "$PROGRAMFILES64\${APPNAME}"
105

106
  ; Get installation folder from registry if available
107
  InstallDirRegKey HKLM "Software\${APPNAME}" ""
108

109
  ; Request application privileges for Windows
110
  RequestExecutionLevel admin
111

112
  ; We would like everyone to see what the (un)installer is doing
113
  ShowInstDetails show
114
  ShowUninstDetails show
115

116
  ; Compression options
117
  !ifdef INNER
118
    !echo "Inner invocation"
119

120
    ; Initially write temporary output
121
    OutFile "$%TEMP%\tempinstaller.exe"
122
    SetCompress off
123

124
  !else
125
    !echo "Outer invocation"
126

127
    ; Call makensis again against current file, defining INNER.  
128
    ; This writes an installer for us which, when invoked, 
129
    ; will just write the uninstaller to some location, and then exit.
130
    !makensis '/DINNER /DVERSION=${VERSION} "${__FILE__}"' = 0
131
  
132
    ; Now run that installer we just created as %TEMP%\tempinstaller.exe.
133
    ; Since it calls quit the return value isn't zero. 
134
    !system 'set __COMPAT_LAYER=RunAsInvoker&"$%TEMP%\tempinstaller.exe"' = 2
135
  
136
    ; That will have written an uninstaller binary for us.
137
    ; Now we will digitally sign it. 
138
    !system "${SIGNCOMMAND} $%TEMP%\${UNINNAME}" = 0
139

140
    ; Write the real installer
141
    OutFile "..\target\${INSTNAME}"
142
    SetCompress auto
143
  !endif
144

145
; ----------------------------------------------------------------------------
146
; Modern interface Settings
147

148
  !include "MUI2.nsh"         ; Modern interface (v2)
149
  !include "StrFunc.nsh"      ; String functions
150
  !include "LogicLib.nsh"     ; ${If} ${Case} etc.
151
  !include "nsDialogs.nsh"    ; For Custom page layouts (radio buttons etc.)
152
  ${StrStr}
153
  ${StrCase}
154
  ${StrLoc}
155

156
  ; "Are you sure you wish to cancel" popup
157
  !define MUI_ABORTWARNING
158

159
  ; Images
160
  !define MUI_ICON img\installer.ico
161
  !define MUI_UNICON img\installer.ico
162
  !define MUI_WELCOMEFINISHPAGE_BITMAP img\installer.bmp
163
  !define MUI_UNWELCOMEFINISHPAGE_BITMAP img\installer.bmp
164

165
  ; Welcome text
166
  !define MUI_WELCOMEPAGE_TEXT "This wizard will guide you through the installation of ${FULLNAME}. \
167
                                $\r$\n$\r$\nIt is recommended that you close all other applications before running this setup. \
168
                                This will make it possible to update relevant system files without having to reboot your computer. \
169
                                $\r$\n$\r$\nClick Next to continue."
170

171
  ; Install location page text
172
  !define MUI_DIRECTORYPAGE_TEXT_TOP "${FULLNAME} will be installed in the suggested folder below. \
173
                                      This folder is recommended when installing ${APPNAME} as a Windows service. \
174
                                      For manual installations, you may want to change the installation directory to a \
175
                                      folder that you created yourself. \
176
                                      $\r$\n$\r$\nClick Browse to select another folder and/or Next to continue."
177

178
; ----------------------------------------------------------------------------
179
; Registry Settings
180

181
  ; Start Menu folder configuration
182
  !define MUI_STARTMENUPAGE_DEFAULTFOLDER "${APPNAME}"
183
  !define MUI_STARTMENUPAGE_REGISTRY_ROOT "HKLM" 
184
  !define MUI_STARTMENUPAGE_REGISTRY_KEY "Software\${APPNAME}" 
185
  !define MUI_STARTMENUPAGE_REGISTRY_VALUENAME "Start Menu Folder"
186

187
; ----------------------------------------------------------------------------
188
; Convert NOTICE.txt markdown into an RTF file using Pandoc
189

190
  !system 'pandoc -s -f markdown -t rtf "..\source\license\NOTICE.txt" -o license.rtf'
191

192
; ----------------------------------------------------------------------------
193
; Installer pages
194

195
  !insertmacro MUI_PAGE_WELCOME                             ; Hello
196
  !insertmacro MUI_PAGE_LICENSE license.rtf                 ; Show license
197
  Page custom SetJRE                                        ; Set the JRE
198
  !insertmacro MUI_PAGE_DIRECTORY                           ; Install location
199
  !insertmacro MUI_PAGE_STARTMENU Application $MenuFolder   ; Start menu location
200
  Page custom SetDataDir                                    ; Set the data directory
201
  Page custom SetCredentials                                ; Set admin/password (if new data_dir)
202
  Page custom SetPorts                                      ; Set Jetty web server ports
203
  Page custom SetInstallType InstallTypeLeave               ; Manual/Service
204
  Page custom ShowSummary                                   ; Summary page
205
  !insertmacro MUI_PAGE_INSTFILES                           ; Actually do the install
206
  !insertmacro MUI_PAGE_FINISH                              ; Done - link to readme
207
  
208
; Uninstaller pages (always uninstall everything)
209
  !ifdef INNER
210
    !define MUI_UNCONFIRMPAGE_TEXT_TOP "${APPNAME} will be completely removed from the following folder. Click Uninstall to start."
211
    !insertmacro MUI_UNPAGE_CONFIRM                         ; Are you sure?
212
    !insertmacro MUI_UNPAGE_INSTFILES                       ; Do the uninstall
213
  !endif
214

215
; ----------------------------------------------------------------------------
216
; Languages
217

218
  !insertmacro MUI_LANGUAGE "English" ; The first language is the default language
219

220
  ; Install options page headers
221
  LangString TEXT_JRE_TITLE ${LANG_ENGLISH} "Java Runtime Environment"
222
  LangString TEXT_JRE_SUBTITLE ${LANG_ENGLISH} "Set a valid JRE path."
223
  LangString TEXT_DATADIR_TITLE ${LANG_ENGLISH} "${APPNAME} Data Directory"
224
  LangString TEXT_DATADIR_SUBTITLE ${LANG_ENGLISH} "Set a valid ${APPNAME} data directory."
225
  LangString TEXT_CREDS_TITLE ${LANG_ENGLISH} "GeoServer Administrator"
226
  LangString TEXT_CREDS_SUBTITLE ${LANG_ENGLISH} "Set administrator credentials."
227
  LangString TEXT_TYPE_TITLE ${LANG_ENGLISH} "Execution Type"
228
  LangString TEXT_TYPE_SUBTITLE ${LANG_ENGLISH} "Run ${APPNAME} manually or as a service."
229
  LangString TEXT_PORT_TITLE ${LANG_ENGLISH} "${APPNAME} Web Server Port"
230
  LangString TEXT_PORT_SUBTITLE ${LANG_ENGLISH} "Set the port on which to run the ${APPNAME} web application."
231
  LangString TEXT_READY_TITLE ${LANG_ENGLISH} "Installation Summary"
232
  LangString TEXT_READY_SUBTITLE ${LANG_ENGLISH} "${APPNAME} is ready to be installed."
233

234
; ----------------------------------------------------------------------------
235
; Reserve Files
236
  
237
  ; If using solid compression, files that are required before
238
  ; the actual installation should be stored first in the data block,
239
  ; because this will make the installer start faster.
240
  !insertmacro MUI_RESERVEFILE_LANGDLL
241

242
; ----------------------------------------------------------------------------
243
; FUNCTIONS
244

245
; Called on initialization of the installer
246
Function .onInit
247

248
  !ifdef INNER
249
    ; If INNER is defined, then we aren't supposed to do anything except write out
250
    ; the uninstaller.  This is better than processing a command line option as it means
251
    ; this entire code path is not present in the final (real) installer.
252
    SetSilent silent
253
    WriteUninstaller "$%TEMP%\${UNINNAME}"
254

255
    ; Bail out quickly when running the "inner" installer
256
    Quit
257
  !endif
258

259
  Call CheckIfInstalled                             ; Quit the installer if the application has been installed already
260
  ${StrCase} $AppKey "${APPNAME}" "L"               ; Set AppKey to lowercase application name
261
  ReadEnvStr $ProgramData PROGRAMDATA               ; Read %PROGRAMDATA% environment variable
262
  StrCpy $DefaultDataDir "$ProgramData\${APPNAME}"  ; Set default data directory
263
  StrCpy $INSTDIR "$PROGRAMFILES64\${APPNAME}"      ; Set default installation directory
264
  StrCpy $IsManual 0                                ; Set to run as a Windows service by default
265
  Call CheckUserType                                ; Verifies that the user has administrative privileges
266
  Call FindJavaHome                                 ; Set the $JavaHome variable (if any)
267
  Call FindDataDir                                  ; Find existing data directory from %GEOSERVER_DATA_DIR%
268

269
FunctionEnd
270

271
; Checks if GeoServer has already been installed (also previous versions)
272
Function CheckIfInstalled
273

274
  ClearErrors
275
  ReadRegStr $0 HKLM "Software\${APPNAME}" ""
276
  ${IfNot} ${Errors}    
277
    MessageBox MB_ICONSTOP "${APPNAME} has already been installed on your system.$\r$\n \
278
                            Please remove that version if you wish to update or re-install."
279
    Quit
280
  ${EndIf}
281

282
FunctionEnd
283

284
; Check the user type, and quit if it's not an administrator.
285
Function CheckUserType
286
  ClearErrors
287
  UserInfo::GetName
288
  IfErrors Unsupported
289
  Pop $0
290
  UserInfo::GetAccountType
291
  Pop $1
292
  StrCmp $1 "Admin" IsAdmin NoAdmin
293

294
  NoAdmin:
295
    MessageBox MB_ICONSTOP "Sorry, you must have administrative privileges in order to install ${APPNAME}."
296
    Quit
297

298
  Unsupported:
299
    MessageBox MB_ICONSTOP "Sorry, this installer cannot be run on this Windows version."
300
    Quit
301
		
302
  IsAdmin:
303
    StrCpy $1 "" ; zero out variable
304
	
305
FunctionEnd
306

307
; Remove trailing slash from path
308
!macro GlobalRemoveTrailingSlash un
309
Function ${un}RemoveTrailingSlash
310
  ClearErrors
311
  Pop $6
312

313
  StrCpy $5 "$6" "" -1  ; Read the last char
314
  StrCmp $5 "\" 0 +2    ; Check if last char is a backslash
315
  StrCpy $6 "$6" -1     ; Last char was '\', so remove it
316
  StrCpy $5 ""          ; Cleanup
317
  Push $6
318

319
FunctionEnd
320
!macroend
321

322
; make RemoveTrailingSlash function available both for installer and uninstaller
323
!insertmacro GlobalRemoveTrailingSlash ""
324
!insertmacro GlobalRemoveTrailingSlash "un."
325

326
; Find the %JAVA_HOME% used on the system and assign it to $JavaHome global
327
; Will check environment variables and the registry (both JRE and JDK)
328
; Will set an empty string if the path cannot be determined
329
Function FindJavaHome
330

331
  ClearErrors
332

333
  ReadEnvStr $1 JAVA_HOME
334
  IfErrors Cleanup End    ; found in the environment variable
335

336
  ; No env var set
337
  ClearErrors
338
  ReadRegStr $2 HKLM "SOFTWARE\JavaSoft\Java Runtime Environment" "CurrentVersion"
339
  ReadRegStr $1 HKLM "SOFTWARE\JavaSoft\Java Runtime Environment\$2" "JavaHome"
340

341
  IfErrors Cleanup End    ; found in the registry (JRE)
342

343
  ; No JRE regkey set
344
  ClearErrors
345
  ReadRegStr $2 HKLM "SOFTWARE\JavaSoft\Java Development Kit" "CurrentVersion"
346
  ReadRegStr $1 HKLM "SOFTWARE\JavaSoft\Java Development Kit\$2" "JavaHome"
347

348
  IfErrors Cleanup End    ; found in the registry (JDK)
349

350
  End:
351
    ${If} ${FileExists} "$1\*.*"
352
      ; Set JavaHome variable
353
      Push $1
354
      Call RemoveTrailingSlash
355
      Pop $JavaHome
356
    ${Else}
357
      StrCpy $JavaHome ""
358
    ${EndIf}   
359
    Goto Cleanup
360

361
  Cleanup:
362
    StrCpy $1 ""
363
    StrCpy $2 ""   
364

365
FunctionEnd
366

367
; JRE page display
368
Function SetJRE
369

370
  !insertmacro MUI_HEADER_TEXT "$(TEXT_JRE_TITLE)" "$(TEXT_JRE_SUBTITLE)"
371

372
  StrCpy $JavaHomeTemp $JavaHome
373

374
  nsDialogs::Create 1018
375

376
  ; ${NSD_Create*} x y width height text
377
  ${NSD_CreateLabel} 0 0 100% 56u "Please select a Java Runtime Environment (JRE) if the suggested path below is incorrect. \
378
                                   $\r$\n$\r$\n${APPNAME} requires a 64-Bit Java JRE or JDK (${REQJREVERSIONNAME} \
379
                                   or ${ALTJREVERSIONNAME}). \
380
                                   $\r$\n$\r$\nIf you don't have a (valid) JDK installed, please click on the link below \
381
                                   to download and install the correct JDK. Then shut down and restart the installer."
382

383
  ${NSD_CreateLink} 0 60u 100% 12u "Visit ${JDKNAME} website"
384
  Pop $LinkHWND
385
  ${NSD_OnClick} $LinkHWND OpenDownloadLink
386

387
  ${NSD_CreateDirRequest} 0 90u 240u 13u $JavaHomeTemp
388
  Pop $JavaHomeHWND
389
  ${NSD_OnChange} $JavaHomeHWND ValidateJava
390

391
  ${NSD_CreateBrowseButton} 242u 90u 50u 13u "Browse..."
392
  Pop $BrowseJavaHWND
393
  ${NSD_OnClick} $BrowseJavaHWND BrowseJava
394

395
  ${NSD_CreateLabel} 0 106u 100% 12u " "
396
  Pop $JavaPathCheck
397

398
  Push $JavaHomeHWND
399
  Call ValidateJava
400

401
  nsDialogs::Show
402

403
FunctionEnd
404

405
; Go to Open JDK download page
406
Function OpenDownloadLink
407
  ExecShell "open" "${JDKURL}"
408
FunctionEnd
409

410
; Checks if the 64-bits Java executable can be found in the given JAVA_HOME
411
; Prevents the installer from continuing if the JRE is invalid
412
Function ValidateJava
413

414
  Pop $8
415
  ${NSD_GetText} $8 $JavaHomeTemp
416

417
  StrCpy $JavaExe "$JavaHomeTemp\bin\java.exe"
418
  IfFileExists $JavaExe ReadVersionInfo Errors
419

420
  ReadVersionInfo:
421
    ; Call java.exe with -version param
422
    nsExec::ExecToStack '"$JavaExe" -version'
423
    Pop $R0         ; Return code
424
    Pop $R1         ; Read stdout 
425

426
    ${StrStr} $R2 $R1 "64-Bit"              ; Find "64-Bit" substring in Java version info
427
    ${StrStr} $R3 $R1 "${REQJREVERSION}"    ; Find "11.0" substring in Java version info
428
    ${StrStr} $R4 $R1 "${ALTJREVERSION}"    ; Find "17.0" substring in Java version info
429

430
    ${If} $R2 != ""
431
    ${AndIf} $R3 != ""
432
      Goto ReqVersionFound      ; "64-Bit" and "11.0" substring found
433
    ${EndIf}
434

435
    ${If} $R2 != ""
436
    ${AndIf} $R4 != ""
437
      Goto AltVersionFound      ; "64-Bit" and "17.0" substring found
438
    ${EndIf}
439

440
  Errors:
441
    ${NSD_SetText} $JavaPathCheck "This path is INVALID: no 64-bit JRE (${REQJREVERSIONNAME} \
442
                                   or ${ALTJREVERSIONNAME}) found."
443
    GetDlgItem $0 $HWNDPARENT 1   ; Next button
444
    EnableWindow $0 0             ; Disable
445
    StrCpy $JavaHome ""
446
    Goto End
447

448
  ReqVersionFound:
449
    ${NSD_SetText} $JavaPathCheck "This path is VALID: 64-bit JRE ${REQJREVERSIONNAME} detected."
450
    GetDlgItem $0 $HWNDPARENT 1 ; Next button
451
    EnableWindow $0 1           ; Enable
452
    StrCpy $JavaHome $JavaHomeTemp
453
    Goto End
454

455
  AltVersionFound:
456
    ${NSD_SetText} $JavaPathCheck "This path is VALID: 64-bit JRE ${ALTJREVERSIONNAME} detected."
457
    GetDlgItem $0 $HWNDPARENT 1 ; Next button
458
    EnableWindow $0 1           ; Enable
459
    StrCpy $JavaHome $JavaHomeTemp
460
    Goto End
461

462
  End:
463
    ClearErrors
464
    StrCpy $JavaExe ""
465

466
FunctionEnd
467

468
; Brings up folder dialog for the JRE
469
Function BrowseJava
470

471
  nsDialogs::SelectFolderDialog "Please select the location of your 64-bit JRE (${REQJREVERSIONNAME} \
472
                                 or ${ALTJREVERSIONNAME})..." $PROGRAMFILES64
473
  Pop $1
474

475
  ${If} $1 != "error"   ; i.e. didn't hit cancel
476
    ${NSD_SetText} $JavaHomeHWND $1
477
  ${EndIf}
478

479
FunctionEnd
480

481
; Find the %GEOSERVER_DATA_DIR% used on the system and set $DataDir variable
482
!macro GlobalFindDataDir un
483
Function ${un}FindDataDir
484

485
  ClearErrors
486
  ReadEnvStr $1 GEOSERVER_DATA_DIR
487
  ${IfNot} ${Errors}
488
    Push $1
489
    Call ${un}RemoveTrailingSlash
490
    Pop $1
491
  ${EndIf}
492

493
  ${If} ${Errors}
494
  ${OrIfNot} ${FileExists} "$1\*.*"
495
    Goto DefaultDataDir
496
  ${Else}
497
    Goto ExistingDataDir
498
  ${EndIf}
499

500
  ExistingDataDir:
501
    ClearErrors
502
    StrCpy $DataDir $1
503
    StrCpy $DataDirType 1
504
    Goto Cleanup
505

506
  DefaultDataDir:
507
    ; Existing GeoServer data dir not found: set to %PROGRAMDATA%\GeoServer dir
508
    ClearErrors
509
    StrCpy $DataDir $DefaultDataDir
510
    StrCpy $DataDirType 0
511
    Goto Cleanup
512

513
  Cleanup:
514
    StrCpy $1 ""
515

516
FunctionEnd
517
!macroend
518

519
; make FindDataDir function available both for installer and uninstaller
520
!insertmacro GlobalFindDataDir ""
521
!insertmacro GlobalFindDataDir "un."
522

523
; Taken from https://nsis.sourceforge.io/Check_if_dir_is_empty
524
Function IsEmptyDir
525
  # Stack ->                    # Stack: <directory>
526
  Exch $0                       # Stack: $0
527
  Push $1                       # Stack: $1, $0
528
  FindFirst $0 $1 "$0\*.*"
529
  strcmp $1 "." 0 _notempty
530
    FindNext $0 $1
531
    strcmp $1 ".." 0 _notempty
532
      ClearErrors
533
      FindNext $0 $1
534
      IfErrors 0 _notempty
535
        FindClose $0
536
        Pop $1                  # Stack: $0
537
        StrCpy $0 1
538
        Exch $0                 # Stack: 1 (true)
539
        goto _end
540
     _notempty:
541
       FindClose $0
542
       ClearErrors
543
       Pop $1                   # Stack: $0
544
       StrCpy $0 0
545
       Exch $0                  # Stack: 0 (false)
546
  _end:
547
FunctionEnd
548

549
; Data directory config page
550
Function SetDataDir
551

552
  !insertmacro MUI_HEADER_TEXT "$(TEXT_DATADIR_TITLE)" "$(TEXT_DATADIR_SUBTITLE)"
553

554
  ${If} $DataDir == ""
555
    StrCpy $DataDir $DefaultDataDir
556
  ${EndIf}
557
  StrCpy $DataDirTemp $DataDir
558

559
  nsDialogs::Create 1018
560

561
  ; ${NSD_Create*} x y width height text
562
  ${NSD_CreateLabel} 0 0 100% 56u "If a valid existing ${APPNAME} data directory was found on your system, \
563
                                   the path should be displayed below. Otherwise, a default directory is suggested. \
564
                                   $\r$\nYou can also set another directory, as long as it's empty or non-existing."
565

566
  ${NSD_CreateDirRequest} 0 90u 240u 13u $DataDirTemp
567
  Pop $DataDirHWND
568
  ${NSD_OnChange} $DataDirHWND ValidateDataDir
569

570
  ${NSD_CreateBrowseButton} 242u 90u 50u 13u "Browse..."
571
  Pop $BrowseDataDirHWND
572
  ${NSD_OnClick} $BrowseDataDirHWND BrowseDataDir
573

574
  ${NSD_CreateLabel} 0 106u 100% 12u " "
575
  Pop $DataDirPathCheck
576

577
  ${NSD_SetText} $DataDirHWND $DataDirTemp
578

579
  nsDialogs::Show
580

581
FunctionEnd
582

583
; Checks if the specified data directory is valid.
584
; Prevents the installer from continuing if it's invalid.
585
Function ValidateDataDir
586

587
    Pop $7
588
    ${NSD_GetText} $7 $DataDirTemp
589

590
    ${If} ${FileExists} "$DataDirTemp\global.xml"       ; 2.0+ data dir
591
    ${OrIf} ${FileExists} "$DataDirTemp\catalog.xml"    ; 1.7 data dir
592
      ${NSD_SetText} $DataDirPathCheck "This path contains a valid existing data directory."
593
      StrCpy $DataDirType 1
594
      Goto IsValid
595
    ${EndIf}
596

597
    ; Directory is not an existing one: check if the path is an empty dir
598
    Push "$DataDirTemp\"
599
    Call IsEmptyDir
600
    Pop $9
601

602
    ${If} $9 == 0
603
    ${AndIf} ${FileExists} "$DataDirTemp\*.*"
604
      ; The directory exists but is not empty: we don't accept this (might raise errors later)
605
      ${NSD_SetText} $DataDirPathCheck "This path does not point to a valid empty data directory."
606
      GetDlgItem $0 $HWNDPARENT 1     ; Get Next button
607
      EnableWindow $0 0               ; Disable the button
608
      Goto End        
609
    ${EndIf}
610

611
    ; The directory is empty or does not exist yet: this is valid (it will be created)
612
    ${NSD_SetText} $DataDirPathCheck "The data directory will be created at the given path."
613
    StrCpy $DataDirType 0
614
    Goto IsValid
615

616
    IsValid:
617
      GetDlgItem $0 $HWNDPARENT 1   ; Get Next button
618
      EnableWindow $0 1             ; Enable the button
619
      StrCpy $DataDir $DataDirTemp  ; Set $DataDir variable to valid path
620
      Goto End
621
    
622
    End:
623
      ClearErrors
624

625
FunctionEnd
626

627
; Brings up folder dialog for the data directory
628
Function BrowseDataDir
629

630
  nsDialogs::SelectFolderDialog "Please select a valid data directory:" $ProgramData
631
  Pop $1
632

633
  ${If} $1 != "error"   ; i.e. didn't hit cancel
634
    ${NSD_SetText} $DataDirHWND $1
635
  ${EndIf}
636

637
FunctionEnd
638

639
; Input GS admin credentials for existing data directory
640
Function SetCredentials
641

642
  ; Check if the data dir already exists
643
  StrCmp $DataDirType 1 SkipCreds
644

645
  !insertmacro MUI_HEADER_TEXT "$(TEXT_CREDS_TITLE)" "$(TEXT_CREDS_SUBTITLE)"
646
  nsDialogs::Create 1018
647

648
  ; Populates defaults on first display, and resets to default user blanked any of the values
649
  StrCmp $GSUser "" 0 +3
650
    StrCpy $GSUser "admin"
651
    StrCpy $GSPass "geoserver"
652
  StrCmp $GSPass "" 0 +3
653
    StrCpy $GSUser "admin"
654
    StrCpy $GSPass "geoserver"
655

656
  ;Syntax: ${NSD_*} x y width height text
657
  ${NSD_CreateLabel} 0 0 100% 36u "Please set the administrator username and password for GeoServer:"
658

659
  ${NSD_CreateLabel} 20u 40u 40u 14u "Username"
660
  ${NSD_CreateText} 70u 38u 50u 14u $GSUser
661
  Pop $GSUserHWND
662
  ${NSD_OnChange} $GSUserHWND UsernameCheck
663

664
  ${NSD_CreateLabel} 20u 60u 40u 14u "Password"
665
  ${NSD_CreateText} 70u 58u 50u 14u $GSPass
666
  Pop $GSPassHWND
667
  ${NSD_OnChange} $GSPassHWND PasswordCheck
668

669
  nsDialogs::Show
670

671
  SkipCreds:
672
    ; If data dir exists, we don't want to change credentials
673

674
FunctionEnd
675

676
; When username value is changed (realtime)
677
Function UsernameCheck
678

679
  ; Check for illegal values of $GSUser and fix immediately
680
  ${NSD_GetText} $GSUserHWND $GSUser
681
  StrCmp $GSUser "" NoContinue Continue
682

683
  NoContinue:
684
    GetDlgItem $0 $HWNDPARENT 1 ; Next
685
    EnableWindow $0 0 ; Disable
686
    Goto End
687
  Continue:
688
  StrCmp $GSPass "" +3 0 ; must make sure neither is blank
689
    GetDlgItem $0 $HWNDPARENT 1 ; Next
690
    EnableWindow $0 1 ; Enable
691
  End:
692

693
FunctionEnd
694

695
; When password value is changed (realtime)
696
Function PasswordCheck
697

698
  ; Check for illegal values of $GSPass and fix immediately
699
  ${NSD_GetText} $GSPassHWND $GSPass
700
  StrCmp $GSPass "" NoContinue Continue
701

702
  NoContinue:
703
    GetDlgItem $0 $HWNDPARENT 1 ; Next
704
    EnableWindow $0 0 ; Disable
705
    Goto End
706
  Continue:
707
  StrCmp $GSUser "" +3 0 ; must make sure neither is blank
708
    GetDlgItem $0 $HWNDPARENT 1 ; Next
709
    EnableWindow $0 1 ; Enable
710
  End:
711

712
FunctionEnd
713

714
; Find Marlin JAR file and write service wrapper configuration
715
Function WriteWrapperConfiguration
716

717
  ClearErrors
718
  FileOpen $9 "$INSTDIR\wrapper\jsl64.ini" w  ; Opens a empty file in (over)write mode
719

720
  ; Service section
721
  FileWrite $9 ";GeoServer Java Service Launcher (JSL) configuration$\r$\n$\r$\n"
722
  FileWrite $9 "[service]$\r$\n"
723
  FileWrite $9 "appname=${APPNAME}$\r$\n"
724
  FileWrite $9 "servicename=${APPNAME}$\r$\n"
725
  FileWrite $9 "displayname=${FULLNAME}$\r$\n"
726
  FileWrite $9 "servicedescription=${APPNAME} is an open source software server written in Java that allows users to share and edit geospatial data.$\r$\n"
727
  FileWrite $9 "account=NT Authority\NetworkService$\r$\n$\r$\n"  ; (S-1-5-20) can not be used here
728
  FileWrite $9 ";Console handling$\r$\n"
729
  FileWrite $9 "useconsolehandler=true$\r$\n"
730
  FileWrite $9 "stopclass=java/lang/System$\r$\n"
731
  FileWrite $9 "stopmethod=exit$\r$\n"
732
  FileWrite $9 "stopsignature=(I)V$\r$\n$\r$\n"
733
  FileWrite $9 ";Logging$\r$\n"
734
  FileWrite $9 'logtimestamp="%%Y-%%m-%%d"$\r$\n'
735
  FileWrite $9 "systemout=%GEOSERVER_HOME%\logs\$AppKey.log$\r$\n"
736
  FileWrite $9 "systemoutappend=yes$\r$\n"
737
  FileWrite $9 "systemerr=%GEOSERVER_HOME%\logs\$AppKey.log$\r$\n"
738
  FileWrite $9 "systemerrappend=yes$\r$\n$\r$\n"
739
  FileWrite $9 ";Failure handling$\r$\n"
740
  FileWrite $9 "failureactions_resetperiod=300000$\r$\n"
741
  FileWrite $9 "failureactions_actions=4$\r$\n"
742
  FileWrite $9 "action0_type=1$\r$\n"
743
  FileWrite $9 "action0_delay=10000$\r$\n"
744
  FileWrite $9 "action1_type=1$\r$\n"
745
  FileWrite $9 "action1_delay=10000$\r$\n"
746
  FileWrite $9 "action2_type=1$\r$\n"
747
  FileWrite $9 "action2_delay=10000$\r$\n"
748
  FileWrite $9 "action3_type=0$\r$\n"
749
  FileWrite $9 "action3_delay=10000$\r$\n$\r$\n"
750

751
  ; Java section (part 1)
752
  FileWrite $9 "[java]$\r$\n"
753
  FileWrite $9 "jrepath=%JAVA_HOME%$\r$\n"
754
  FileWrite $9 "jvmsearch=path$\r$\n"
755
  FileWrite $9 "wrkdir=%GEOSERVER_HOME%$\r$\n"
756

757
  ; Build command line
758
  StrCpy $2 "-Djava.awt.headless=true -Djetty.http.port=$StartPort -DSTOP.PORT=$StopPort -DSTOP.KEY=$AppKey"
759

760
  ; Find the Marlin renderer JAR
761
  FindFirst $0 $1 "$INSTDIR\webapps\$AppKey\WEB-INF\lib\marlin*.jar"
762
  IfErrors End
763

764
  ; Add Marlin parameters to the command line
765
  StrCpy $2 "$2 -Xbootclasspath/a:./webapps/$AppKey/WEB-INF/lib/$1"
766
  StrCpy $2 "$2 -Dsun.java2d.renderer=org.marlin.pisces.MarlinRenderingEngine"
767
  Goto End
768

769
  End:
770
    ; Finish Java section by writing the command line
771
    ClearErrors
772
    FindClose $0
773
    FileWrite $9 "cmdline=$2 -jar start.jar$\r$\n"
774
    FileClose $9  ; Closes the file    
775

776
FunctionEnd
777

778
; Set the web server port
779
Function SetPorts
780

781
  !insertmacro MUI_HEADER_TEXT "$(TEXT_PORT_TITLE)" "$(TEXT_PORT_SUBTITLE)"
782
  nsDialogs::Create 1018
783

784
  ; Populates defaults on first display, and resets to default user blanked any of the values
785
  StrCmp $StartPort "" 0 +2
786
  StrCpy $StartPort "8080"
787
  
788
  Call SetStopPort
789

790
  ;Syntax: ${NSD_*} x y width height text
791
  ${NSD_CreateLabel} 0 0 100% 26u "Specify the ${APPNAME} web server port. When in doubt, use the default ($StartPort)."
792

793
  ${NSD_CreateLabel} 0 30u 20u 14u "Port"  
794
  ${NSD_CreateNumber} 25u 28u 50u 14u $StartPort
795
  Pop $PortHWND
796
  ${NSD_OnChange} $PortHWND PortCheck
797

798
  ${NSD_CreateLabel} 85u 30u 120u 14u "Valid range is 80, 1024-65535." 
799

800
  nsDialogs::Show
801

802
FunctionEnd
803

804
; Set $StopPort variable based on $StartPort
805
; Also sets localized URL based on start port (while we're here)
806
Function SetStopPort
807

808
  IntOp $StopPort $StartPort - 1
809
  StrCpy $LocalUrl "http://localhost:$StartPort/$AppKey"
810

811
FunctionEnd
812

813
; When port value is changed (realtime)
814
Function PortCheck
815

816
  ; Check for illegal values of $StartPort and fix immediately
817
  ${NSD_GetText} $PortHWND $StartPort
818

819
  ; Check for illegal values of $StartPort
820
  ${If} $StartPort = 80
821
    GetDlgItem $0 $HWNDPARENT 1     ; Next
822
    EnableWindow $0 1               ; Enable
823
  ${Else}  
824
     ${If} $StartPort < 1024        ; Too low
825
     ${OrIf} $StartPort > 65535     ; Too high
826
      GetDlgItem $0 $HWNDPARENT 1   ; Next
827
      EnableWindow $0 0             ; Disable
828
     ${Else}
829
      GetDlgItem $0 $HWNDPARENT 1   ; Next
830
      EnableWindow $0 1             ; Enable
831
     ${EndIf}
832
   ${EndIf}
833

834
   Call SetStopPort
835

836
FunctionEnd
837

838
; Manual vs service selection
839
Function SetInstallType
840

841
  nsDialogs::Create 1018
842

843
  !insertmacro MUI_HEADER_TEXT "$(TEXT_TYPE_TITLE)" "$(TEXT_TYPE_SUBTITLE)"
844

845
  ;Syntax: ${NSD_*} x y width height text
846
  ${NSD_CreateLabel} 0 0 100% 24u "Select how you wish to run ${APPNAME}.$\r$\nIf you don't know which option to choose, select the $\"Install as a service$\" option."
847
  ${NSD_CreateRadioButton} 10u 28u 50% 12u "Install as a service (recommended)"
848
  Pop $Service
849
  ${NSD_CreateLabel} 10u 44u 90% 24u "Installed for all users. Runs as a Windows network service for greater security."
850

851
  ${NSD_CreateRadioButton} 10u 72u 50% 12u "Run manually"
852
  Pop $Manual
853
  ${NSD_CreateLabel} 10u 88u 90% 24u "Installed for the current user. Must be manually started and stopped."
854

855
  ${If} $IsManual == 1
856
    ${NSD_Check} $Manual ; Default
857
  ${Else}
858
    ${NSD_Check} $Service
859
  ${EndIf}
860

861
  nsDialogs::Show
862

863
FunctionEnd
864

865
; Records the final state of manual vs service
866
Function InstallTypeLeave
867

868
  ${NSD_GetState} $Manual $IsManual
869
  ; $IsManual = 1 -> Run manually
870
  ; $IsManual = 0 -> Run as service
871
FunctionEnd
872

873
; Summary page before install
874
Function ShowSummary
875

876
  nsDialogs::Create 1018
877
  !insertmacro MUI_HEADER_TEXT "$(TEXT_READY_TITLE)" "$(TEXT_READY_SUBTITLE)"
878

879
  ;Syntax: ${NSD_*} x y width height text
880
  ${NSD_CreateLabel} 0 0 100% 24u "Please review the settings below and click the Back button if \
881
                                   changes need to be made. Click the Install button to continue."
882

883
  ; Directories
884
  ${NSD_CreateLabel} 10u 25u 35% 24u "Installation directory:"
885
  ${NSD_CreateLabel} 40% 25u 60% 24u "$INSTDIR"
886

887
  ${NSD_CreateLabel} 10u 45u 35% 24u "Data directory:"
888
  ${NSD_CreateLabel} 40% 45u 60% 24u "$DataDir"
889

890
  ; Install type
891
  ${NSD_CreateLabel} 10u 65u 35% 24u "Installation type:"
892
  ${If} $IsManual == 1
893
    ${NSD_CreateLabel} 40% 65u 60% 24u "Run manually"
894
  ${Else}
895
    ${NSD_CreateLabel} 40% 65u 60% 24u "Installed as a service"
896
  ${EndIf}
897
 
898
  ; JRE
899
  ${NSD_CreateLabel} 10u 85u 35% 24u "Java Runtime Environment:"
900
  ${NSD_CreateLabel} 40% 85u 60% 24u "$JavaHome"
901

902
  ; Server Port
903
  ${NSD_CreateLabel} 10u 105u 35% 24u "Web server port:"
904
  ${NSD_CreateLabel} 40% 105u 60% 24u "$StartPort"
905

906
  nsDialogs::Show
907

908
FunctionEnd
909

910
; Write an environment variable
911
Function WriteEnvVar
912

913
  Pop $4
914
  Pop $3
915

916
  WriteRegExpandStr HKLM "SYSTEM\CurrentControlSet\Control\Session Manager\Environment" $3 $4
917
  SendMessage ${HWND_BROADCAST} ${WM_WININICHANGE} 0 "STR:Environment" /TIMEOUT=5000
918

919
  StrCpy $3 ""
920
  StrCpy $4 ""
921

922
FunctionEnd
923

924
; Remove an environment variable
925
Function un.DeleteEnvVar
926

927
  Pop $3
928
  DeleteRegValue HKLM "SYSTEM\CurrentControlSet\Control\Session Manager\Environment" $3
929
  StrCpy $3 ""
930

931
FunctionEnd
932

933
; Copy Jetty INI file line by line, but modify start port
934
Function CreateNewJettyIni
935

936
  FileOpen $0 $INSTDIR\start.default.ini r    ; Open the default ini
937
  FileOpen $1 $INSTDIR\start.ini w            ; Create the user ini
938
  
939
  LOOP:
940
    IfErrors exit_loop
941
    FileRead $0 $2
942
    ${StrLoc} $3 $2 "jetty.http.port=8080" ">"
943
    ${If} $3 == "0"
944
      FileWrite $1 "jetty.http.port=$StartPort"
945
    ${Else}
946
      FileWrite $1 $2
947
    ${EndIf}
948
    Goto LOOP
949
  
950
  exit_loop:
951
    FileClose $0
952
    FileClose $1
953

954
FunctionEnd
955

956
; ----------------------------------------------------------------------------
957
; SECTIONS
958

959
; The main install section
960
Section "GeoServer" SectionMain
961

962
  SectionIn RO ; Makes this install mandatory
963
  SetOverwrite on
964

965
  DetailPrint "Copying program files..."
966

967
  ; Create program folder and copy files only from unzipped binary distribution
968
  CreateDirectory "$INSTDIR"
969
  ;CopyFiles /SILENT /FILESONLY "..\source\*.*" "$INSTDIR"
970

971
  ; Copy relevant folders from unzipped binary distribution (recursively)
972
  SetOutPath "$INSTDIR"
973
  File /r /x "*.sh" "..\source\bin"  ; Copy manual start/stop *.bat files (skip *.sh)
974
  File /r "..\source\etc"
975
  File /r "..\source\lib"
976
  File /r "..\source\license"
977
  File /r "..\source\logs"
978
  File /r "..\source\modules"
979
  File /r "..\source\resources"
980
  File /r "..\source\webapps"
981
  File "..\source\*.txt"
982
  File "..\source\*.html"
983

984

985
  ; Copy Jetty files, manipulate .ini
986
  File "..\source\start.jar"
987
  File "/oname=start.default.ini" "..\source\start.ini"
988
  Call CreateNewJettyIni
989

990
  ; Copy icon files
991
  CreateDirectory "$INSTDIR\ico"
992
  SetOutPath "$INSTDIR\ico"
993
  File "/oname=gs.ico" "img\installer.ico"
994
  File "img\start.ico"
995
  File "img\stop.ico"
996
  File "img\info.ico"
997

998
  ; Create Java IO temp dir
999
  CreateDirectory "$INSTDIR\work"
1000

1001
  ; Special handling of the 'data_dir'
1002
  ${If} $DataDirType == 0
1003
    ; Only place files, when NOT using an existing folder
1004
    DetailPrint "Creating data directory..."
1005
    CreateDirectory $DataDir
1006
    ${If} ${Errors}
1007
    ${AndIfNot} ${FileExists} "$DataDir\*.*"
1008
      DetailPrint "Failed to create data directory!"
1009
      MessageBox mb_IconStop|mb_TopMost|mb_SetForeground "Cannot create data directory $DataDir"
1010
      Abort
1011
    ${EndIf}
1012
    SetOutPath $DataDir
1013
    File /r "..\source\data_dir\*.*"
1014
  ${EndIf}
1015

1016
  DetailPrint "Writing environment variables..."
1017

1018
  ; Write environment variables
1019
  Push "JAVA_HOME"
1020
  Push "$JavaHome"
1021
  Call WriteEnvVar
1022

1023
  Push "GEOSERVER_HOME"
1024
  Push "$INSTDIR"
1025
  Call WriteEnvVar
1026

1027
  Push "GEOSERVER_DATA_DIR"
1028
  Push "$DataDir"
1029
  Call WriteEnvVar
1030

1031
  ${If} $IsManual == 0 ; install as service
1032

1033
    DetailPrint "Setting up Windows service..."
1034

1035
    ; Create a directory for the wrapper
1036
    CreateDirectory "$INSTDIR\wrapper"
1037
    SetOutPath "$INSTDIR\wrapper"
1038
    File "wrapper\LICENSE.txt"
1039
    File "wrapper\README.md"
1040
    
1041
    ; Copy JSL, rename and sign with SHA1, add to output dir
1042
    !system 'copy /y /b wrapper\jsl64.exe wrapper\${APPNAME}.exe'
1043
    !system '${SIGNCOMMAND} wrapper\${APPNAME}.exe'
1044
    File "wrapper\${APPNAME}.exe"
1045

1046
    ; Generate JSL configuration ini file
1047
    Call WriteWrapperConfiguration
1048

1049
    ; Install the service using Java Service Launcher and start it
1050
    ; jsl64.exe -install|configure|remove|run|runapp (<ini file>) (-console hide|attach|new)
1051
    DetailPrint "Installing Windows service..."
1052
    nsExec::ExecToLog '"$INSTDIR\wrapper\${APPNAME}.exe" -install "$INSTDIR\wrapper\jsl64.ini" -console attach'
1053
    Pop $0
1054
    ${If} $0 != "0"
1055
      DetailPrint "Error: $0"
1056
    ${EndIf}
1057
    ClearErrors
1058
    Sleep 4000    ; make sure install has finished
1059
    
1060
  ${EndIf}
1061

1062
  ; Grant full access to directories that require them:
1063
  ; - Logging directory
1064
  ; - Data directory
1065
  ; - Working directory
1066
  ; This requires the NSIS AccessControl plugin at https://nsis.sourceforge.io/AccessControl_plug-in
1067
  ; For more info, see https://nsis.sourceforge.io/How_can_I_install_a_plugin#NSIS_plugin_installation
1068
  DetailPrint "Granting access..."
1069
  ${If} $IsManual == 1      ; manual run -> grant to Users group
1070
    AccessControl::GrantOnFile "$INSTDIR\work" "(S-1-5-32-545)" "FullAccess"
1071
    AccessControl::GrantOnFile "$INSTDIR\logs" "(S-1-5-32-545)" "FullAccess"
1072
    AccessControl::GrantOnFile "$DataDir" "(S-1-5-32-545)" "FullAccess"
1073
  ${ElseIf} $IsManual == 0  ; run as service -> grant to NT AUTHORITY\Network Service
1074
    AccessControl::GrantOnFile "$INSTDIR\work" "(S-1-5-20)" "FullAccess"
1075
    AccessControl::GrantOnFile "$INSTDIR\logs" "(S-1-5-20)" "FullAccess"
1076
    AccessControl::GrantOnFile "$DataDir" "(S-1-5-20)" "FullAccess"
1077
  ${EndIf}
1078

1079
SectionEnd
1080

1081
!ifndef INNER
1082

1083
  ; What happens at the end of the install
1084
  Section -FinishSection
1085

1086
    ${If} $IsManual == 0  ; service
1087

1088
      DetailPrint "Starting Windows service..."
1089

1090
      ; Start the installed service using Windows "net" command
1091
      nsExec::ExecToLog 'net start ${APPNAME}'
1092
      Pop $0
1093
      ${If} $0 != "0"
1094
        DetailPrint "Error: $0"
1095
      ${EndIf}
1096
      ClearErrors
1097
      Sleep 2000
1098

1099
      DetailPrint "Writing batch files..."
1100

1101
      ; Add simple start/stop service batch files
1102
      SetOutPath "$INSTDIR\bin"
1103

1104
      FileOpen $9 startService.bat w  ; Creates a new bat file and opens it
1105
      FileWrite $9 'net start ${APPNAME}$\r$\n'
1106
      FileClose $9                    ; Closes the file
1107

1108
      FileOpen $9 stopService.bat w   ; Creates a new bat file and opens it
1109
      FileWrite $9 'net stop ${APPNAME}$\r$\n'
1110
      FileClose $9                    ; Closes the file
1111

1112
    ${EndIf}
1113
    
1114
    DetailPrint "Creating Start Menu shortcuts..."
1115

1116
    ; Begin writing Start Menu
1117
    !insertmacro MUI_STARTMENU_WRITE_BEGIN Application
1118

1119
      ; Create Start Menu folder
1120
      CreateDirectory "$SMPROGRAMS\$MenuFolder"
1121

1122
      ; Create shortcut to official homepage    
1123
      CreateShortCut "$SMPROGRAMS\$MenuFolder\About ${APPNAME}.lnk" "${HOMEPAGE}" "" "$INSTDIR\ico\info.ico" 0
1124
      
1125
      ; Create shortcut to application webpage
1126
      CreateShortCut "$SMPROGRAMS\$MenuFolder\${APPNAME} Web Portal.lnk" "$LocalUrl" "" "$INSTDIR\ico\gs.ico" 0
1127

1128
      ; Create batch file shortcuts in appropriate target directory and move them to Start Menu folder
1129
      ; Also make sure that they are executed as administrator (else they won't work)
1130
      SetOutPath "$INSTDIR\bin"
1131
      ${If} $IsManual == 0
1132
        ; Link to service batch files
1133
        CreateShortCut "$INSTDIR\bin\Start ${APPNAME}.lnk" "$INSTDIR\bin\startService.bat" "" "$INSTDIR\ico\start.ico" 0
1134
        CreateShortCut "$INSTDIR\bin\Stop ${APPNAME}.lnk" "$INSTDIR\bin\stopService.bat" "" "$INSTDIR\ico\stop.ico" 0
1135
      ${Else}
1136
        ; Link to manual batch files
1137
        CreateShortCut "$INSTDIR\bin\Start ${APPNAME}.lnk" "$INSTDIR\bin\startup.bat" "" "$INSTDIR\ico\start.ico" 0
1138
        CreateShortCut "$INSTDIR\bin\Stop ${APPNAME}.lnk" "$INSTDIR\bin\shutdown.bat" "" "$INSTDIR\ico\stop.ico" 0      
1139
      ${EndIf}
1140
      Rename "$INSTDIR\bin\Start ${APPNAME}.lnk" "$SMPROGRAMS\$MenuFolder\Start ${APPNAME}.lnk"
1141
      Rename "$INSTDIR\bin\Stop ${APPNAME}.lnk" "$SMPROGRAMS\$MenuFolder\Stop ${APPNAME}.lnk"
1142
      ShellLink::SetRunAsAdministrator "$SMPROGRAMS\$MenuFolder\Start ${APPNAME}.lnk"
1143
      ShellLink::SetRunAsAdministrator "$SMPROGRAMS\$MenuFolder\Stop ${APPNAME}.lnk"
1144

1145
    !insertmacro MUI_STARTMENU_WRITE_END
1146

1147
    DetailPrint "Writing registry keys..."
1148

1149
    ; Registry
1150
    WriteRegStr HKLM "Software\${APPNAME}" "" "$INSTDIR"
1151

1152
    ; For the Add/Remove programs area
1153
    !define UNINSTALLREGPATH "Software\Microsoft\Windows\CurrentVersion\Uninstall"
1154
    WriteRegStr HKLM "${UNINSTALLREGPATH}\${FULLKEY}" "DisplayName" "${FULLNAME}"
1155
    WriteRegStr HKLM "${UNINSTALLREGPATH}\${FULLKEY}" "UninstallString" "$INSTDIR\${UNINNAME}"
1156
    WriteRegStr HKLM "${UNINSTALLREGPATH}\${FULLKEY}" "InstallLocation" "$INSTDIR"
1157
    WriteRegStr HKLM "${UNINSTALLREGPATH}\${FULLKEY}" "DisplayIcon" "$INSTDIR\ico\gs.ico"
1158
    WriteRegStr HKLM "${UNINSTALLREGPATH}\${FULLKEY}" "HelpLink" "${HOMEPAGE}"
1159
    WriteRegDWORD HKLM "${UNINSTALLREGPATH}\${FULLKEY}" "NoModify" "1"
1160
    WriteRegDWORD HKLM "${UNINSTALLREGPATH}\${FULLKEY}" "NoRepair" "1"
1161

1162
    ; Package the signed uninstaller
1163
    SetOutPath "$INSTDIR"
1164
    File "$%TEMP%\${UNINNAME}"
1165

1166
  SectionEnd
1167

1168
!else
1169

1170
  ; Uninstall section
1171
  Section Uninstall
1172

1173
    Call un.FindDataDir
1174

1175
    ; Stop GeoServer
1176
    DetailPrint "Stopping ${FULLNAME}..."
1177

1178
    IfFileExists "$INSTDIR\wrapper\*.*" 0 ManualStop
1179
      nsExec::ExecToLog '"$INSTDIR\bin\stopService.bat"'
1180
      Pop $0
1181
      ${If} $0 != "0"
1182
        DetailPrint "Error: $0"
1183
      ${EndIf}
1184
      ClearErrors
1185
      Sleep 2000    ; make sure it's fully stopped
1186
      
1187
      DetailPrint "Removing ${FULLNAME} service..."
1188
      nsExec::ExecToLog '"$INSTDIR\wrapper\${APPNAME}.exe" -remove "$INSTDIR\wrapper\jsl64.ini" -console attach'
1189
      Pop $0
1190
      ${If} $0 != "0"
1191
        DetailPrint "Error: $0"
1192
      ${EndIf}
1193
      ClearErrors
1194
      Sleep 2000                  ; make sure it's fully removed
1195
      
1196
      RMDir /r "$INSTDIR\wrapper" ; remove the wrapper files
1197

1198
    ManualStop:
1199
      nsExec::ExecToLog '"$INSTDIR\bin\shutdown.bat"'
1200
      Pop $0
1201
      ${If} $0 != "0"
1202
        DetailPrint "Error: $0"
1203
      ${EndIf}
1204
      ClearErrors
1205
      Sleep 2000    ; make sure it's fully stopped
1206

1207
    DetailPrint "Removing environment variables and registry keys..."
1208

1209
    ; Remove GEOSERVER_HOME environment var (but keep JAVA_HOME)
1210
    Push GEOSERVER_HOME
1211
    Call un.DeleteEnvVar
1212

1213
    ; Remove from registry...
1214
    DeleteRegKey HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\${FULLKEY}"
1215
    DeleteRegKey HKLM "SOFTWARE\${APPNAME}"
1216

1217
    DetailPrint "Removing shortcuts..."
1218
    
1219
    ; Delete Shortcuts
1220
    RMDir /r "$SMPROGRAMS\${APPNAME}"
1221

1222
    DetailPrint "Removing program files..."
1223

1224
    ; Delete files/folders
1225
    RMDir /r "$INSTDIR\bin"
1226
    RMDir /r "$INSTDIR\etc"
1227
    RMDir /r "$INSTDIR\modules"
1228
    RMDir /r "$INSTDIR\lib"
1229
    RMDir /r "$INSTDIR\logs"
1230
    RMDir /r "$INSTDIR\resources"
1231
    RMDir /r "$INSTDIR\ico"
1232
    RMDir /r "$INSTDIR\work"        ; working data
1233
    RMDir /r "$INSTDIR\webapps"
1234
    RMDir /r "$INSTDIR\v*"          ; EPSG DB
1235
    Delete "$INSTDIR\*.*"           ; delete root files
1236

1237
    RMDir "$INSTDIR" ; no /r!
1238

1239
    IfFileExists "$INSTDIR\*.*" 0 +3
1240
      DetailPrint "WARNING: could not completely remove $INSTDIR"
1241
      MessageBox MB_OK|MB_ICONEXCLAMATION "Some files or folders could not be removed from:$\r$\n$INSTDIR"
1242

1243
    IfFileExists "$DataDir\*.*" 0 NoDataDir
1244
      ; Ask to also remove the data directory. For silent uninstalls (/SD IDNO), we will KEEP the data directory.
1245
      MessageBox MB_YESNO|MB_DEFBUTTON2 "Would you like to remove all ${APPNAME} data in $DataDir?$\r$\n\
1246
                                         If you ever plan to reinstall ${APPNAME}, this is not recommended." /SD IDNO IDYES RemoveData IDNO KeepData
1247

1248
      KeepData:
1249
        DetailPrint "Keeping ${APPNAME} data directory at $DataDir"
1250
        Goto Finish
1251

1252
      RemoveData:
1253
        DetailPrint "Removing ${APPNAME} data directory..."
1254
        RMDir /r "$DataDir\*.*"
1255
        RMDir "$DataDir"
1256
        IfFileExists "$DataDir\*.*" 0 RemoveEnvVar
1257
          DetailPrint "WARNING: could not completely remove $DataDir"
1258
          MessageBox MB_OK|MB_ICONEXCLAMATION "WARNING - Some files or folders could not be removed from:$\r$\n$DataDir"
1259
          Goto Finish
1260

1261
      RemoveEnvVar:
1262
        ; Delete environment var if data dir was successfully removed
1263
        DetailPrint "Removed ${APPNAME} data directory $DataDir"
1264
        Push GEOSERVER_DATA_DIR
1265
        Call un.DeleteEnvVar
1266
        DetailPrint "Removed GEOSERVER_DATA_DIR system environment variable"
1267
        Goto Finish
1268

1269
    NoDataDir:
1270
      DetailPrint "WARNING: no data directory found"
1271

1272
    Finish:
1273
      ; "Completed" is printed automatically
1274

1275
  SectionEnd
1276

1277
!endif
1278

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.