-
Notifications
You must be signed in to change notification settings - Fork 9
/
openmrs-upgrade-64bit.nsi
327 lines (282 loc) · 11.9 KB
/
openmrs-upgrade-64bit.nsi
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
;--------------------------------
;Defines
!include "MUI2.nsh"
!include "Registry.nsh"
!include "Sections.nsh"
Name "Uganda EMR"
!define JavaRegKey 'HKLM "Software\JavaSoft\Java Runtime Environment" ""'
!define MUI_ICON "software/favicon.ico"
!define MUI_UNICON "software/favicon.ico"
Var mysqlUserName
Var mysqlPassword
Var SMDir ;Start menu folder
Var errorsrc
;!define MUI_STARTMENUPAGE_DEFAULTFOLDER "MY Program" ;Default, name is used if not defined
!define MUI_HEADERIMAGE_BITMAP "software64\logo.bmp"
!define MUI_HEADERIMAGE_RIGHT
!define TOMCATDIR "C:\Program Files\UgandaEMR\UgandaEMRTomcat\"
RequestExecutionLevel admin
;--------------------------------
;Interface Settings
!define MUI_ABORTWARNING
;--------------------------------
;Pages
!insertmacro MUI_PAGE_LICENSE "includes\license.txt"
!insertmacro MUI_PAGE_COMPONENTS
!insertmacro MUI_PAGE_DIRECTORY
!insertmacro MUI_PAGE_STARTMENU 0 $SMDir
!insertmacro MUI_PAGE_INSTFILES
!insertmacro MUI_UNPAGE_CONFIRM
!insertmacro MUI_UNPAGE_INSTFILES
;--------------------------------
;Languages
!insertmacro MUI_LANGUAGE "English"
;--------------------------------
InstallDir "C:\Program Files\UgandaEMR" ;This line creates a default location for the installation. Note that C:\Program Files is a constant value provided by NSIS
DirText "OpenMrs will install in this directory"
!define instDirectory "C:\Program Files\UgandaEMR"
Var RestoreFilePath
OutFile "ugandaemr_upgrade_from_1.x_to_2.1.0_64bit.exe"
;-------------------------Splash Screen For installer--------------------------------
XPStyle on
Function .onInit
UserInfo::GetAccountType
pop $0
${If} $0 != "admin" ;Require admin rights on NT4+
MessageBox mb_iconstop "Administrator rights required!"
SetErrorLevel 740 ;ERROR_ELEVATION_REQUIRED
Quit
${EndIf}
# the plugins dir is automatically deleted when the installer exits
InitPluginsDir
File /oname=$PLUGINSDIR\splash.bmp "includes\splash.bmp"
advsplash::show 5000 600 400 -1 $PLUGINSDIR\splash
Pop $0 ; $0 has '1' if the user closed the splash screen early,
; '0' if everything closed normally, and '-1' if some error occurred.
FunctionEnd
;===========================================Installer Sections============================================
;Installing Java
Section /o 'Java Runtime' SecJava
SetOutPath '$TEMP'
SetOverwrite on
File 'software64\jdk-8u131.exe'
ExecWait '"$TEMP\jdk-8u131.exe"' $0
DetailPrint '..Java Runtime Setup exit code = $0'
Delete '$TEMP\jdk-8u131.exe'
; include for some of the windows messages defines
!include "winmessages.nsh"
; HKLM (all users) vs HKCU (current user) defines
!define env_hklm 'HKLM "SYSTEM\CurrentControlSet\Control\Session Manager\Environment"'
!define env_hkcu 'HKCU "Environment"'
; set variable
WriteRegStr ${env_hklm} JAVA_HOME "C:\Program Files\Java\jdk1.8.0_131"
WriteRegStr ${env_hklm} JRE_HOME "C:\Program Files\Java\jre1.8.0_131"
; make sure windows knows about the change
WriteRegStr ${env_hkcu} JAVA_HOME "C:\Program Files\Java\jdk1.8.0_131"
WriteRegStr ${env_hkcu} JRE_HOME "C:\Program Files\Java\jre1.8.0_131"
WriteRegStr ${env_hkcu} Path "%JAVA_HOME%\bin;"
WriteRegDWORD HKCU "SOFTWARE\JavaSoft\Java Update\Policy" 'EnableJavaUpdate' 0
SendMessage ${HWND_BROADCAST} ${WM_WININICHANGE} 0 "STR:Environment" /TIMEOUT=5000
SectionEnd
Section -createUpgradeFolder
CreateDirectory $DESKTOP\UgandaEMRUpgrade
SectionEnd
Section -databaseBackup
StrCpy $1 '"$DESKTOP\UgandaEMRUpgrade\openmrs.backup.upgrade.sql"'
FileOpen $4 "$DESKTOP\UgandaEMRUpgrade\backup.bat" w
FileWrite $4 "mysqldump openmrs -uopenmrs -popenmrs>$1"
FileClose $4
DetailPrint 'Starting to backup openmrs database'
nsExec::Exec '"$DESKTOP\UgandaEMRUpgrade\backup.bat"' $0
ExecWait '"$0" /C "$DESKTOP\UgandaEMRUpgrade\backup.bat"'
DetailPrint 'Database Backup Completed Backup file link $1'
SectionEnd
;Changing mysql max allowed packet
Section -databaseMYSQLCONFFILE
DetailPrint 'Stopping mysql'
nsExec::Exec 'net stop MySQL' $0
DetailPrint 'MYSQL Stopped $0'
SetOutPath "C:\Program Files\MySQL\MySQL Server 5.5"
File "includes\databases\default\my.ini"
DetailPrint 'starting mysql'
nsExec::Exec 'net start MySQL' $0
DetailPrint 'MYSQL Started $0'
SectionEnd
;Copying Scripts
Section -scripts
SetOutPath "C:\Program Files\UgandaEMR"
File /r "includes\scripts"
SectionEnd
Section -StartMenu
!insertmacro MUI_STARTMENU_WRITE_BEGIN 0 ;This macro sets $SMDir and skips to MUI_STARTMENU_WRITE_END if the "Don't create shortcuts" checkbox is checked...
CreateDirectory "$SMPrograms\$SMDir"
SetOutPath "$SMPrograms\$SMDir"
File "includes\shortcuts\Start UgandaEMR.lnk"
File "includes\shortcuts\Stop UgandaEMR.lnk"
File "includes\shortcuts\Backup UgandaEMR Database.lnk"
File "includes\shortcuts\Restore UgandaEMR Database.lnk"
File "includes\shortcuts\Upgrade UgandaEMR War File.lnk"
File "includes\shortcuts\Correct Database Path.lnk"
File "includes\shortcuts\Launch Tomcat Manager.lnk"
File "includes\shortcuts\uninstall.lnk"
File "includes\shortcuts\Access UgandaEMR.url"
File "includes\shortcuts\Start FingerPrint Scanner.lnk"
File "includes\shortcuts\Excecute Mysql Script.lnk"
File "includes\shortcuts\Clean UgandaEMR.lnk"
!insertmacro MUI_STARTMENU_WRITE_END
SectionEnd
!define /date MyTIMESTAMP "%Y-%m-%d-%H%M"
;===========================================Installer Sections============================================
Section -defaultProperties
DetailPrint 'Stopping Tomcat'
nsExec::Exec 'net stop UgandaEMRTomcat' $0
DetailPrint 'Tomcat Stopped $0'
CopyFiles "C:\Program Files\UgandaEMR\UgandaEMRTomcat\webapps\openmrs.war" "C:\Application Data\OpenMRS\warfile\${MyTIMESTAMP}\openmrs.war"
RMDir /r 'C:\Program Files\UgandaEMR\UgandaEMRTomcat\webapps\openmrs'
RMDir /r 'C:\Program Files\UgandaEMR\UgandaEMRTomcat\temp'
CreateDirectory 'C:\Program Files\UgandaEMR\UgandaEMRTomcat\temp'
RMDir /r 'C:\Program Files\UgandaEMR\UgandaEMRTomcat\work\Catalina\localhost'
RMDir /r 'C:\Application Data\OpenMRS\.openmrs-lib-cache'
RMDir /r 'C:\Application Data\OpenMRS\activemq-data'
RMDir /r 'C:\Application Data\OpenMRS\chartsearch'
RMDir /r 'C:\Application Data\OpenMRS\lucene'
Delete 'C:\Program Files\UgandaEMR\UgandaEMRTomcat\webapps\openmrs.war'
SectionEnd
;Installing Tomcat
Section -configTomcat
nsExec::Exec '"C:\Program Files\UgandaEMR\UgandaEMRTomcat\bin\UgandaEMRTomcat" //IS//UgandaEMRTomcat --Jvm="C:\Program Files\Java\jre1.8.0_131\bin\server\jvm.dll"'
SectionEnd
Section -defaultProperties32
RMDir /r 'C:\Windows\System32\config\systemprofile\Application Data\OpenMRS\.openmrs-lib-cache'
RMDir /r 'C:\Windows\System32\config\systemprofile\Application Data\OpenMRS\activemq-data'
RMDir /r 'C:\Windows\System32\config\systemprofile\Application Data\OpenMRS\chartsearch'
RMDir /r 'C:\Windows\System32\config\systemprofile\Application Data\OpenMRS\lucene'
CopyFiles "C:\Application Data\openmrs-runtime.properties" "C:\Windows\System32\config\systemprofile\Application Data\OpenMRS"
SectionEnd
;Restore database in UgandaEMR
Section -databaseRestore
nsExec::Exec 'C:\Program Files\MySQL\MySQL Server 5.5\bin\mysql -uopenmrs -popenmrs -e "drop database openmrs"'
nsExec::Exec 'C:\Program Files\MySQL\MySQL Server 5.5\bin\mysql -uopenmrs -popenmrs -e "CREATE database openmrs"'
importdbs:
DetailPrint "SQL file import"
ExecWait '"C:\Program Files\MySQL\MySQL Server 5.5\bin\mysql" --user=openmrs --password=openmrs --execute="source $DESKTOP\UgandaEMRUpgrade\openmrs.backup.upgrade.sql" openmrs' $2
StrCmp $2 1 0 endinst
StrCpy $errorsrc "File import error"
Goto abortinst
abortinst:
DetailPrint " "
DetailPrint "$\n An error occured ! $\n"
DetailPrint " $errorsrc "
DetailPrint " "
endinst:
SectionEnd
Section -defaultDatabase
DetailPrint "Running import"
StrCmp $createdb 1 importdbs
SetOutPath "$DESKTOP\"
File 'includes\databases\default\concept_dictonary_ref.sql'
DetailPrint '..Add default database exit code = $0'
importdbs:
DetailPrint "SQL file import"
ExecWait '"C:\Program Files\MySQL\MySQL Server 5.5\bin\mysql" --user=openmrs --password=openmrs --execute="source $DESKTOP\concept_dictonary_ref.sql" openmrs' $2
StrCmp $2 1 0 endinst
StrCpy $errorsrc "File import error"
Goto abortinst
abortinst:
DetailPrint " "
DetailPrint "$\n An error occured ! $\n"
DetailPrint " $errorsrc "
DetailPrint " "
endinst:
Delete '$DESKTOP\concept_dictonary_ref.sql'
SectionEnd
Section -patientFlagsFix
DetailPrint "Running import"
StrCmp $createdb 1 importdbs
SetOutPath "$DESKTOP\"
File 'includes\databases\default\drop_patientflags.sql'
DetailPrint '..Add default database exit code = $0'
importdbs:
DetailPrint "SQL file import"
ExecWait '"C:\Program Files\MySQL\MySQL Server 5.5\bin\mysql" --user=openmrs --password=openmrs --execute="source $DESKTOP\drop_patientflags.sql" openmrs' $2
StrCmp $2 1 0 endinst
StrCpy $errorsrc "File import error"
Goto abortinst
abortinst:
DetailPrint " "
DetailPrint "$\n An error occured ! $\n"
DetailPrint " $errorsrc "
DetailPrint " "
endinst:
Delete '$DESKTOP\drop_patientflags.sql'
SectionEnd
;fixing patient programs
Section -patientProgramFix
DetailPrint "Running import"
StrCmp $createdb 1 importdbs
SetOutPath "$DESKTOP\"
File 'includes\databases\default\fixpatientprogram.sql'
DetailPrint '..Add default database exit code = $0'
importdbs:
DetailPrint "SQL file import"
ExecWait '"C:\Program Files\MySQL\MySQL Server 5.5\bin\mysql" --user=openmrs --password=openmrs --execute="source $DESKTOP\fixpatientprogram.sql" openmrs' $2
StrCmp $2 1 0 endinst
StrCpy $errorsrc "File import error"
Goto abortinst
abortinst:
DetailPrint " "
DetailPrint "$\n An error occured ! $\n"
DetailPrint " $errorsrc "
DetailPrint " "
endinst:
Delete '$DESKTOP\fixpatientprogram.sql'
SectionEnd
;fixing reports
Section -reportsFix
DetailPrint "Running import"
StrCmp $createdb 1 importdbs
SetOutPath "$DESKTOP\"
File 'includes\databases\default\reports.sql'
DetailPrint '..Add default database exit code = $0'
importdbs:
DetailPrint "SQL file import"
ExecWait '"C:\Program Files\MySQL\MySQL Server 5.5\bin\mysql" --user=openmrs --password=openmrs --execute="source $DESKTOP\reports.sql" openmrs' $2
StrCmp $2 1 0 endinst
StrCpy $errorsrc "File import error"
Goto abortinst
abortinst:
DetailPrint " "
DetailPrint "$\n An error occured ! $\n"
DetailPrint " $errorsrc "
DetailPrint " "
endinst:
Delete '$DESKTOP\reports.sql'
SectionEnd
;Delete Upgrade Directorry
Section -scripts
RMDir /r '$DESKTOP\UgandaEMRUpgrade'
SectionEnd
;Installing Firefox
Section 'Firefox' SecBrowser
SectionIn RO
SetOutPath '$TEMP'
SetOverwrite on
File 'software64\firefox67.exe'
ExecWait '"$TEMP\firefox67.exe"' $0
DetailPrint '..Fire Fox Setup exit code = $0'
Delete '$TEMP\firefox67.exe'
SectionEnd
;Restore database in UgandaEMR
Section 'Upgrade War File to 2.1.0' SecUpgradeWarFile
SectionIn RO
SetOutPath "C:\Program Files\UgandaEMR\UgandaEMRTomcat\webapps"
File "includes\warfile\openmrs.war"
DetailPrint 'Starting Tomcat $0'
nsExec::Exec 'net start UgandaEMRTomcat'
DetailPrint 'Tomcat Started $0'
!define MB_OK 0x00000000
!define MB_ICONINFORMATION 0x00000040
System::Call 'USER32::MessageBox(i $hwndparent, t "UgandaEMR war file was upgraded go to browser to proceed ", t "Upgrade Completed", i ${MB_OK}|${MB_ICONINFORMATION})i'
Quit
SectionEnd
;--------------------------------