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