1
; GEOSERVER WINDOWS INSTALLER SCRIPT FOR NSIS
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)
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
; ----------------------------------------------------------------------------
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
18
; Constants (VERSION should be updated by a script!)
19
!define APPNAME "GeoServer" ; application name
21
!searchparse /file ..\source\VERSION.txt `version = ` VERSION ; Read version from VERSION.txt
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
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.
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
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"
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
59
!finalize "${SIGNCOMMAND} ..\target\${INSTNAME}" ; Sign installer with SHA1
60
!finalize 'DEL /F /Q "wrapper\${APPNAME}.exe"' ; Remove the signed wrapper
62
; ----------------------------------------------------------------------------
94
; ----------------------------------------------------------------------------
97
; Properly display all languages (if any)
103
; Default installation folder
104
InstallDir "$PROGRAMFILES64\${APPNAME}"
106
; Get installation folder from registry if available
107
InstallDirRegKey HKLM "Software\${APPNAME}" ""
109
; Request application privileges for Windows
110
RequestExecutionLevel admin
112
; We would like everyone to see what the (un)installer is doing
114
ShowUninstDetails show
116
; Compression options
118
!echo "Inner invocation"
120
; Initially write temporary output
121
OutFile "$%TEMP%\tempinstaller.exe"
125
!echo "Outer invocation"
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
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
136
; That will have written an uninstaller binary for us.
137
; Now we will digitally sign it.
138
!system "${SIGNCOMMAND} $%TEMP%\${UNINNAME}" = 0
140
; Write the real installer
141
OutFile "..\target\${INSTNAME}"
145
; ----------------------------------------------------------------------------
146
; Modern interface Settings
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.)
156
; "Are you sure you wish to cancel" popup
157
!define MUI_ABORTWARNING
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
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."
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."
178
; ----------------------------------------------------------------------------
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"
187
; ----------------------------------------------------------------------------
188
; Convert NOTICE.txt markdown into an RTF file using Pandoc
190
!system 'pandoc -s -f markdown -t rtf "..\source\license\NOTICE.txt" -o license.rtf'
192
; ----------------------------------------------------------------------------
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
208
; Uninstaller pages (always uninstall everything)
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
215
; ----------------------------------------------------------------------------
218
!insertmacro MUI_LANGUAGE "English" ; The first language is the default language
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."
234
; ----------------------------------------------------------------------------
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
242
; ----------------------------------------------------------------------------
245
; Called on initialization of the installer
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.
253
WriteUninstaller "$%TEMP%\${UNINNAME}"
255
; Bail out quickly when running the "inner" installer
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%
271
; Checks if GeoServer has already been installed (also previous versions)
272
Function CheckIfInstalled
275
ReadRegStr $0 HKLM "Software\${APPNAME}" ""
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."
284
; Check the user type, and quit if it's not an administrator.
285
Function CheckUserType
290
UserInfo::GetAccountType
292
StrCmp $1 "Admin" IsAdmin NoAdmin
295
MessageBox MB_ICONSTOP "Sorry, you must have administrative privileges in order to install ${APPNAME}."
299
MessageBox MB_ICONSTOP "Sorry, this installer cannot be run on this Windows version."
303
StrCpy $1 "" ; zero out variable
307
; Remove trailing slash from path
308
!macro GlobalRemoveTrailingSlash un
309
Function ${un}RemoveTrailingSlash
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
322
; make RemoveTrailingSlash function available both for installer and uninstaller
323
!insertmacro GlobalRemoveTrailingSlash ""
324
!insertmacro GlobalRemoveTrailingSlash "un."
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
333
ReadEnvStr $1 JAVA_HOME
334
IfErrors Cleanup End ; found in the environment variable
338
ReadRegStr $2 HKLM "SOFTWARE\JavaSoft\Java Runtime Environment" "CurrentVersion"
339
ReadRegStr $1 HKLM "SOFTWARE\JavaSoft\Java Runtime Environment\$2" "JavaHome"
341
IfErrors Cleanup End ; found in the registry (JRE)
345
ReadRegStr $2 HKLM "SOFTWARE\JavaSoft\Java Development Kit" "CurrentVersion"
346
ReadRegStr $1 HKLM "SOFTWARE\JavaSoft\Java Development Kit\$2" "JavaHome"
348
IfErrors Cleanup End ; found in the registry (JDK)
351
${If} ${FileExists} "$1\*.*"
352
; Set JavaHome variable
354
Call RemoveTrailingSlash
370
!insertmacro MUI_HEADER_TEXT "$(TEXT_JRE_TITLE)" "$(TEXT_JRE_SUBTITLE)"
372
StrCpy $JavaHomeTemp $JavaHome
374
nsDialogs::Create 1018
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."
383
${NSD_CreateLink} 0 60u 100% 12u "Visit ${JDKNAME} website"
385
${NSD_OnClick} $LinkHWND OpenDownloadLink
387
${NSD_CreateDirRequest} 0 90u 240u 13u $JavaHomeTemp
389
${NSD_OnChange} $JavaHomeHWND ValidateJava
391
${NSD_CreateBrowseButton} 242u 90u 50u 13u "Browse..."
393
${NSD_OnClick} $BrowseJavaHWND BrowseJava
395
${NSD_CreateLabel} 0 106u 100% 12u " "
405
; Go to Open JDK download page
406
Function OpenDownloadLink
407
ExecShell "open" "${JDKURL}"
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
415
${NSD_GetText} $8 $JavaHomeTemp
417
StrCpy $JavaExe "$JavaHomeTemp\bin\java.exe"
418
IfFileExists $JavaExe ReadVersionInfo Errors
421
; Call java.exe with -version param
422
nsExec::ExecToStack '"$JavaExe" -version'
423
Pop $R0 ; Return code
424
Pop $R1 ; Read stdout
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
432
Goto ReqVersionFound ; "64-Bit" and "11.0" substring found
437
Goto AltVersionFound ; "64-Bit" and "17.0" substring found
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
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
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
468
; Brings up folder dialog for the JRE
471
nsDialogs::SelectFolderDialog "Please select the location of your 64-bit JRE (${REQJREVERSIONNAME} \
472
or ${ALTJREVERSIONNAME})..." $PROGRAMFILES64
475
${If} $1 != "error" ; i.e. didn't hit cancel
476
${NSD_SetText} $JavaHomeHWND $1
481
; Find the %GEOSERVER_DATA_DIR% used on the system and set $DataDir variable
482
!macro GlobalFindDataDir un
483
Function ${un}FindDataDir
486
ReadEnvStr $1 GEOSERVER_DATA_DIR
489
Call ${un}RemoveTrailingSlash
494
${OrIfNot} ${FileExists} "$1\*.*"
503
StrCpy $DataDirType 1
507
; Existing GeoServer data dir not found: set to %PROGRAMDATA%\GeoServer dir
509
StrCpy $DataDir $DefaultDataDir
510
StrCpy $DataDirType 0
519
; make FindDataDir function available both for installer and uninstaller
520
!insertmacro GlobalFindDataDir ""
521
!insertmacro GlobalFindDataDir "un."
523
; Taken from https://nsis.sourceforge.io/Check_if_dir_is_empty
525
# Stack -> # Stack: <directory>
527
Push $1 # Stack: $1, $0
528
FindFirst $0 $1 "$0\*.*"
529
strcmp $1 "." 0 _notempty
531
strcmp $1 ".." 0 _notempty
538
Exch $0 # Stack: 1 (true)
545
Exch $0 # Stack: 0 (false)
549
; Data directory config page
552
!insertmacro MUI_HEADER_TEXT "$(TEXT_DATADIR_TITLE)" "$(TEXT_DATADIR_SUBTITLE)"
555
StrCpy $DataDir $DefaultDataDir
557
StrCpy $DataDirTemp $DataDir
559
nsDialogs::Create 1018
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."
566
${NSD_CreateDirRequest} 0 90u 240u 13u $DataDirTemp
568
${NSD_OnChange} $DataDirHWND ValidateDataDir
570
${NSD_CreateBrowseButton} 242u 90u 50u 13u "Browse..."
571
Pop $BrowseDataDirHWND
572
${NSD_OnClick} $BrowseDataDirHWND BrowseDataDir
574
${NSD_CreateLabel} 0 106u 100% 12u " "
575
Pop $DataDirPathCheck
577
${NSD_SetText} $DataDirHWND $DataDirTemp
583
; Checks if the specified data directory is valid.
584
; Prevents the installer from continuing if it's invalid.
585
Function ValidateDataDir
588
${NSD_GetText} $7 $DataDirTemp
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
597
; Directory is not an existing one: check if the path is an empty dir
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
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
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
627
; Brings up folder dialog for the data directory
628
Function BrowseDataDir
630
nsDialogs::SelectFolderDialog "Please select a valid data directory:" $ProgramData
633
${If} $1 != "error" ; i.e. didn't hit cancel
634
${NSD_SetText} $DataDirHWND $1
639
; Input GS admin credentials for existing data directory
640
Function SetCredentials
642
; Check if the data dir already exists
643
StrCmp $DataDirType 1 SkipCreds
645
!insertmacro MUI_HEADER_TEXT "$(TEXT_CREDS_TITLE)" "$(TEXT_CREDS_SUBTITLE)"
646
nsDialogs::Create 1018
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"
656
;Syntax: ${NSD_*} x y width height text
657
${NSD_CreateLabel} 0 0 100% 36u "Please set the administrator username and password for GeoServer:"
659
${NSD_CreateLabel} 20u 40u 40u 14u "Username"
660
${NSD_CreateText} 70u 38u 50u 14u $GSUser
662
${NSD_OnChange} $GSUserHWND UsernameCheck
664
${NSD_CreateLabel} 20u 60u 40u 14u "Password"
665
${NSD_CreateText} 70u 58u 50u 14u $GSPass
667
${NSD_OnChange} $GSPassHWND PasswordCheck
672
; If data dir exists, we don't want to change credentials
676
; When username value is changed (realtime)
677
Function UsernameCheck
679
; Check for illegal values of $GSUser and fix immediately
680
${NSD_GetText} $GSUserHWND $GSUser
681
StrCmp $GSUser "" NoContinue Continue
684
GetDlgItem $0 $HWNDPARENT 1 ; Next
685
EnableWindow $0 0 ; Disable
688
StrCmp $GSPass "" +3 0 ; must make sure neither is blank
689
GetDlgItem $0 $HWNDPARENT 1 ; Next
690
EnableWindow $0 1 ; Enable
695
; When password value is changed (realtime)
696
Function PasswordCheck
698
; Check for illegal values of $GSPass and fix immediately
699
${NSD_GetText} $GSPassHWND $GSPass
700
StrCmp $GSPass "" NoContinue Continue
703
GetDlgItem $0 $HWNDPARENT 1 ; Next
704
EnableWindow $0 0 ; Disable
707
StrCmp $GSUser "" +3 0 ; must make sure neither is blank
708
GetDlgItem $0 $HWNDPARENT 1 ; Next
709
EnableWindow $0 1 ; Enable
714
; Find Marlin JAR file and write service wrapper configuration
715
Function WriteWrapperConfiguration
718
FileOpen $9 "$INSTDIR\wrapper\jsl64.ini" w ; Opens a empty file in (over)write mode
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"
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"
758
StrCpy $2 "-Djava.awt.headless=true -Djetty.http.port=$StartPort -DSTOP.PORT=$StopPort -DSTOP.KEY=$AppKey"
760
; Find the Marlin renderer JAR
761
FindFirst $0 $1 "$INSTDIR\webapps\$AppKey\WEB-INF\lib\marlin*.jar"
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"
770
; Finish Java section by writing the command line
773
FileWrite $9 "cmdline=$2 -jar start.jar$\r$\n"
774
FileClose $9 ; Closes the file
778
; Set the web server port
781
!insertmacro MUI_HEADER_TEXT "$(TEXT_PORT_TITLE)" "$(TEXT_PORT_SUBTITLE)"
782
nsDialogs::Create 1018
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"
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)."
793
${NSD_CreateLabel} 0 30u 20u 14u "Port"
794
${NSD_CreateNumber} 25u 28u 50u 14u $StartPort
796
${NSD_OnChange} $PortHWND PortCheck
798
${NSD_CreateLabel} 85u 30u 120u 14u "Valid range is 80, 1024-65535."
804
; Set $StopPort variable based on $StartPort
805
; Also sets localized URL based on start port (while we're here)
808
IntOp $StopPort $StartPort - 1
809
StrCpy $LocalUrl "http://localhost:$StartPort/$AppKey"
813
; When port value is changed (realtime)
816
; Check for illegal values of $StartPort and fix immediately
817
${NSD_GetText} $PortHWND $StartPort
819
; Check for illegal values of $StartPort
820
${If} $StartPort = 80
821
GetDlgItem $0 $HWNDPARENT 1 ; Next
822
EnableWindow $0 1 ; Enable
824
${If} $StartPort < 1024 ; Too low
825
${OrIf} $StartPort > 65535 ; Too high
826
GetDlgItem $0 $HWNDPARENT 1 ; Next
827
EnableWindow $0 0 ; Disable
829
GetDlgItem $0 $HWNDPARENT 1 ; Next
830
EnableWindow $0 1 ; Enable
838
; Manual vs service selection
839
Function SetInstallType
841
nsDialogs::Create 1018
843
!insertmacro MUI_HEADER_TEXT "$(TEXT_TYPE_TITLE)" "$(TEXT_TYPE_SUBTITLE)"
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)"
849
${NSD_CreateLabel} 10u 44u 90% 24u "Installed for all users. Runs as a Windows network service for greater security."
851
${NSD_CreateRadioButton} 10u 72u 50% 12u "Run manually"
853
${NSD_CreateLabel} 10u 88u 90% 24u "Installed for the current user. Must be manually started and stopped."
856
${NSD_Check} $Manual ; Default
858
${NSD_Check} $Service
865
; Records the final state of manual vs service
866
Function InstallTypeLeave
868
${NSD_GetState} $Manual $IsManual
869
; $IsManual = 1 -> Run manually
870
; $IsManual = 0 -> Run as service
873
; Summary page before install
876
nsDialogs::Create 1018
877
!insertmacro MUI_HEADER_TEXT "$(TEXT_READY_TITLE)" "$(TEXT_READY_SUBTITLE)"
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."
884
${NSD_CreateLabel} 10u 25u 35% 24u "Installation directory:"
885
${NSD_CreateLabel} 40% 25u 60% 24u "$INSTDIR"
887
${NSD_CreateLabel} 10u 45u 35% 24u "Data directory:"
888
${NSD_CreateLabel} 40% 45u 60% 24u "$DataDir"
891
${NSD_CreateLabel} 10u 65u 35% 24u "Installation type:"
893
${NSD_CreateLabel} 40% 65u 60% 24u "Run manually"
895
${NSD_CreateLabel} 40% 65u 60% 24u "Installed as a service"
899
${NSD_CreateLabel} 10u 85u 35% 24u "Java Runtime Environment:"
900
${NSD_CreateLabel} 40% 85u 60% 24u "$JavaHome"
903
${NSD_CreateLabel} 10u 105u 35% 24u "Web server port:"
904
${NSD_CreateLabel} 40% 105u 60% 24u "$StartPort"
910
; Write an environment variable
916
WriteRegExpandStr HKLM "SYSTEM\CurrentControlSet\Control\Session Manager\Environment" $3 $4
917
SendMessage ${HWND_BROADCAST} ${WM_WININICHANGE} 0 "STR:Environment" /TIMEOUT=5000
924
; Remove an environment variable
925
Function un.DeleteEnvVar
928
DeleteRegValue HKLM "SYSTEM\CurrentControlSet\Control\Session Manager\Environment" $3
933
; Copy Jetty INI file line by line, but modify start port
934
Function CreateNewJettyIni
936
FileOpen $0 $INSTDIR\start.default.ini r ; Open the default ini
937
FileOpen $1 $INSTDIR\start.ini w ; Create the user ini
942
${StrLoc} $3 $2 "jetty.http.port=8080" ">"
944
FileWrite $1 "jetty.http.port=$StartPort"
956
; ----------------------------------------------------------------------------
959
; The main install section
960
Section "GeoServer" SectionMain
962
SectionIn RO ; Makes this install mandatory
965
DetailPrint "Copying program files..."
967
; Create program folder and copy files only from unzipped binary distribution
968
CreateDirectory "$INSTDIR"
969
;CopyFiles /SILENT /FILESONLY "..\source\*.*" "$INSTDIR"
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"
985
; Copy Jetty files, manipulate .ini
986
File "..\source\start.jar"
987
File "/oname=start.default.ini" "..\source\start.ini"
988
Call CreateNewJettyIni
991
CreateDirectory "$INSTDIR\ico"
992
SetOutPath "$INSTDIR\ico"
993
File "/oname=gs.ico" "img\installer.ico"
998
; Create Java IO temp dir
999
CreateDirectory "$INSTDIR\work"
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
1007
${AndIfNot} ${FileExists} "$DataDir\*.*"
1008
DetailPrint "Failed to create data directory!"
1009
MessageBox mb_IconStop|mb_TopMost|mb_SetForeground "Cannot create data directory $DataDir"
1013
File /r "..\source\data_dir\*.*"
1016
DetailPrint "Writing environment variables..."
1018
; Write environment variables
1023
Push "GEOSERVER_HOME"
1027
Push "GEOSERVER_DATA_DIR"
1031
${If} $IsManual == 0 ; install as service
1033
DetailPrint "Setting up Windows service..."
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"
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"
1046
; Generate JSL configuration ini file
1047
Call WriteWrapperConfiguration
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'
1055
DetailPrint "Error: $0"
1058
Sleep 4000 ; make sure install has finished
1062
; Grant full access to directories that require them:
1063
; - Logging 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"
1083
; What happens at the end of the install
1084
Section -FinishSection
1086
${If} $IsManual == 0 ; service
1088
DetailPrint "Starting Windows service..."
1090
; Start the installed service using Windows "net" command
1091
nsExec::ExecToLog 'net start ${APPNAME}'
1094
DetailPrint "Error: $0"
1099
DetailPrint "Writing batch files..."
1101
; Add simple start/stop service batch files
1102
SetOutPath "$INSTDIR\bin"
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
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
1114
DetailPrint "Creating Start Menu shortcuts..."
1116
; Begin writing Start Menu
1117
!insertmacro MUI_STARTMENU_WRITE_BEGIN Application
1119
; Create Start Menu folder
1120
CreateDirectory "$SMPROGRAMS\$MenuFolder"
1122
; Create shortcut to official homepage
1123
CreateShortCut "$SMPROGRAMS\$MenuFolder\About ${APPNAME}.lnk" "${HOMEPAGE}" "" "$INSTDIR\ico\info.ico" 0
1125
; Create shortcut to application webpage
1126
CreateShortCut "$SMPROGRAMS\$MenuFolder\${APPNAME} Web Portal.lnk" "$LocalUrl" "" "$INSTDIR\ico\gs.ico" 0
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
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
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"
1145
!insertmacro MUI_STARTMENU_WRITE_END
1147
DetailPrint "Writing registry keys..."
1150
WriteRegStr HKLM "Software\${APPNAME}" "" "$INSTDIR"
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"
1162
; Package the signed uninstaller
1163
SetOutPath "$INSTDIR"
1164
File "$%TEMP%\${UNINNAME}"
1176
DetailPrint "Stopping ${FULLNAME}..."
1178
IfFileExists "$INSTDIR\wrapper\*.*" 0 ManualStop
1179
nsExec::ExecToLog '"$INSTDIR\bin\stopService.bat"'
1182
DetailPrint "Error: $0"
1185
Sleep 2000 ; make sure it's fully stopped
1187
DetailPrint "Removing ${FULLNAME} service..."
1188
nsExec::ExecToLog '"$INSTDIR\wrapper\${APPNAME}.exe" -remove "$INSTDIR\wrapper\jsl64.ini" -console attach'
1191
DetailPrint "Error: $0"
1194
Sleep 2000 ; make sure it's fully removed
1196
RMDir /r "$INSTDIR\wrapper" ; remove the wrapper files
1199
nsExec::ExecToLog '"$INSTDIR\bin\shutdown.bat"'
1202
DetailPrint "Error: $0"
1205
Sleep 2000 ; make sure it's fully stopped
1207
DetailPrint "Removing environment variables and registry keys..."
1209
; Remove GEOSERVER_HOME environment var (but keep JAVA_HOME)
1211
Call un.DeleteEnvVar
1213
; Remove from registry...
1214
DeleteRegKey HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\${FULLKEY}"
1215
DeleteRegKey HKLM "SOFTWARE\${APPNAME}"
1217
DetailPrint "Removing shortcuts..."
1220
RMDir /r "$SMPROGRAMS\${APPNAME}"
1222
DetailPrint "Removing program files..."
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
1237
RMDir "$INSTDIR" ; no /r!
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"
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
1249
DetailPrint "Keeping ${APPNAME} data directory at $DataDir"
1253
DetailPrint "Removing ${APPNAME} data directory..."
1254
RMDir /r "$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"
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"
1270
DetailPrint "WARNING: no data directory found"
1273
; "Completed" is printed automatically