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
64 setShellVarContext all
65 !insertmacro VerifyUserIsAdmin
71 function ValidateInstall
73 ReadRegStr $1 HKLM "SOFTWARE\${COMPANYNAME}\${APPNAME}" "Version"
75 ${If} $1 S== ${FULLVERSION} ;Same version is installed
76 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
77 ${ElseIf} $1 S> ${FULLVERSION} ;Older version is installed
78 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
79 ${ElseIf} $1 S< ${FULLVERSION} ;Newer version is installed
80 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
83 ReadRegStr $1 HKLM "SOFTWARE\${COMPANYNAME}\${APPNAME}" "Install Path"
84 ; 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.
85 CopyFiles /SILENT "$1\Uninstall ${APPNAME}.exe" "$TEMP\Uninstall ${APPNAME}.exe"
86 ExecWait '"$TEMP\Uninstall ${APPNAME}.exe" /S _?=$1'
87 Delete /REBOOTOK "$TEMP\Uninstall ${APPNAME}.exe"
95 ;--------------------------
96 ; Where our install files go
97 InstallDir "$PROGRAMFILES\${APPNAME}" ;This is where our variables come in.
98 ;----------------------------------------------
101 ; Install directory files - keep these in the same directory
102 ; as the script before compiling.
103 SetOutPath $INSTDIR\ ;Sets output path to our InstallDir
104 File /r ..\..\java-jdk-win
105 File /r ..\..\javafx-sdk-win
107 File /r ..\..\extension
109 File ..\..\hatch.properties
110 File ..\..\logging.properties
112 ; Set path variable in org.ils_evergreen.hatch.*.json to $INSTDIR\hatch.bat
113 ${StrRep} '$0' '$INSTDIR' '\' '\\'
114 !insertmacro _ReplaceInFile "$INSTDIR\extension\host\org.evergreen_ils.hatch.chrome.json" "/path/to/hatch.sh" "$0\\hatch.bat"
115 !insertmacro _ReplaceInFile "$INSTDIR\extension\host\org.evergreen_ils.hatch.firefox.json" "/path/to/hatch.sh" "$0\\hatch.bat"
116 AccessControl::EnableFileInheritance "$INSTDIR\extension\host\org.evergreen_ils.hatch.chrome.json"
117 AccessControl::EnableFileInheritance "$INSTDIR\extension\host\org.evergreen_ils.hatch.firefox.json"
119 ; Set logging to be in ProgramData
120 SetShellVarContext all
121 ${IfNot} ${FileExists} "$APPDATA\${APPNAME}"
122 CreateDirectory "$APPDATA\${APPNAME}"
124 !insertmacro _ReplaceInFile "$INSTDIR\hatch.properties" "#data.directory=/tmp/foo" "data.directory=C://ProgramData//${APPNAME}"
125 !insertmacro _ReplaceInFile "$INSTDIR\logging.properties" "%h/.evergreen/hatch.log" "C://ProgramData//${APPNAME}//hatch.log"
126 AccessControl::EnableFileInheritance "$INSTDIR\hatch.properties"
127 AccessControl::EnableFileInheritance "$INSTDIR\logging.properties"
129 ; Registry info for Add/Remove Programs
130 WriteRegStr HKLM "SOFTWARE\${COMPANYNAME}\${APPNAME}" "Logging Path" $APPDATA
131 SetShellVarContext current
132 WriteRegStr HKLM "SOFTWARE\${COMPANYNAME}\${APPNAME}" "Install Path" $INSTDIR
133 WriteRegStr HKLM "SOFTWARE\${COMPANYNAME}\${APPNAME}" "Version" "${FULLVERSION}"
134 WriteRegStr HKLM "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\${APPNAME}" "DisplayName" "${COMPANYNAME} - ${APPNAME} - ${DESCRIPTION}"
135 WriteRegStr HKLM "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\${APPNAME}" "UninstallString" "$INSTDIR\Uninstall ${APPNAME}.exe"
136 WriteRegStr HKLM "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\${APPNAME}" "QuietUninstallString" "$INSTDIR\Uninstall ${APPNAME}.exe /S"
137 WriteRegStr HKLM "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\${APPNAME}" "InstallLocation" "$INSTDIR"
138 WriteRegStr HKLM "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\${APPNAME}" "DisplayIcon" "$INSTDIR\logo.ico"
139 WriteRegStr HKLM "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\${APPNAME}" "Publisher" "${COMPANYNAME}"
140 StrCmp "${HELPURL}" "" +2
141 WriteRegStr HKLM "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\${APPNAME}" "HelpLink" "${HELPURL}"
142 StrCmp "${UPDATEURL}" "" +2
143 WriteRegStr HKLM "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\${APPNAME}" "URLUpdateInfo" "${UPDATEURL}"
144 StrCmp "${ABOUTURL}" "" +2
145 WriteRegStr HKLM "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\${APPNAME}" "URLInfoAbout" "${ABOUTURL}"
146 WriteRegStr HKLM "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\${APPNAME}" "DisplayVersion" "${VERSIONMAJOR}.${VERSIONMINOR}.${VERSIONBUILD}"
147 WriteRegDWORD HKLM "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\${APPNAME}" "VersionMajor" ${VERSIONMAJOR}
148 WriteRegDWORD HKLM "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\${APPNAME}" "VersionMinor" ${VERSIONMINOR}
149 # There is no option for modifying or repairing the install
150 WriteRegDWORD HKLM "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\${APPNAME}" "NoModify" 1
151 WriteRegDWORD HKLM "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\${APPNAME}" "NoRepair" 1
152 # Set the INSTALLSIZE constant (!defined at the top of this script) so Add/Remove Programs can accurately report the size
153 WriteRegDWORD HKLM "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\${APPNAME}" "EstimatedSize" ${INSTALLSIZE}
155 ; Connect Hatch to Chrome and install the Hatch extension from the Chrome Web Store
156 WriteRegStr HKLM "SOFTWARE\Google\Chrome\NativeMessagingHosts\org.evergreen_ils.hatch" "" "$INSTDIR\extension\host\org.evergreen_ils.hatch.chrome.json"
157 WriteRegStr HKLM "Software\Google\Chrome\Extensions\${EXTENSIONID}" "update_url" "${EXTENSION_UPDATEURL}"
159 ; Firefox won't check both the 32 and 64 bit views, so it's on us to put the key in the right place.
160 ; Firefox doesn't allow automatic installation of remote extensions either, so there's no (good) auto-install option here. :-/
161 ; A link should be added to the web client to simplify locating the FF extension. (Links to both would likely be a good practice.)
166 WriteRegStr HKLM "SOFTWARE\Mozilla\NativeMessagingHosts\org.evergreen_ils.hatch" "" "$INSTDIR\extension\host\org.evergreen_ils.hatch.firefox.json"
173 writeUninstaller "$INSTDIR\Uninstall ${APPNAME}.exe"
178 #############################
182 SetShellVarContext all
185 MessageBox MB_OKCANCEL "Permanently remove ${APPNAME}?" /SD IDOK IDOK next
188 !insertmacro VerifyUserIsAdmin
192 # Remove the data log directory
193 SetShellVarContext all
194 ${If} ${FileExists} "$APPDATA\${APPNAME}"
195 RmDir /r /REBOOTOK "$APPDATA\${APPNAME}"
197 SetShellVarContext current
199 # Remove the actual files
200 Delete /REBOOTOK "$INSTDIR\hatch.bat"
201 Delete /REBOOTOK "$INSTDIR\hatch.properties"
202 Delete /REBOOTOK "$INSTDIR\logging.properties"
203 ; blindly using /r isn't ideal but the extreme unlikelyhood of there being \lib or \extension folders under $PROGRAMFILES makes it low risk.
204 RmDir /r /REBOOTOK "$INSTDIR\extension"
205 RmDir /r /REBOOTOK "$INSTDIR\lib"
206 RmDir /r /REBOOTOK "$INSTDIR\java-jdk-win"
207 RmDir /r /REBOOTOK "$INSTDIR\javafx-sdk-win"
209 # Delete uninstaller last
210 Delete /REBOOTOK "$INSTDIR\Uninstall ${APPNAME}.exe"
212 # Remove installation directory
213 RmDir /REBOOTOK "$INSTDIR"
215 # Remove uninstaller info from registry
216 DeleteRegKey HKLM "SOFTWARE\${COMPANYNAME}\${APPNAME}"
217 DeleteRegKey HKLM "SOFTWARE\${COMPANYNAME}"
218 DeleteRegKey HKLM "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\${APPNAME}"
219 DeleteRegKey HKLM "SOFTWARE\Google\Chrome\NativeMessagingHosts\org.evergreen_ils.hatch"
220 DeleteRegKey HKLM "SOFTWARE\Google\Chrome\Extensions\${EXTENSIONID}"
226 DeleteRegKey HKLM "SOFTWARE\Mozilla\NativeMessagingHosts\org.evergreen_ils.hatch"
233 MessageBox MB_YESNO "A reboot is required to finish the installation. Do you wish to reboot now?" /SD IDNO IDNO Done