]> git.evergreen-ils.org Git - Hatch.git/blob - installer/windows/hatch.nsi
LP1860187: Set .properties Permissions Appropriately
[Hatch.git] / installer / windows / hatch.nsi
1 ;-----------------------------------------------------------------------
2 ; NSIS Installation Script                                              ;
3 ; Kyle Huckins                                                          ;
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.              ;
7 ;                                                                       ;
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.                            ;
12 ;                                                                       ;
13 ;------------------------------------------------------------------------
14
15 ;==================
16 ; Basic Information
17 ;--------
18 ; Includes
19 !include "MUI2.nsh" ;This enables the use of ModernUI, and must go at the top
20 !include "x64.nsh"
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
24 !include StrRep.nsh
25 !include ReplaceInFile.nsh
26 ;---------------------------------------------------------------
27 ; Installer's filename
28 Outfile "${APPNAME} Installer.exe"
29 RequestExecutionLevel admin
30
31
32 ;-----------------
33 ; Titlebar Content
34 Name "${APPNAME}"
35
36 ;==================================
37 ; Page system
38 !insertmacro MUI_PAGE_WELCOME
39 !define MUI_PAGE_CUSTOMFUNCTION_PRE VersionChecker
40 !insertmacro MUI_PAGE_LICENSE "license.rtf" ;Loads licence.rtf to show license content
41 !insertmacro MUI_PAGE_DIRECTORY
42 !insertmacro MUI_PAGE_INSTFILES
43 !insertmacro MUI_PAGE_FINISH
44
45 !insertmacro MUI_LANGUAGE "English"
46 ;-------------------------------------
47 ; Code to verify if a user is an admin
48 !macro VerifyUserIsAdmin
49 UserInfo::GetAccountType
50 pop $0
51 ${If} $0 != "admin" ;Require admin rights
52     messageBox mb_iconstop "Administrator rights required!"
53     setErrorLevel 740 ;ERROR_ELEVATION_REQUIRED
54     quit
55 ${EndIf}
56 !macroend
57
58 ;---------------------------------------------------------------------
59 ; 1. Check for Java
60 ; 2. Read our current version and check if it's newer, older, or the same
61 ; LogicLib gives S>, S<, and S== for comparing strings.
62 !macro VersionCheck
63     ;JRE Check
64     ClearErrors
65     ${if} ${RunningX64}
66         SetRegView 64 ;So we can read the Registry of 64 bit devices
67     ${endif}
68     ReadRegStr $R0 HKLM "SOFTWARE\JavaSoft\Java Runtime Environment" "CurrentVersion"
69     ReadRegStr $R1 HKLM "SOFTWARE\JavaSoft\Java Runtime Environment\$R0" "JavaHome"
70     IfErrors 0  NoAbort
71         MessageBox MB_OK "Java not detected.  Setup will now exit."
72         Quit
73     NoAbort:
74         ${If} $R0 S< ${JRE_MIN_VERSION}
75             MessageBox MB_OK "You must update Java.  Setup will now exit."
76         ${EndIf}
77         ; Hatch Version Check
78         ReadRegStr $R2 HKCU "Software\${COMPANYNAME}\${APPNAME}" "Version"
79         ${If} $R2 = 0
80             Goto INSTALL ;As you were, citizen.
81         ${ElseIf} $R2 S== ${FULLVERSION} ;Same version is installed
82             MessageBox MB_OKCANCEL|MB_ICONSTOP "You already have this version of ${APPNAME} installed.  You must uninstall the currently installed version to continue." IDOK UNINSTALL IDCANCEL QUIT
83         ${ElseIf} $R2 S> ${FULLVERSION} ;Older version is installed
84             MessageBox MB_OKCANCEL|MB_ICONSTOP "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." IDOK UNINSTALL IDCANCEL QUIT
85         ${ElseIf} $R2 S< ${FULLVERSION} ;Newer version is installed
86             MessageBox MB_OKCANCEL|MB_ICONSTOP "You have a previous version of ${APPNAME} installed. You must uninstall the currently installed version to continue." IDOK UNINSTALL IDCANCEL QUIT
87         ${EndIf}
88         UNINSTALL:
89             ExecWait '"$INSTDIR\Uninstall ${APPNAME}.exe"_?=$INSTDIR'
90             Goto INSTALL
91         QUIT:
92             Quit
93         INSTALL:
94
95 !macroend
96
97 function .onInit
98     setShellVarContext all
99     !insertmacro VerifyUserIsAdmin
100 functionEnd
101 ;-----------------
102 ;Check our version
103 function VersionChecker
104     !insertmacro VersionCheck
105 functionEnd
106
107 ;--------------------------
108 ; Where our install files go
109 InstallDir "$PROGRAMFILES\${APPNAME}" ;This is where our variables come in.
110 ;----------------------------------------------
111
112 section "install"
113     ; Install directory files - keep these in the same directory
114     ; as the script before compiling.
115     SetOutPath $INSTDIR\ ;Sets output path to our InstallDir
116     File /r ..\..\lib
117     File /r ..\..\extension
118     File ..\..\hatch.bat
119     File ..\..\hatch.properties
120     File ..\..\logging.properties
121     
122     ; Set path variable in org.ils_evergreen.hatch.json to $INSTDIR\hatch.bat
123     ${StrRep} '$0' '$INSTDIR' '\' '\\'
124     !insertmacro _ReplaceInFile  "$INSTDIR\extension\host\org.evergreen_ils.hatch.json" "/path/to/hatch.sh" "$0\\hatch.bat"
125
126     ; Uninstaller
127     writeUninstaller "$INSTDIR\Uninstall ${APPNAME}.exe"
128
129     ; Registry info for Add/Remove Programs
130     WriteRegStr HKCU "Software\${COMPANYNAME}\${APPNAME}" "Install Path" $INSTDIR
131     WriteRegStr HKCU "Software\${COMPANYNAME}\${APPNAME}" "Version" "${FULLVERSION}"
132     WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\${APPNAME}" "DisplayName" "${COMPANYNAME} - ${APPNAME} - ${DESCRIPTION}"
133     WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\${APPNAME}" "UninstallString" "$\"$INSTDIR\Uninstall ${APPNAME}.exe$\""
134     WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\${APPNAME}" "QuietUninstallString" "$\"$INSTDIR\Uninstall ${APPNAME}.exe$\" /S"
135     WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\${APPNAME}" "InstallLocation" "$\"$INSTDIR$\""
136     WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\ ${APPNAME}" "DisplayIcon" "$\"$INSTDIR\logo.ico$\""
137     WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\${APPNAME}" "Publisher" "$\"${COMPANYNAME}$\""
138     WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\${APPNAME}" "HelpLink" "$\"${HELPURL}$\""
139     WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\${APPNAME}" "URLUpdateInfo" "$\"${UPDATEURL}$\""
140     WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\${APPNAME}" "URLInfoAbout" "$\"${ABOUTURL}$\""
141     WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\${APPNAME}" "DisplayVersion" "$\"${VERSIONMAJOR}.${VERSIONMINOR}.${VERSIONBUILD}$\""
142     WriteRegStr HKCU "Software\Google\Chrome\NativeMessagingHosts\org.evergreen_ils.hatch" "" "$INSTDIR\extension\host\org.evergreen_ils.hatch.json"
143     WriteRegDWORD HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\${APPNAME}" "VersionMajor" ${VERSIONMAJOR}
144     WriteRegDWORD HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\${APPNAME}" "VersionMinor" ${VERSIONMINOR}
145     # There is no option for modifying or repairing the install
146     WriteRegDWORD HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\${APPNAME}" "NoModify" 1
147     WriteRegDWORD HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\${APPNAME}" "NoRepair" 1
148     # Set the INSTALLSIZE constant (!defined at the top of this script) so Add/Remove Programs can accurately report the size
149     WriteRegDWORD HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\${APPNAME}" "EstimatedSize" ${INSTALLSIZE}
150
151     ;Uncommend when extension is on web store
152     ;${if} ${RunningX64}
153         ;WriteRegStr HKLM "Software\Wow6432Node\Google\Chrome\Extensions\${EXTENSIONID}" "update_url" "${EXTENSION_UPDATEURL}"
154     ;${EndIf}
155     ;WriteRegStr HKLM "Software\Google\Chrome\Extensions\${EXTENSIONID}" "update_url" "${EXTENSION_UPDATEURL}"
156 SectionEnd
157
158
159 #############################
160 # Uninstaller code
161
162 function un.onInit
163     SetShellVarContext all
164     
165     # Verify uninstaller
166     MessageBox MB_OKCANCEL "Permanently remove ${APPNAME}?" IDOK next
167         Abort
168     next:
169     !insertmacro VerifyUserIsAdmin
170 functionEnd
171
172 section "uninstall"    
173     # Remove the actual files
174     delete $INSTDIR\*.*
175     rmDir /r $INSTDIR\extension
176     rmDir /r $INSTDIR\lib
177     # Delete uninstaller last
178     delete "$INSTDIR\Uninstall ${APPNAME}.exe"
179     
180     # Remove installation directory
181     rmDir $INSTDIR\
182     
183     # Remove uninstaller info from registry
184     DeleteRegKey HKCU "Software\${COMPANYNAME}\${APPNAME}"
185     DeleteRegKey HKCU "Software\${COMPANYNAME}"
186     DeleteRegKey HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\${APPNAME}"
187     DeleteRegKey HKCU "Software\Google\Chrome\NativeMessagingHosts\org.evergreen_ils.hatch"
188     DeleteRegKey HKLM "Software\Google\Chrome\Extensions\${EXTENSIONID}"
189     ${if} ${RunningX64}
190         DeleteRegKey HKLM "Software\Wow6432Node\Google\Chrome\Extensions\${EXTENSIONID}"
191     ${EndIf}
192     
193 sectionEnd