1 ;-----------------------------------------------------------------------
2 ; NSIS Installation Script ;
4 ; khuckins@catalystdevworks.com ;
5 ; This will be a guide to working with NSIS to create an installer. ;
6 ; It is a heavily commented practice installer, basically. ;
8 ; Comments are designated by # and ; ;
9 ; # tends to be at the beginning of a line, while ; is ;
10 ; primarilly used as end-of-line comments. However it's ;
11 ; common to use just ; for comments as well. ;
13 ;------------------------------------------------------------------------
19 !include "MUI2.nsh" ;This enables the use of ModernUI, and must go at the top
21 !include "defines.nsh" ;Definitions for our variables
22 !include "LogicLib.nsh" ;Sparsly documented library, but necessary for any real logic
23 !include "nsDialogs.nsh" ;Need this to create custom pages
25 !include ReplaceInFile.nsh
26 ;---------------------------------------------------------------
28 ; Installer's filename
29 Outfile "${APPNAME} Installer.exe"
30 RequestExecutionLevel admin
37 ;==================================
39 !insertmacro MUI_PAGE_WELCOME
40 !define MUI_PAGE_CUSTOMFUNCTION_PRE ValidateInstall
41 !insertmacro MUI_PAGE_LICENSE "license.rtf" ;Loads licence.rtf to show license content
42 !insertmacro MUI_PAGE_DIRECTORY
43 !insertmacro MUI_PAGE_INSTFILES
44 !insertmacro MUI_PAGE_FINISH
46 !insertmacro MUI_LANGUAGE "English"
48 ;-------------------------------------
49 ; Code to verify if a user is an admin
50 !macro VerifyUserIsAdmin
51 UserInfo::GetAccountType
53 ${If} $0 != "admin" ;Require admin rights
54 messageBox MB_OK|MB_ICONSTOP "Administrator rights required!"
55 setErrorLevel 740 ;ERROR_ELEVATION_REQUIRED
60 ; Find any installed JRE/JDK and return the version or -1
63 ReadRegStr $0 HKLM "SOFTWARE\JavaSoft\JRE" "CurrentVersion"
67 ReadRegStr $0 HKLM "SOFTWARE\JavaSoft\JDK" "CurrentVersion"
73 ReadRegStr $0 HKLM "SOFTWARE\JavaSoft\JRE" "CurrentVersion"
74 SetRegView 32 ; basically SetRegView Default since NSIS only creates 32 bit installers
81 ReadRegStr $0 HKLM "SOFTWARE\JavaSoft\JDK" "CurrentVersion"
87 ReadRegStr $0 HKLM "SOFTWARE\JavaSoft\Java Runtime Environment" "CurrentVersion"
91 ReadRegStr $0 HKLM "SOFTWARE\JavaSoft\Java Development Kit" "CurrentVersion"
97 ReadRegStr $0 HKLM "SOFTWARE\JavaSoft\Java Runtime Environment" "CurrentVersion"
105 ReadRegStr $0 HKLM "SOFTWARE\JavaSoft\Java Development Kit" "CurrentVersion"
107 StrCmp $0 "" +1 Found
120 setShellVarContext all
121 !insertmacro VerifyUserIsAdmin
127 function ValidateInstall
130 StrCmp $0 "-1" NoJava
131 ${If} $0 S< ${JRE_MIN_VERSION}
132 MessageBox MB_OK "Please update Java to version ${JRE_MIN_VERSION} or higher. Setup will now exit." /SD IDOK IDOK QUIT
134 ; Hatch Version Check
135 ReadRegStr $1 HKLM "SOFTWARE\${COMPANYNAME}\${APPNAME}" "Version"
137 ${If} $1 S== ${FULLVERSION} ;Same version is installed
138 MessageBox MB_OKCANCEL|MB_ICONINFORMATION "You already have this version of ${APPNAME} installed. You must uninstall the currently installed version to continue." /SD IDOK IDOK UNINSTALL IDCANCEL QUIT
139 ${ElseIf} $1 S> ${FULLVERSION} ;Older version is installed
140 MessageBox MB_OKCANCEL|MB_ICONEXCLAMATION "You are tring to install an older version of ${APPNAME} than the one you currently have installed. You must uninstall the currently installed verion to continue." /SD IDOK IDOK UNINSTALL IDCANCEL QUIT
141 ${ElseIf} $1 S< ${FULLVERSION} ;Newer version is installed
142 MessageBox MB_OKCANCEL|MB_ICONINFORMATION "You have a previous version of ${APPNAME} installed. The previous version will be uninrtalled so installation can continue." /SD IDOK IDOK UNINSTALL IDCANCEL QUIT
145 ReadRegStr $1 HKLM "SOFTWARE\${COMPANYNAME}\${APPNAME}" "Install Path"
146 ; Manually copying the uninstaller like this allows the use of the _? param which is required for ExecWait while also allowing all files to be deleted.
147 CopyFiles /SILENT "$1\Uninstall ${APPNAME}.exe" "$TEMP\Uninstall ${APPNAME}.exe"
148 ExecWait '"$TEMP\Uninstall ${APPNAME}.exe" /S _?=$1'
149 Delete /REBOOTOK "$TEMP\Uninstall ${APPNAME}.exe"
152 MessageBox MB_OK|MB_ICONSTOP "Java Not Detected. Please install a JRE of version ${JRE_MIN_VERSION} or greater." /SD IDOK
159 ;--------------------------
160 ; Where our install files go
161 InstallDir "$PROGRAMFILES\${APPNAME}" ;This is where our variables come in.
162 ;----------------------------------------------
165 ; Install directory files - keep these in the same directory
166 ; as the script before compiling.
167 SetOutPath $INSTDIR\ ;Sets output path to our InstallDir
169 File /r ..\..\extension
171 File ..\..\hatch.properties
172 File ..\..\logging.properties
174 ; Set path variable in org.ils_evergreen.hatch.json to $INSTDIR\hatch.bat
175 ${StrRep} '$0' '$INSTDIR' '\' '\\'
176 !insertmacro _ReplaceInFile "$INSTDIR\extension\host\org.evergreen_ils.hatch.json" "/path/to/hatch.sh" "$0\\hatch.bat"
179 writeUninstaller "$INSTDIR\Uninstall ${APPNAME}.exe"
181 ; Registry info for Add/Remove Programs
182 WriteRegStr HKLM "SOFTWARE\${COMPANYNAME}\${APPNAME}" "Install Path" $INSTDIR
183 WriteRegStr HKLM "SOFTWARE\${COMPANYNAME}\${APPNAME}" "Version" "${FULLVERSION}"
184 WriteRegStr HKLM "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\${APPNAME}" "DisplayName" "${COMPANYNAME} - ${APPNAME} - ${DESCRIPTION}"
185 WriteRegStr HKLM "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\${APPNAME}" "UninstallString" "$INSTDIR\Uninstall ${APPNAME}.exe"
186 WriteRegStr HKLM "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\${APPNAME}" "QuietUninstallString" "$INSTDIR\Uninstall ${APPNAME}.exe /S"
187 WriteRegStr HKLM "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\${APPNAME}" "InstallLocation" "$INSTDIR"
188 WriteRegStr HKLM "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\${APPNAME}" "DisplayIcon" "$INSTDIR\logo.ico"
189 WriteRegStr HKLM "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\${APPNAME}" "Publisher" "${COMPANYNAME}"
190 StrCmp "${HELPURL}" "" +2
191 WriteRegStr HKLM "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\${APPNAME}" "HelpLink" "${HELPURL}"
192 StrCmp "${UPDATEURL}" "" +2
193 WriteRegStr HKLM "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\${APPNAME}" "URLUpdateInfo" "${UPDATEURL}"
194 StrCmp "${ABOUTURL}" "" +2
195 WriteRegStr HKLM "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\${APPNAME}" "URLInfoAbout" "${ABOUTURL}"
196 WriteRegStr HKLM "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\${APPNAME}" "DisplayVersion" "${VERSIONMAJOR}.${VERSIONMINOR}.${VERSIONBUILD}"
197 WriteRegDWORD HKLM "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\${APPNAME}" "VersionMajor" ${VERSIONMAJOR}
198 WriteRegDWORD HKLM "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\${APPNAME}" "VersionMinor" ${VERSIONMINOR}
199 # There is no option for modifying or repairing the install
200 WriteRegDWORD HKLM "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\${APPNAME}" "NoModify" 1
201 WriteRegDWORD HKLM "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\${APPNAME}" "NoRepair" 1
202 # Set the INSTALLSIZE constant (!defined at the top of this script) so Add/Remove Programs can accurately report the size
203 WriteRegDWORD HKLM "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\${APPNAME}" "EstimatedSize" ${INSTALLSIZE}
205 ; Connect Hatch to Chrome and install the Hatch extension from the Chrome Web Store
206 WriteRegStr HKLM "SOFTWARE\Google\Chrome\NativeMessagingHosts\org.evergreen_ils.hatch" "" "$INSTDIR\extension\host\org.evergreen_ils.hatch.json"
207 WriteRegStr HKLM "Software\Google\Chrome\Extensions\${EXTENSIONID}" "update_url" "${EXTENSION_UPDATEURL}"
211 #############################
215 SetShellVarContext all
218 MessageBox MB_OKCANCEL "Permanently remove ${APPNAME}?" /SD IDOK IDOK next
221 !insertmacro VerifyUserIsAdmin
225 # Remove the actual files
226 Delete /REBOOTOK "$INSTDIR\hatch.bat"
227 Delete /REBOOTOK "$INSTDIR\hatch.properties"
228 Delete /REBOOTOK "$INSTDIR\logging.properties"
229 ; blindly using /r isn't ideal but the extreme unlikelyhood of there being \lib or \extension folders under $PROGRAMFILES makes it low risk.
230 RmDir /r /REBOOTOK "$INSTDIR\extension"
231 RmDir /r /REBOOTOK "$INSTDIR\lib"
232 # Delete uninstaller last
233 Delete /REBOOTOK "$INSTDIR\Uninstall ${APPNAME}.exe"
235 # Remove installation directory
236 RmDir /REBOOTOK "$INSTDIR"
238 # Remove uninstaller info from registry
239 DeleteRegKey HKLM "SOFTWARE\${COMPANYNAME}\${APPNAME}"
240 DeleteRegKey HKLM "SOFTWARE\${COMPANYNAME}"
241 DeleteRegKey HKLM "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\${APPNAME}"
242 DeleteRegKey HKLM "SOFTWARE\Google\Chrome\NativeMessagingHosts\org.evergreen_ils.hatch"
243 DeleteRegKey HKLM "SOFTWARE\Google\Chrome\Extensions\${EXTENSIONID}"
245 DeleteRegKey HKLM "SOFTWARE\Wow6432Node\Google\Chrome\Extensions\${EXTENSIONID}"
249 MessageBox MB_YESNO "A reboot is required to finish the installation. Do you wish to reboot now?" /SD IDNO IDNO Done