]> git.sur5r.net Git - bacula/bacula/blob - bacula/src/win32/win64_installer/winbacula.nsi
Fix class member shadowing.
[bacula/bacula] / bacula / src / win32 / win64_installer / winbacula.nsi
1 ; winbacula.nsi
2 ;
3 ; Began as a version written by Michel Meyers (michel@tcnnet.dyndns.org)
4 ;
5 ; Adapted by Kern Sibbald for native Win32 Bacula
6 ;    added a number of elements from Christopher Hull's installer
7 ;
8 ; D. Scott Barninger Nov 13 2004
9 ; added configuration editing for bconsole.conf and bwx-console.conf
10 ; better explanation in dialog boxes for editing config files
11 ; added Start Menu items
12 ; fix uninstall of config files to do all not just bacula-fd.conf
13 ;
14 ; D. Scott Barninger Dec 05 2004
15 ; added specification of default permissions for bacula-fd.conf
16 ;   - thanks to Jamie Ffolliott for pointing me at cacls
17 ; added removal of working-dir files if user selects to remove config
18 ; uninstall is now 100% clean
19 ;
20 ; D. Scott Barninger Apr 17 2005
21 ; 1.36.3 release docs update
22 ; add pdf manual and menu shortcut
23 ;
24 ; Robert Nelson May 15 2006
25 ; Added server installs and implemented Microsoft install locations
26 ; Use LogicLib.nsh
27 ; Added Bacula-SD and Bacula-DIR
28 ; Replaced ParameterGiven with standard GetOptions
29 ;
30 ; Kern Sibbald October 2008
31 ; Remove server installs
32 ; Install into single bacula directory
33 ;  (i.e. undo a large part of what Robert Nelson did)
34 ;
35 ; Eric Bollengier March 2009
36 ; Updated to handle Win64 installation
37 ;
38 ; Kern Sibbald April 2009
39 ; Correct some Win64 install problems
40 ; It is mind boggling how many lines of this insane scripting language
41 ;   have been written with absolutely no comments
42 ;
43 ; Command line options:
44 ;
45 ; /service    - 
46 ; /start
47 ;
48 ; netsh firewall add portopening protocol=tcp port=9102 name="Bacula-FD"
49
50
51 !define PRODUCT "Bacula"
52
53 ;
54 ; Include the Modern UI
55 ;
56
57 !include "MUI.nsh"
58 !include "LogicLib.nsh"
59 !include "FileFunc.nsh"
60 !include "Sections.nsh"
61 !include "StrFunc.nsh"
62 !include "WinMessages.nsh"
63 ;
64 ; Basics
65 ;
66 Name "Bacula"
67 OutFile "${OUT_DIR}\bacula-win${WINVER}-${VERSION}.exe"
68 SetCompressor lzma
69
70 InstallDir "C:\Program Files\Bacula"
71 InstallDirRegKey HKLM "Software\Bacula" "InstallLocation"
72
73 InstType "Client"
74 ;InstType "Server"
75 ;InstType "Full"
76
77 !insertmacro GetParent
78
79 ${StrCase}
80 ${StrRep}
81 ${StrTok}
82 ${StrTrimNewLines}
83
84 ;
85 ; Pull in pages
86 ;
87
88 !define      MUI_COMPONENTSPAGE_SMALLDESC
89
90 !define      MUI_HEADERIMAGE
91 !define      MUI_BGCOLOR                739AB9
92 !define      MUI_HEADERIMAGE_BITMAP     "bacula-logo.bmp"
93
94 !InsertMacro MUI_PAGE_WELCOME
95 !InsertMacro MUI_PAGE_LICENSE "..\..\..\LICENSE"
96 Page custom EnterInstallType
97 !define      MUI_PAGE_CUSTOMFUNCTION_SHOW PageComponentsShow
98 !InsertMacro MUI_PAGE_COMPONENTS
99 !define      MUI_PAGE_CUSTOMFUNCTION_PRE PageDirectoryPre
100 !InsertMacro MUI_PAGE_DIRECTORY
101 Page custom EnterConfigPage1 LeaveConfigPage1
102 Page custom EnterConfigPage2 LeaveConfigPage2
103 !Define      MUI_PAGE_CUSTOMFUNCTION_LEAVE LeaveInstallPage
104 !InsertMacro MUI_PAGE_INSTFILES
105 Page custom EnterWriteTemplates
106 !Define      MUI_FINISHPAGE_SHOWREADME $INSTDIR\Readme.txt
107 !InsertMacro MUI_PAGE_FINISH
108
109 !InsertMacro MUI_UNPAGE_WELCOME
110 !InsertMacro MUI_UNPAGE_CONFIRM
111 !InsertMacro MUI_UNPAGE_INSTFILES
112 !InsertMacro MUI_UNPAGE_FINISH
113
114 !define      MUI_ABORTWARNING
115
116 !InsertMacro MUI_LANGUAGE "English"
117
118 !InsertMacro GetParameters
119 !InsertMacro GetOptions
120
121 DirText "Setup will install Bacula ${VERSION} to the directory specified below. To install in a different folder, click Browse and select another folder."
122
123 !InsertMacro MUI_RESERVEFILE_INSTALLOPTIONS
124 ;
125 ; Global Variables
126 ;
127 Var OptService
128 Var OptStart
129 Var OptSilent
130
131 Var CommonFilesDone
132
133 Var OsIsNT
134
135 Var HostName
136
137 Var ConfigClientName
138 Var ConfigClientPort
139 Var ConfigClientMaxJobs
140 Var ConfigClientPassword
141 Var ConfigClientInstallService
142 Var ConfigClientStartService
143
144 Var ConfigStorageName
145 Var ConfigStoragePort
146 Var ConfigStorageMaxJobs
147 Var ConfigStoragePassword
148 Var ConfigStorageInstallService
149 Var ConfigStorageStartService
150
151 Var ConfigDirectorName
152 Var ConfigDirectorPort
153 Var ConfigDirectorMaxJobs
154 Var ConfigDirectorPassword
155 Var ConfigDirectorAddress
156 Var ConfigDirectorMailServer
157 Var ConfigDirectorMailAddress
158 Var ConfigDirectorDB
159 Var ConfigDirectorInstallService
160 Var ConfigDirectorStartService
161
162 Var ConfigMonitorName
163 Var ConfigMonitorPassword
164
165 Var LocalDirectorPassword
166 Var LocalHostAddress
167
168 Var MySQLPath
169 Var MySQLVersion
170 Var PostgreSQLPath
171 Var PostgreSQLVersion
172
173 Var AutomaticInstall
174 Var InstallType
175
176 !define NewInstall      0
177 !define UpgradeInstall  1
178 !define MigrateInstall  2
179
180 Var OldInstallDir
181 Var PreviousComponents
182 Var NewComponents
183
184 ; Bit 0 = File Service
185 ;     1 = Storage Service
186 ;     2 = Director Service
187 ;     3 = Command Console
188 ;     4 = Bat Console
189 ;     5 = wxWidgits Console
190 ;     6 = Documentation (PDF)
191 ;     7 = Documentation (HTML)
192 ;    10 = Tray Monitor
193
194 !define ComponentFile                   1
195 !define ComponentStorage                2
196 !define ComponentDirector               4
197 !define ComponentTextConsole            8
198 !define ComponentBatConsole             16
199 !define ComponentGUIConsole             32
200 !define ComponentPDFDocs                64
201 !define ComponentHTMLDocs               128
202 !define ComponentTrayMonitor            1024
203
204 !define ComponentsRequiringUserConfig           63
205 !define ComponentsFileAndStorage                3
206 !define ComponentsFileAndStorageAndDirector     7
207 !define ComponentsDirectorAndTextGuiConsoles    60
208 !define ComponentsTextAndGuiConsoles            56
209
210 Var HDLG
211 Var HCTL
212
213 Function .onInit
214   Push $R0
215   Push $R1
216
217   ; Process Command Line Options
218   StrCpy $OptService 1
219   StrCpy $OptStart 1
220   StrCpy $OptSilent 0
221   StrCpy $CommonFilesDone 0
222   StrCpy $OsIsNT 0
223   StrCpy $AutomaticInstall 0
224   StrCpy $InstallType ${NewInstall}
225   StrCpy $OldInstallDir ""
226   StrCpy $PreviousComponents 0
227   StrCpy $NewComponents 0
228   StrCpy $MySQLPath ""
229   StrCpy $MySQLVersion ""
230   StrCpy $PostgreSQLPath ""
231   StrCpy $PostgreSQLVersion ""
232   StrCpy $LocalDirectorPassword ""
233
234   ${GetParameters} $R0
235
236   ClearErrors
237   ${GetOptions} $R0 "/noservice" $R1
238   IfErrors +2
239     StrCpy $OptService 0
240
241   ClearErrors
242   ${GetOptions} $R0 "/nostart" $R1
243   IfErrors +2
244     StrCpy $OptStart 0
245
246   IfSilent 0 +2
247     StrCpy $OptSilent 1
248
249   ReadRegStr $R0 HKLM "SOFTWARE\Microsoft\Windows NT\CurrentVersion" CurrentVersion
250   ${If} $R0 != ""
251     StrCpy $OsIsNT 1
252   ${EndIf}
253
254   Call GetComputerName
255   Pop $HostName
256
257   Call GetHostName
258   Pop $LocalHostAddress
259
260   Call GetUserName
261
262   ; Configuration Defaults
263
264   StrCpy $ConfigClientName               "$HostName-fd"
265   StrCpy $ConfigClientPort               9102
266   StrCpy $ConfigClientMaxJobs            10
267   ;StrCpy $ConfigClientPassword
268   StrCpy $ConfigClientInstallService     "$OptService"
269   StrCpy $ConfigClientStartService       "$OptStart"
270
271   StrCpy $ConfigDirectorPort             9101
272
273   StrCpy $ConfigMonitorName              "$HostName-mon"
274   ;StrCpy $ConfigMonitorPassword
275
276 ; PLUGINSDIR refers to temporary helper programs and not Bacula plugins!
277   InitPluginsDir
278   File "/oname=$PLUGINSDIR\openssl.exe"  "${SRC_DIR}\openssl.exe"
279   File "/oname=$PLUGINSDIR\ssleay32-0.9.8.dll" "${SRC_DIR}\ssleay32-0.9.8.dll"
280   File "/oname=$PLUGINSDIR\cryptoeay32-0.9.8.dll" "${SRC_DIR}\cryptoeay32-0.9.8.dll"        
281 ;  File "/oname=$PLUGINSDIR\libeay32.dll" "${SRC_DIR}\libeay32.dll"
282 ;  File "/oname=$PLUGINSDIR\ssleay32.dll" "${SRC_DIR}\ssleay32.dll"
283   File "/oname=$PLUGINSDIR\sed.exe"      "${SRC_DIR}\sed.exe"
284
285   !InsertMacro MUI_INSTALLOPTIONS_EXTRACT "InstallType.ini"
286   !InsertMacro MUI_INSTALLOPTIONS_EXTRACT "WriteTemplates.ini"
287
288   SetPluginUnload alwaysoff
289
290 ; Set client password
291   nsExec::Exec '"$PLUGINSDIR\openssl.exe" rand -base64 -out $PLUGINSDIR\pw.txt 33'
292   pop $R0
293   ${If} $R0 = 0
294    FileOpen $R1 "$PLUGINSDIR\pw.txt" r
295    IfErrors +4
296      FileRead $R1 $R0
297      ${StrTrimNewLines} $ConfigClientPassword $R0
298      FileClose $R1
299   ${EndIf}
300
301   SetPluginUnload manual
302
303 ; Set monitor password
304   nsExec::Exec '"$PLUGINSDIR\openssl.exe" rand -base64 -out $PLUGINSDIR\pw.txt 33'
305   pop $R0
306   ${If} $R0 = 0
307    FileOpen $R1 "$PLUGINSDIR\pw.txt" r
308    IfErrors +4
309      FileRead $R1 $R0
310      ${StrTrimNewLines} $ConfigMonitorPassword $R0
311      FileClose $R1
312   ${EndIf}
313
314   Pop $R1
315   Pop $R0
316 FunctionEnd
317
318 Function .onSelChange
319   Call UpdateComponentUI
320 FunctionEnd
321
322 Function InstallCommonFiles
323   ${If} $CommonFilesDone = 0
324     SetOutPath "$INSTDIR"
325     File "Readme.txt"
326
327     SetOutPath "$INSTDIR"
328 !if "${BUILD_TOOLS}" == "MinGW32"
329     File "${SRC_DIR}\mingwm10.dll"
330     File "${SRC_DIR}\pthreadGCE.dll"
331     File "${SRC_DIR}\zlib1.dll"
332     File "${SRC_DIR}\ssleay32.dll"
333     File "${SRC_DIR}\libeay32.dll"
334 !endif
335 !if "${BUILD_TOOLS}" == "MinGW64"
336     File "${SRC_DIR}\pthreadGCE.dll"
337     File "${SRC_DIR}\cryptoeay32-0.9.8.dll"
338     File "${SRC_DIR}\ssleay32-0.9.8.dll"
339     File "${SRC_DIR}\zlib1.dll"
340 !endif
341     File "${SRC_DIR}\bacula.dll"
342     File "/oname=$INSTDIR\openssl.cnf" "${SRC_DIR}\openssl.cnf"
343     File "${SRC_DIR}\openssl.exe"
344     File "${SRC_DIR}\bsleep.exe"
345     File "${SRC_DIR}\bsmtp.exe"
346     File "${SRC_DIR}\expr64.exe"
347     File "${SRC_DIR}\snooze.exe"
348
349     CreateShortCut "$SMPROGRAMS\Bacula\Documentation\View Readme.lnk" "write.exe" '"$INSTDIR\Readme.txt"'
350
351     StrCpy $CommonFilesDone 1
352   ${EndIf}
353 FunctionEnd
354
355 Section "-Initialize"
356
357   WriteRegStr   HKLM Software\Bacula InstallLocation "$INSTDIR"
358
359   Call GetSelectedComponents
360   Pop $R2
361   WriteRegDWORD HKLM Software\Bacula Components $R2
362
363   ; remove start menu items
364   SetShellVarContext all
365
366   Delete /REBOOTOK "$SMPROGRAMS\Bacula\Configuration\*"
367   Delete /REBOOTOK "$SMPROGRAMS\Bacula\Documentation\*"
368   Delete /REBOOTOK "$SMPROGRAMS\Bacula\*"
369   RMDir "$SMPROGRAMS\Bacula\Configuration"
370   RMDir "$SMPROGRAMS\Bacula\Documentation"
371   RMDir "$SMPROGRAMS\Bacula"
372   CreateDirectory "$SMPROGRAMS\Bacula"
373   CreateDirectory "$SMPROGRAMS\Bacula\Configuration"
374   CreateDirectory "$SMPROGRAMS\Bacula\Documentation"
375
376   CreateDirectory "$INSTDIR"
377   CreateDirectory "$INSTDIR\working"
378
379   SetOutPath "$INSTDIR"
380   File "..\..\..\LICENSE"
381   Delete /REBOOTOK "$INSTDIR\License.txt"
382
383 ; Output a series of SED commands to configure the .conf file(s)
384   FileOpen $R1 $PLUGINSDIR\config.sed w
385   FileWrite $R1 "s;@VERSION@;${VERSION};g$\r$\n"
386   FileWrite $R1 "s;@DATE@;${__DATE__};g$\r$\n"
387   FileWrite $R1 "s;@DISTNAME@;Windows;g$\r$\n"
388
389   StrCpy $R2 ${BUILD_TOOLS}
390
391   Call GetHostName
392   Exch $R3
393   Pop $R3
394
395   FileWrite $R1 "s;@DISTVER@;$R2;g$\r$\n"
396
397   ${StrRep} $R2 "$INSTDIR\working" "\" "\\\\"
398   FileWrite $R1 's;@working_dir@;$R2;g$\r$\n'
399   ${StrRep} $R2 "$INSTDIR\working" "\" "\\"
400   FileWrite $R1 's;@working_dir_cmd@;$R2;g$\r$\n'
401
402   ${StrRep} $R2 "$INSTDIR" "\" "\\\\"
403   FileWrite $R1 's;@bin_dir@;$R2;g$\r$\n'
404   ${StrRep} $R2 "$INSTDIR" "\" "\\"
405   FileWrite $R1 's;@bin_dir_cmd@;$R2;g$\r$\n'
406
407   ${StrRep} $R2 "$INSTDIR\plugins" "\" "\\\\"
408   FileWrite $R1 's;@fdplugins_dir@;$R2;g$\r$\n'
409
410   ${StrRep} $R2 "$INSTDIR" "\" "/"
411   FileWrite $R1 "s;@BUILD_DIR@;$R2;g$\r$\n"
412
413   FileWrite $R1 "s;@client_address@;$LocalHostAddress;g$\r$\n"
414
415   ${If} "$ConfigClientName" != ""
416     FileWrite $R1 "s;@client_name@;$ConfigClientName;g$\r$\n"
417   ${EndIf}
418   ${If} "$ConfigClientPort" != ""
419     FileWrite $R1 "s;@client_port@;$ConfigClientPort;g$\r$\n"
420   ${EndIf}
421   ${If} "$ConfigClientMaxJobs" != ""
422     FileWrite $R1 "s;@client_maxjobs@;$ConfigClientMaxJobs;g$\r$\n"
423   ${EndIf}
424   ${If} "$ConfigClientPassword" != ""
425     FileWrite $R1 "s;@client_password@;$ConfigClientPassword;g$\r$\n"
426   ${EndIf}
427   ${If} "$ConfigDirectorName" != ""
428     FileWrite $R1 "s;@director_name@;$ConfigDirectorName;g$\r$\n"
429   ${EndIf}
430   ${If} "$ConfigDirectorPort" != ""
431     FileWrite $R1 "s;@director_port@;$ConfigDirectorPort;g$\r$\n"
432   ${EndIf}
433   ${If} "$ConfigDirectorPassword" != ""
434     FileWrite $R1 "s;@director_password@;$ConfigDirectorPassword;g$\r$\n"
435   ${EndIf}
436   ${If} "$ConfigDirectorAddress" != ""
437     FileWrite $R1 "s;@director_address@;$ConfigDirectorAddress;g$\r$\n"
438   ${EndIf}
439   ${If} "$ConfigMonitorName" != ""
440     FileWrite $R1 "s;@monitor_name@;$ConfigMonitorName;g$\r$\n"
441   ${EndIf}
442   ${If} "$ConfigMonitorPassword" != ""
443     FileWrite $R1 "s;@monitor_password@;$ConfigMonitorPassword;g$\r$\n"
444   ${EndIf}
445
446   FileClose $R1
447
448   ${If} ${FileExists} "$OldInstallDir\bacula-fd.exe"
449     nsExec::ExecToLog '"$OldInstallDir\bacula-fd.exe" /kill'     ; Shutdown any bacula that could be running
450     Sleep 3000
451     nsExec::ExecToLog '"$OldInstallDir\bacula-fd.exe" /remove'   ; Remove existing service
452   ${EndIf}
453
454 SectionEnd
455
456 SectionGroup "Client" SecGroupClient
457
458 Section "File Service" SecFileDaemon
459   SectionIn 1 2 3
460
461   SetOutPath "$INSTDIR\plugins"
462   File "${SRC_DIR}\exchange-fd.dll"
463
464   SetOutPath "$INSTDIR"
465
466   File "${SRC_DIR}\bacula-fd.exe"
467
468   File "/oname=$PLUGINSDIR\bacula-fd.conf" "bacula-fd.conf.in"
469
470   StrCpy $0 "$INSTDIR"
471   StrCpy $1 bacula-fd.conf
472   Call ConfigEditAndCopy
473
474   StrCpy $0 bacula-fd
475   StrCpy $1 "File Service"
476   StrCpy $2 $ConfigClientInstallService
477   StrCpy $3 $ConfigClientStartService
478
479   Call InstallDaemon
480
481   CreateShortCut "$SMPROGRAMS\Bacula\Configuration\Edit Client Configuration.lnk" "write.exe" '"$INSTDIR\bacula-fd.conf"'
482 SectionEnd
483
484 SectionGroupEnd
485
486 SectionGroup "Consoles" SecGroupConsoles
487
488 Section "Command Console" SecConsole
489   SectionIn 1 2 3
490
491   SetOutPath "$INSTDIR"
492
493   File "${SRC_DIR}\bconsole.exe"
494   Call InstallCommonFiles
495
496   File "/oname=$PLUGINSDIR\bconsole.conf" "bconsole.conf.in"
497   StrCpy $0 "$INSTDIR"
498   StrCpy $1 bconsole.conf
499   Call ConfigEditAndCopy
500
501   CreateShortCut "$SMPROGRAMS\Bacula\bconsole.lnk" "$INSTDIR\bconsole.exe" '-c "$INSTDIR\bconsole.conf"' "$INSTDIR\bconsole.exe" 0
502   CreateShortCut "$SMPROGRAMS\Bacula\Configuration\Edit Command Console Configuration.lnk" "write.exe" '"$INSTDIR\bconsole.conf"'
503
504 SectionEnd
505
506 Section "Bat Console" SecBatConsole
507   SectionIn 1 2 3
508
509   SetOutPath "$INSTDIR\bin32"
510
511   Call InstallCommonFiles
512   File "${SRC_DIR}\QtCore4.dll"
513   File "${SRC_DIR}\QtGui4.dll"
514   File "${SRC_DIR}\libgcc_s_dw2-1.dll"
515   File "${SRC_DIR}\mingwm10.dll"
516   File "${SRC_DIR}\ssleay32.dll"
517   File "${SRC_DIR}\libeay32.dll"
518   File "${SRC_DIR}\bat.exe"
519   File "/oname=$INSTDIR\bin32\bacula.dll" "${SRC_DIR}\bacula32.dll"
520   File "/oname=$INSTDIR\bin32\pthreadGCE.dll" "${SRC_DIR}\pthreadGCE32.dll"
521   File "/oname=$INSTDIR\bin32\zlib1.dll" "${SRC_DIR}\zlib132.dll"
522
523   File "/oname=$PLUGINSDIR\bat.conf" "bat.conf.in"
524   StrCpy $0 "$INSTDIR\bin32"
525   StrCpy $1 bat.conf
526   Call ConfigEditAndCopy
527
528   SetOutPath "$INSTDIR\help"
529   File "${SRC_DIR}\help\*"
530   SetOutPath "$INSTDIR"
531
532
533   ; Create Start Menu entry
534   CreateShortCut "$SMPROGRAMS\Bacula\Bat.lnk" "$INSTDIR\bin32\bat.exe" '-c "$INSTDIR\bin32\bat.conf"' "$INSTDIR\bin32\bat.exe" 0
535   CreateShortCut "$SMPROGRAMS\Bacula\Configuration\Edit Bat Configuration.lnk" "write.exe" '"$INSTDIR\bin32\bat.conf"'
536   SetOutPath "$INSTDIR"
537 SectionEnd
538
539 Section "Tray Monitor" SecTrayMonitor
540   SectionIn 1 2 3
541
542   SetOutPath "$INSTDIR\bin32"
543
544   Call InstallCommonFiles
545   File "${SRC_DIR}\QtCore4.dll"
546   File "${SRC_DIR}\QtGui4.dll"
547   File "${SRC_DIR}\libgcc_s_dw2-1.dll"
548   File "${SRC_DIR}\mingwm10.dll"
549   File "${SRC_DIR}\ssleay32.dll"
550   File "${SRC_DIR}\libeay32.dll"
551   File "${SRC_DIR}\bacula-tray-monitor.exe"
552   File "/oname=$INSTDIR\bin32\bacula.dll" "${SRC_DIR}\bacula32.dll"
553   File "/oname=$INSTDIR\bin32\pthreadGCE.dll" "${SRC_DIR}\pthreadGCE32.dll"
554   File "/oname=$INSTDIR\bin32\zlib1.dll" "${SRC_DIR}\zlib132.dll"
555
556   File "/oname=$PLUGINSDIR\tray-monitor.conf" "tray-monitor.conf.in"
557   StrCpy $0 "$INSTDIR\bin32"
558   StrCpy $1 tray-monitor.conf
559   Call ConfigEditAndCopy
560
561   ; Create Start Menu entry
562   CreateShortCut "$SMPROGRAMS\Bacula\TrayMonitor.lnk" "$INSTDIR\bin32\bacula-tray-monitor.exe" '-c "$INSTDIR\bin32\tray-monitor.conf"' "$INSTDIR\bin32\bacula-tray-monitor.exe" 0
563   CreateShortCut "$SMPROGRAMS\Bacula\Configuration\Edit Tray Monitor Configuration.lnk" "write.exe" '"$INSTDIR\bin32\tray-monitor.conf"'
564   SetOutPath "$INSTDIR"
565
566 SectionEnd
567
568 ; Deleted because wxconsole is deprecated
569 ;Section "Graphical Console" SecWxConsole
570 ;  SectionIn 1 2 3
571   
572 ;  SetOutPath "$INSTDIR"
573 ;
574 ;SectionEnd
575
576 SectionGroupEnd
577
578
579 Section "-Finish"
580   Push $R0
581
582   ${If} $OsIsNT = 1
583 ;   nsExec::ExecToLog 'cmd.exe /C echo Y|cacls "$INSTDIR" /T /G SYSTEM:F Administrators:F'
584   ${EndIf}
585
586   ; Write the uninstall keys for Windows & create Start Menu entry
587   WriteRegStr   HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\Bacula" "DisplayName" "Bacula"
588   WriteRegStr   HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\Bacula" "InstallLocation" "$INSTDIR"
589   WriteRegStr   HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\Bacula" "DisplayVersion" "${VERSION}"
590   ${StrTok} $R0 "${VERSION}" "." 0 0
591   WriteRegDWORD HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\Bacula" "VersionMajor" $R0
592   ${StrTok} $R0 "${VERSION}" "." 1 0
593   WriteRegDWORD HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\Bacula" "VersionMinor" $R0
594   WriteRegDWORD HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\Bacula" "NoModify" 1
595   WriteRegDWORD HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\Bacula" "NoRepair" 1
596   WriteRegStr   HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\Bacula" "URLUpdateInfo" "http://www.bacula.org"
597   WriteRegStr   HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\Bacula" "URLInfoAbout" "http://www.bacula.org"
598   WriteRegStr   HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\Bacula" "HelpLink" "http://www.bacula.org?page=support"
599   WriteRegStr   HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\Bacula" "UninstallString" '"$INSTDIR\uninstall.exe"'
600   WriteUninstaller "$INSTDIR\Uninstall.exe"
601   CreateShortCut "$SMPROGRAMS\Bacula\Uninstall Bacula.lnk" "$INSTDIR\Uninstall.exe" "" "$INSTDIR\Uninstall.exe" 0
602   Pop $R0
603 SectionEnd
604
605 ; Extra Page descriptions
606
607 LangString DESC_SecFileDaemon ${LANG_ENGLISH} "Install Bacula File Daemon on this system."
608 LangString DESC_SecConsole ${LANG_ENGLISH} "Install command console program on this system."
609 LangString DESC_SecBatConsole ${LANG_ENGLISH} "Install Bat graphical console program on this system."
610 LangString DESC_SecTrayMonitor ${LANG_ENGLISH} "Install Tray Monitor graphical program on this system."
611
612 LangString TITLE_ConfigPage1 ${LANG_ENGLISH} "Configuration"
613 LangString SUBTITLE_ConfigPage1 ${LANG_ENGLISH} "Set installation configuration."
614
615 LangString TITLE_ConfigPage2 ${LANG_ENGLISH} "Configuration (continued)"
616 LangString SUBTITLE_ConfigPage2 ${LANG_ENGLISH} "Set installation configuration."
617
618 LangString TITLE_InstallType ${LANG_ENGLISH} "Installation Type"
619 LangString SUBTITLE_InstallType ${LANG_ENGLISH} "Choose installation type."
620
621 LangString TITLE_WriteTemplates ${LANG_ENGLISH} "Create Templates"
622 LangString SUBTITLE_WriteTemplates ${LANG_ENGLISH} "Create a resource template for inclusion in the Director's configuration file."
623
624 !InsertMacro MUI_FUNCTION_DESCRIPTION_BEGIN
625   !InsertMacro MUI_DESCRIPTION_TEXT ${SecFileDaemon} $(DESC_SecFileDaemon)
626   !InsertMacro MUI_DESCRIPTION_TEXT ${SecConsole} $(DESC_SecConsole)
627   !InsertMacro MUI_DESCRIPTION_TEXT ${SecBatConsole} $(DESC_SecBatConsole)
628   !InsertMacro MUI_DESCRIPTION_TEXT ${SecTrayMonitor} $(DESC_SecTrayMonitor)
629 !InsertMacro MUI_FUNCTION_DESCRIPTION_END
630
631 ; Uninstall section
632
633 UninstallText "This will uninstall Bacula. Click Uninstall to continue."
634
635 Section "Uninstall"
636   ; Shutdown any baculum that could be running
637   nsExec::ExecToLog '"$INSTDIR\bacula-fd.exe" /kill'
638   Sleep 3000
639
640 ; ReadRegDWORD $R0 HKLM "Software\Bacula" "Service_Bacula-fd"
641   ; Remove bacula service
642   nsExec::ExecToLog '"$INSTDIR\bacula-fd.exe" /remove'
643   nsExec::ExecToLog '"$INSTDIR\plugins\exchange-fd.dll" /remove'
644   
645   ; remove registry keys
646   DeleteRegKey HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\Bacula"
647   DeleteRegKey HKLM "Software\Bacula"
648
649   ; remove start menu items
650   SetShellVarContext all
651   Delete /REBOOTOK "$SMPROGRAMS\Bacula\*"
652   RMDir "$SMPROGRAMS\Bacula"
653
654   ; remove files and uninstaller (preserving config for now)
655   Delete /REBOOTOK "$INSTDIR\doc\*"
656   Delete /REBOOTOK "$INSTDIR\*"
657   Delete /REBOOTOK "$INSTDIR\help\*"
658
659   ; Check for existing installation
660   MessageBox MB_YESNO|MB_ICONQUESTION \
661   "Would you like to delete the current configuration files and the working state file?" IDNO NoDel
662     Delete /REBOOTOK "$INSTDIR\*"
663     Delete /REBOOTOK "$INSTDIR\bin32\*"
664     Delete /REBOOTOK "$INSTDIR\working\*"
665     Delete /REBOOTOK "$INSTDIR\plugins\*"
666     Delete /REBOOTOK "$PLUGINSDIR\bacula-*.conf"
667     Delete /REBOOTOK "$PLUGINSDIR\*console.conf"
668     Delete /REBOOTOK "$PLUGINSDIR\*conf.in"
669     Delete /REBOOTOK "$PLUGINSDIR\openssl.exe"
670     Delete /REBOOTOK "$PLUGINSDIR\libeay32.dll"
671     Delete /REBOOTOK "$PLUGINSDIR\ssleay32.dll"
672     Delete /REBOOTOK "$PLUGINSDIR\sed.exe"    
673     Delete /REBOOTOK "$PLUGINSDIR\pw.txt"     
674     Delete /REBOOTOK "$PLUGINSDIR\*.sed" 
675     Delete /REBOOTOK "$PLUGINSDIR\*.cmd"    
676     Delete /REBOOTOK "$PLUGINSDIR\*.sql"    
677     RMDir "$INSTDIR\plugins"
678     RMDir "$INSTDIR\working"
679     RMDir "$INSTDIR\bin32"
680     RMDir "$INSTDIR"
681 NoDel:
682
683   ; remove directories used
684   RMDir "$INSTDIR\doc"
685   RMDir "$INSTDIR\help"
686   RMDir "$INSTDIR"
687 SectionEnd
688
689 ;
690 ; $0 - Service Name (ie Bacula-FD)
691 ; $1 - Service Description (ie Bacula File Daemon)
692 ; $2 - Install as Service
693 ; $3 - Start Service now
694 ;
695 Function InstallDaemon
696   Call InstallCommonFiles
697
698   WriteRegDWORD HKLM "Software\Bacula" "Service_$0" $2
699   
700   ${If} $2 = 1
701     nsExec::ExecToLog '"$INSTDIR\$0.exe" /kill'
702     sleep 3000
703     nsExec::ExecToLog '"$INSTDIR\$0.exe" /remove'
704     nsExec::ExecToLog '"$INSTDIR\$0.exe" /install -c "$INSTDIR\$0.conf"'
705
706     ${If} $OsIsNT <> 1
707       File "Start.bat"
708       File "Stop.bat"
709     ${EndIf}
710
711     ; Start the service?
712
713     ${If} $3 = 1  
714       ${If} $OsIsNT = 1
715         nsExec::ExecToLog 'net start $0'
716       ${Else}
717         Exec '"$INSTDIR\$0.exe" /service -c "$INSTDIR\$0.conf"'
718       ${EndIf}
719     ${EndIf}
720   ${Else}
721     CreateShortCut "$SMPROGRAMS\Bacula\Start $1.lnk" "$INSTDIR\$0.exe" '-c "$INSTDIR\$0.conf"' "$INSTDIR\$0.exe" 0
722   ${EndIf}
723 FunctionEnd
724
725 Function GetComputerName
726   Push $R0
727   Push $R1
728   Push $R2
729
730   System::Call "kernel32::GetComputerNameA(t .R0, *i ${NSIS_MAX_STRLEN} R1) i.R2"
731
732   ${StrCase} $R0 $R0 "L"
733
734   Pop $R2
735   Pop $R1
736   Exch $R0
737 FunctionEnd
738
739 !define ComputerNameDnsFullyQualified   3
740
741 Function GetHostName
742   Push $R0
743   Push $R1
744   Push $R2
745
746   ${If} $OsIsNT = 1
747     System::Call "kernel32::GetComputerNameExA(i ${ComputerNameDnsFullyQualified}, t .R0, *i ${NSIS_MAX_STRLEN} R1) i.R2 ?e"
748     ${If} $R2 = 0
749       Pop $R2
750       DetailPrint "GetComputerNameExA failed - LastError = $R2"
751       Call GetComputerName
752       Pop $R0
753     ${Else}
754       Pop $R2
755     ${EndIf}
756   ${Else}
757     Call GetComputerName
758     Pop $R0
759   ${EndIf}
760
761   Pop $R2
762   Pop $R1
763   Exch $R0
764 FunctionEnd
765
766 !define NameUserPrincipal 8
767
768 Function GetUserName
769   Push $R0
770   Push $R1
771   Push $R2
772
773   ${If} $OsIsNT = 1
774     System::Call "secur32::GetUserNameExA(i ${NameUserPrincipal}, t .R0, *i ${NSIS_MAX_STRLEN} R1) i.R2 ?e"
775     ${If} $R2 = 0
776       Pop $R2
777       DetailPrint "GetUserNameExA failed - LastError = $R2"
778       Pop $R0
779       StrCpy $R0 ""
780     ${Else}
781       Pop $R2
782     ${EndIf}
783   ${Else}
784       StrCpy $R0 ""
785   ${EndIf}
786
787   ${If} $R0 == ""
788     System::Call "advapi32::GetUserNameA(t .R0, *i ${NSIS_MAX_STRLEN} R1) i.R2 ?e"
789     ${If} $R2 = 0
790       Pop $R2
791       DetailPrint "GetUserNameA failed - LastError = $R2"
792       StrCpy $R0 ""
793     ${Else}
794       Pop $R2
795     ${EndIf}
796   ${EndIf}
797
798   Pop $R2
799   Pop $R1
800   Exch $R0
801 FunctionEnd
802
803 Function ConfigEditAndCopy
804   Push $R1
805
806   ${If} ${FileExists} "$0\$1"
807     StrCpy $R1 ".new"
808   ${Else}
809     StrCpy $R1 ""
810   ${EndIf}
811
812   nsExec::ExecToLog '$PLUGINSDIR\sed.exe -f "$PLUGINSDIR\config.sed" -i.bak "$PLUGINSDIR\$1"'
813   CopyFiles "$PLUGINSDIR\$1" "$0\$1$R1"
814
815   Pop $R1
816 FunctionEnd
817
818 Function GetSelectedComponents
819   Push $R0
820   StrCpy $R0 0
821   ${If} ${SectionIsSelected} ${SecFileDaemon}
822     IntOp $R0 $R0 | ${ComponentFile}
823   ${EndIf}
824   ${If} ${SectionIsSelected} ${SecConsole}
825     IntOp $R0 $R0 | ${ComponentTextConsole}
826   ${EndIf}
827   ${If} ${SectionIsSelected} ${SecBatConsole}
828     IntOp $R0 $R0 | ${ComponentBatConsole}
829   ${EndIf}
830   ${If} ${SectionIsSelected} ${SecTrayMonitor}
831     IntOp $R0 $R0 | ${ComponentTrayMonitor}
832   ${EndIf}
833   Exch $R0
834 FunctionEnd
835
836 Function PageComponentsShow
837
838   Call SelectPreviousComponents
839   Call UpdateComponentUI
840 FunctionEnd
841
842 Function PageDirectoryPre
843   ${If} $AutomaticInstall = 1
844   ${OrIf} $InstallType = ${UpgradeInstall}
845     Abort
846   ${EndIf}
847 FunctionEnd
848
849 Function LeaveInstallPage
850   Push "$INSTDIR\install.log"
851   Call DumpLog
852 FunctionEnd
853
854 Function EnterWriteTemplates
855   Push $R0
856   Push $R1
857
858   Call GetSelectedComponents
859   Pop $R0
860
861   IntOp $R0 $R0 & ${ComponentDirector}
862   IntOp $R1 $NewComponents & ${ComponentsFileAndStorage}
863
864   ${If} $R0 <> 0
865   ${OrIf} $R1 = 0
866     Pop $R1
867     Pop $R0
868     Abort
869   ${EndIf}
870
871   IntOp $R0 $NewComponents & ${ComponentFile}
872   ${If} $R0 = 0
873     WriteINIStr "$PLUGINSDIR\WriteTemplates.ini" "Field 2" State 0
874     WriteINIStr "$PLUGINSDIR\WriteTemplates.ini" "Field 2" Flags DISABLED
875     DeleteINIStr "$PLUGINSDIR\WriteTemplates.ini" "Field 3" State
876     WriteINIStr "$PLUGINSDIR\WriteTemplates.ini" "Field 3" Flags REQ_SAVE|FILE_EXPLORER|WARN_IF_EXIST|DISABLED
877   ${Else}
878     WriteINIStr "$PLUGINSDIR\WriteTemplates.ini" "Field 2" State 1
879     DeleteINIStr "$PLUGINSDIR\WriteTemplates.ini" "Field 2" Flags
880     WriteINIStr "$PLUGINSDIR\WriteTemplates.ini" "Field 3" State "C:\$ConfigClientName.conf"
881   ${EndIf}
882
883
884   !InsertMacro MUI_HEADER_TEXT "$(TITLE_WriteTemplates)" "$(SUBTITLE_WriteTemplates)"
885   !InsertMacro MUI_INSTALLOPTIONS_DISPLAY "WriteTemplates.ini"
886
887   !InsertMacro MUI_INSTALLOPTIONS_READ $R0 "WriteTemplates.ini" "Field 2" State
888   ${If} $R0 <> 0
889     File "/oname=$PLUGINSDIR\client.conf.in" "client.conf.in"
890
891     nsExec::ExecToLog '$PLUGINSDIR\sed.exe -f "$PLUGINSDIR\config.sed" -i.bak "$PLUGINSDIR\client.conf.in"'
892     !InsertMacro MUI_INSTALLOPTIONS_READ $R0 "WriteTemplates.ini" "Field 3" State
893     ${If} $R0 != ""
894       CopyFiles "$PLUGINSDIR\client.conf.in" "$R0"
895     ${EndIf}
896   ${EndIf}
897
898
899   Pop $R1
900   Pop $R0
901 FunctionEnd
902
903 Function SelectPreviousComponents
904   ${If} $InstallType <> ${NewInstall}
905     IntOp $R1 $PreviousComponents & ${ComponentFile}
906     ${If} $R1 <> 0
907       !InsertMacro SelectSection ${SecFileDaemon}
908       !InsertMacro SetSectionFlag ${SecFileDaemon} ${SF_RO}
909     ${Else}
910       !InsertMacro UnselectSection ${SecFileDaemon}
911       !InsertMacro ClearSectionFlag ${SecFileDaemon} ${SF_RO}
912     ${EndIf}
913     IntOp $R1 $PreviousComponents & ${ComponentTextConsole}
914     ${If} $R1 <> 0
915       !InsertMacro SelectSection ${SecConsole}
916       !InsertMacro SetSectionFlag ${SecConsole} ${SF_RO}
917     ${Else}
918       !InsertMacro UnselectSection ${SecConsole}
919       !InsertMacro ClearSectionFlag ${SecConsole} ${SF_RO}
920     ${EndIf}
921     IntOp $R1 $PreviousComponents & ${ComponentBatConsole}
922     ${If} $R1 <> 0
923       !InsertMacro SelectSection ${SecBatConsole}
924       !InsertMacro SetSectionFlag ${SecBatConsole} ${SF_RO}
925     ${Else}
926       !InsertMacro UnselectSection ${SecBatConsole}
927       !InsertMacro ClearSectionFlag ${SecBatConsole} ${SF_RO}
928     ${EndIf}
929     IntOp $R1 $PreviousComponents & ${ComponentTrayMonitor}
930     ${If} $R1 <> 0
931       !InsertMacro SelectSection ${SecTrayMonitor}
932       !InsertMacro SetSectionFlag ${SecTrayMonitor} ${SF_RO}
933     ${Else}
934       !InsertMacro UnselectSection ${SecTrayMonitor}
935       !InsertMacro ClearSectionFlag ${SecTrayMonitor} ${SF_RO}
936     ${EndIf}
937   ${EndIf}
938 FunctionEnd
939
940 Function UpdateComponentUI
941   Push $R0
942   Push $R1
943
944   Call GetSelectedComponents
945   Pop $R0
946
947   IntOp $R1 $R0 ^ $PreviousComponents
948   IntOp $NewComponents $R0 & $R1
949
950   ${If} $InstallType <> ${NewInstall}
951     IntOp $R1 $NewComponents & ${ComponentFile}
952     ${If} $R1 <> 0
953       !InsertMacro SetSectionFlag ${SecFileDaemon} ${SF_BOLD}
954     ${Else}
955       !InsertMacro ClearSectionFlag ${SecFileDaemon} ${SF_BOLD}
956     ${EndIf}
957     IntOp $R1 $NewComponents & ${ComponentTextConsole}
958     ${If} $R1 <> 0
959       !InsertMacro SetSectionFlag ${SecConsole} ${SF_BOLD}
960     ${Else}
961       !InsertMacro ClearSectionFlag ${SecConsole} ${SF_BOLD}
962     ${EndIf}
963     IntOp $R1 $NewComponents & ${ComponentBatConsole}
964     ${If} $R1 <> 0
965       !InsertMacro SetSectionFlag ${SecBatConsole} ${SF_BOLD}
966     ${Else}
967       !InsertMacro ClearSectionFlag ${SecBatConsole} ${SF_BOLD}
968     ${EndIf}
969     IntOp $R1 $NewComponents & ${ComponentTrayMonitor}
970     ${If} $R1 <> 0
971       !InsertMacro SetSectionFlag ${SecTrayMonitor} ${SF_BOLD}
972     ${Else}
973       !InsertMacro ClearSectionFlag ${SecTrayMonitor} ${SF_BOLD}
974     ${EndIf}
975   ${EndIf}
976
977   GetDlgItem $R0 $HWNDPARENT 1
978
979   IntOp $R1 $NewComponents & ${ComponentsRequiringUserConfig}
980   ${If} $R1 = 0
981     SendMessage $R0 ${WM_SETTEXT} 0 "STR:Install"
982   ${Else}
983     SendMessage $R0 ${WM_SETTEXT} 0 "STR:&Next >"
984   ${EndIf}
985
986   Pop $R1
987   Pop $R0
988 FunctionEnd
989
990 !include "InstallType.nsh"
991 !include "ConfigPage1.nsh"
992 !include "ConfigPage2.nsh"
993 !include "DumpLog.nsh"