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 ; Add local copy of AccessControl plugin
31 ; Installer's filename
32 Outfile "${APPNAME}-Installer-${FULLVERSION}.exe"
33 RequestExecutionLevel admin
40 ;==================================
42 !insertmacro MUI_PAGE_WELCOME
43 !define MUI_PAGE_CUSTOMFUNCTION_PRE ValidateInstall
44 !insertmacro MUI_PAGE_LICENSE "license.rtf" ;Loads licence.rtf to show license content
45 !insertmacro MUI_PAGE_DIRECTORY
46 !insertmacro MUI_PAGE_INSTFILES
47 !insertmacro MUI_PAGE_FINISH
49 !insertmacro MUI_LANGUAGE "English"
51 ;-------------------------------------
52 ; Code to verify if a user is an admin
53 !macro VerifyUserIsAdmin
54 UserInfo::GetAccountType
56 ${If} $0 != "admin" ;Require admin rights
57 messageBox MB_OK|MB_ICONSTOP "Administrator rights required!"
58 setErrorLevel 740 ;ERROR_ELEVATION_REQUIRED
63 ; Find any installed JRE/JDK and return the version or -1
66 ReadRegStr $0 HKLM "SOFTWARE\JavaSoft\JRE" "CurrentVersion"
70 ReadRegStr $0 HKLM "SOFTWARE\JavaSoft\JDK" "CurrentVersion"
76 ReadRegStr $0 HKLM "SOFTWARE\JavaSoft\JRE" "CurrentVersion"
77 SetRegView 32 ; basically SetRegView Default since NSIS only creates 32 bit installers
84 ReadRegStr $0 HKLM "SOFTWARE\JavaSoft\JDK" "CurrentVersion"
90 ReadRegStr $0 HKLM "SOFTWARE\JavaSoft\Java Runtime Environment" "CurrentVersion"
94 ReadRegStr $0 HKLM "SOFTWARE\JavaSoft\Java Development Kit" "CurrentVersion"
100 ReadRegStr $0 HKLM "SOFTWARE\JavaSoft\Java Runtime Environment" "CurrentVersion"
102 StrCmp $0 "" +1 Found
108 ReadRegStr $0 HKLM "SOFTWARE\JavaSoft\Java Development Kit" "CurrentVersion"
110 StrCmp $0 "" +1 Found
123 setShellVarContext all
124 !insertmacro VerifyUserIsAdmin
130 function ValidateInstall
133 StrCmp $0 "-1" NoJava
134 ${If} $0 S< ${JRE_MIN_VERSION}
135 MessageBox MB_OK "Please update Java to version ${JRE_MIN_VERSION} or higher. Setup will now exit." /SD IDOK IDOK QUIT
137 ; Hatch Version Check
138 ReadRegStr $1 HKLM "SOFTWARE\${COMPANYNAME}\${APPNAME}" "Version"
140 ${If} $1 S== ${FULLVERSION} ;Same version is installed
141 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
142 ${ElseIf} $1 S> ${FULLVERSION} ;Older version is installed
143 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
144 ${ElseIf} $1 S< ${FULLVERSION} ;Newer version is installed
145 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
148 ReadRegStr $1 HKLM "SOFTWARE\${COMPANYNAME}\${APPNAME}" "Install Path"
149 ; 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.
150 CopyFiles /SILENT "$1\Uninstall ${APPNAME}.exe" "$TEMP\Uninstall ${APPNAME}.exe"
151 ExecWait '"$TEMP\Uninstall ${APPNAME}.exe" /S _?=$1'
152 Delete /REBOOTOK "$TEMP\Uninstall ${APPNAME}.exe"
155 MessageBox MB_OK|MB_ICONSTOP "Java Not Detected. Please install a JRE of version ${JRE_MIN_VERSION} or greater." /SD IDOK
162 ;--------------------------
163 ; Where our install files go
164 InstallDir "$PROGRAMFILES\${APPNAME}" ;This is where our variables come in.
165 ;----------------------------------------------
168 ; Install directory files - keep these in the same directory
169 ; as the script before compiling.
170 SetOutPath $INSTDIR\ ;Sets output path to our InstallDir
172 File /r ..\..\extension
174 File ..\..\hatch.properties
175 File ..\..\logging.properties
177 ; Set path variable in org.ils_evergreen.hatch.json to $INSTDIR\hatch.bat
178 ${StrRep} '$0' '$INSTDIR' '\' '\\'
179 !insertmacro _ReplaceInFile "$INSTDIR\extension\host\org.evergreen_ils.hatch.json" "/path/to/hatch.sh" "$0\\hatch.bat"
180 AccessControl::EnableFileInheritance "$INSTDIR\extension\host\org.evergreen_ils.hatch.json"
183 writeUninstaller "$INSTDIR\Uninstall ${APPNAME}.exe"
185 ; Registry info for Add/Remove Programs
186 WriteRegStr HKLM "SOFTWARE\${COMPANYNAME}\${APPNAME}" "Install Path" $INSTDIR
187 WriteRegStr HKLM "SOFTWARE\${COMPANYNAME}\${APPNAME}" "Version" "${FULLVERSION}"
188 WriteRegStr HKLM "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\${APPNAME}" "DisplayName" "${COMPANYNAME} - ${APPNAME} - ${DESCRIPTION}"
189 WriteRegStr HKLM "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\${APPNAME}" "UninstallString" "$INSTDIR\Uninstall ${APPNAME}.exe"
190 WriteRegStr HKLM "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\${APPNAME}" "QuietUninstallString" "$INSTDIR\Uninstall ${APPNAME}.exe /S"
191 WriteRegStr HKLM "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\${APPNAME}" "InstallLocation" "$INSTDIR"
192 WriteRegStr HKLM "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\${APPNAME}" "DisplayIcon" "$INSTDIR\logo.ico"
193 WriteRegStr HKLM "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\${APPNAME}" "Publisher" "${COMPANYNAME}"
194 StrCmp "${HELPURL}" "" +2
195 WriteRegStr HKLM "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\${APPNAME}" "HelpLink" "${HELPURL}"
196 StrCmp "${UPDATEURL}" "" +2
197 WriteRegStr HKLM "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\${APPNAME}" "URLUpdateInfo" "${UPDATEURL}"
198 StrCmp "${ABOUTURL}" "" +2
199 WriteRegStr HKLM "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\${APPNAME}" "URLInfoAbout" "${ABOUTURL}"
200 WriteRegStr HKLM "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\${APPNAME}" "DisplayVersion" "${VERSIONMAJOR}.${VERSIONMINOR}.${VERSIONBUILD}"
201 WriteRegDWORD HKLM "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\${APPNAME}" "VersionMajor" ${VERSIONMAJOR}
202 WriteRegDWORD HKLM "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\${APPNAME}" "VersionMinor" ${VERSIONMINOR}
203 # There is no option for modifying or repairing the install
204 WriteRegDWORD HKLM "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\${APPNAME}" "NoModify" 1
205 WriteRegDWORD HKLM "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\${APPNAME}" "NoRepair" 1
206 # Set the INSTALLSIZE constant (!defined at the top of this script) so Add/Remove Programs can accurately report the size
207 WriteRegDWORD HKLM "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\${APPNAME}" "EstimatedSize" ${INSTALLSIZE}
209 ; Connect Hatch to Chrome and install the Hatch extension from the Chrome Web Store
210 WriteRegStr HKLM "SOFTWARE\Google\Chrome\NativeMessagingHosts\org.evergreen_ils.hatch" "" "$INSTDIR\extension\host\org.evergreen_ils.hatch.json"
211 WriteRegStr HKLM "Software\Google\Chrome\Extensions\${EXTENSIONID}" "update_url" "${EXTENSION_UPDATEURL}"
215 #############################
219 SetShellVarContext all
222 MessageBox MB_OKCANCEL "Permanently remove ${APPNAME}?" /SD IDOK IDOK next
225 !insertmacro VerifyUserIsAdmin
229 # Remove the actual files
230 Delete /REBOOTOK "$INSTDIR\hatch.bat"
231 Delete /REBOOTOK "$INSTDIR\hatch.properties"
232 Delete /REBOOTOK "$INSTDIR\logging.properties"
233 ; blindly using /r isn't ideal but the extreme unlikelyhood of there being \lib or \extension folders under $PROGRAMFILES makes it low risk.
234 RmDir /r /REBOOTOK "$INSTDIR\extension"
235 RmDir /r /REBOOTOK "$INSTDIR\lib"
236 # Delete uninstaller last
237 Delete /REBOOTOK "$INSTDIR\Uninstall ${APPNAME}.exe"
239 # Remove installation directory
240 RmDir /REBOOTOK "$INSTDIR"
242 # Remove uninstaller info from registry
243 DeleteRegKey HKLM "SOFTWARE\${COMPANYNAME}\${APPNAME}"
244 DeleteRegKey HKLM "SOFTWARE\${COMPANYNAME}"
245 DeleteRegKey HKLM "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\${APPNAME}"
246 DeleteRegKey HKLM "SOFTWARE\Google\Chrome\NativeMessagingHosts\org.evergreen_ils.hatch"
247 DeleteRegKey HKLM "SOFTWARE\Google\Chrome\Extensions\${EXTENSIONID}"
249 DeleteRegKey HKLM "SOFTWARE\Wow6432Node\Google\Chrome\Extensions\${EXTENSIONID}"
253 MessageBox MB_YESNO "A reboot is required to finish the installation. Do you wish to reboot now?" /SD IDNO IDNO Done