]> git.sur5r.net Git - bacula/bacula/blob - bacula/src/win32/full_win32_installer/winbacula.nsi
Restore win32 dir from Branch-5.2 and update it
[bacula/bacula] / bacula / src / win32 / full_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 ; Command line options:
31 ;
32 ; /service    - 
33 ; /start
34 ;
35 ; netsh firewall add portopening protocol=tcp port=9102 name="Bacula-FD"
36
37
38 !define PRODUCT "Bacula"
39
40 ;
41 ; Include the Modern UI
42 ;
43
44 !include "MUI.nsh"
45 !include "LogicLib.nsh"
46 !include "FileFunc.nsh"
47 !include "Sections.nsh"
48 !include "StrFunc.nsh"
49 !include "WinMessages.nsh"
50 ;
51 ; Basics
52 ;
53 Name "Bacula"
54 OutFile "${OUT_DIR}\winbacula-${VERSION}.exe"
55 SetCompressor lzma
56 InstallDir "$PROGRAMFILES\Bacula"
57 InstallDirRegKey HKLM "Software\Bacula" "InstallLocation"
58
59 InstType "Client"
60 InstType "Server"
61 InstType "Full"
62
63 !insertmacro GetParent
64
65 ${StrCase}
66 ${StrRep}
67 ${StrTok}
68 ${StrTrimNewLines}
69
70 ;
71 ; Pull in pages
72 ;
73
74 !define      MUI_COMPONENTSPAGE_SMALLDESC
75
76 !define      MUI_HEADERIMAGE
77 !define      MUI_BGCOLOR                739AB9
78 !define      MUI_HEADERIMAGE_BITMAP     "bacula-logo.bmp"
79
80 !InsertMacro MUI_PAGE_WELCOME
81 !InsertMacro MUI_PAGE_LICENSE "..\..\..\LICENSE"
82 Page custom EnterInstallType
83 !define      MUI_PAGE_CUSTOMFUNCTION_SHOW PageComponentsShow
84 !InsertMacro MUI_PAGE_COMPONENTS
85 !define      MUI_PAGE_CUSTOMFUNCTION_PRE PageDirectoryPre
86 !InsertMacro MUI_PAGE_DIRECTORY
87 Page custom EnterConfigPage1 LeaveConfigPage1
88 Page custom EnterConfigPage2 LeaveConfigPage2
89 !Define      MUI_PAGE_CUSTOMFUNCTION_LEAVE LeaveInstallPage
90 !InsertMacro MUI_PAGE_INSTFILES
91 Page custom EnterWriteTemplates
92 !Define      MUI_FINISHPAGE_SHOWREADME $INSTDIR\Readme.txt
93 !InsertMacro MUI_PAGE_FINISH
94
95 !InsertMacro MUI_UNPAGE_WELCOME
96 !InsertMacro MUI_UNPAGE_CONFIRM
97 !InsertMacro MUI_UNPAGE_INSTFILES
98 !InsertMacro MUI_UNPAGE_FINISH
99
100 !define      MUI_ABORTWARNING
101
102 !InsertMacro MUI_LANGUAGE "English"
103
104 !InsertMacro GetParameters
105 !InsertMacro GetOptions
106
107 DirText "Setup will install Bacula ${VERSION} to the directory specified below. To install in a different folder, click Browse and select another folder."
108
109 !InsertMacro MUI_RESERVEFILE_INSTALLOPTIONS
110 ;
111 ; Global Variables
112 ;
113 Var OptService
114 Var OptStart
115 Var OptSilent
116
117 Var CommonFilesDone
118
119 Var OsIsNT
120
121 Var HostName
122
123 Var ConfigClientName
124 Var ConfigClientPort
125 Var ConfigClientMaxJobs
126 Var ConfigClientPassword
127 Var ConfigClientInstallService
128 Var ConfigClientStartService
129
130 Var ConfigStorageName
131 Var ConfigStoragePort
132 Var ConfigStorageMaxJobs
133 Var ConfigStoragePassword
134 Var ConfigStorageInstallService
135 Var ConfigStorageStartService
136
137 Var ConfigDirectorName
138 Var ConfigDirectorPort
139 Var ConfigDirectorMaxJobs
140 Var ConfigDirectorPassword
141 Var ConfigDirectorAddress
142 Var ConfigDirectorMailServer
143 Var ConfigDirectorMailAddress
144 Var ConfigDirectorDB
145 Var ConfigDirectorInstallService
146 Var ConfigDirectorStartService
147
148 Var ConfigMonitorName
149 Var ConfigMonitorPassword
150
151 Var LocalDirectorPassword
152 Var LocalHostAddress
153
154 Var MySQLPath
155 Var MySQLVersion
156 Var PostgreSQLPath
157 Var PostgreSQLVersion
158
159 Var AutomaticInstall
160 Var InstallType
161 !define NewInstall      0
162 !define UpgradeInstall  1
163 !define MigrateInstall  2
164
165 Var OldInstallDir
166 Var PreviousComponents
167 Var NewComponents
168
169 ; Bit 0 = File Service
170 ;     1 = Storage Service
171 ;     2 = Director Service
172 ;     3 = Command Console
173 ;     4 = Bat Console
174 ;     5 = wxWidgets Console
175 ;     7 = Documentation (PDF)
176 ;     7 = Documentation (HTML)
177
178 !define ComponentFile                   1
179 !define ComponentStorage                2
180 !define ComponentDirector               4
181 !define ComponentTextConsole            8
182 !define ComponentBatConsole             16
183 !define ComponentGUIConsole             32
184 !define ComponentPDFDocs                64
185 !define ComponentHTMLDocs               128
186
187 !define ComponentsRequiringUserConfig           63
188 !define ComponentsFileAndStorage                3
189 !define ComponentsFileAndStorageAndDirector     7
190 !define ComponentsDirectorAndTextGuiConsoles    60
191 !define ComponentsTextAndGuiConsoles            56
192
193 Var HDLG
194 Var HCTL
195
196 Function .onInit
197   Push $R0
198   Push $R1
199
200   ; Process Command Line Options
201   StrCpy $OptService 1
202   StrCpy $OptStart 1
203   StrCpy $OptSilent 0
204   StrCpy $CommonFilesDone 0
205   StrCpy $OsIsNT 0
206   StrCpy $AutomaticInstall 0
207   StrCpy $InstallType ${NewInstall}
208   StrCpy $OldInstallDir ""
209   StrCpy $PreviousComponents 0
210   StrCpy $NewComponents 0
211   StrCpy $MySQLPath ""
212   StrCpy $MySQLVersion ""
213   StrCpy $PostgreSQLPath ""
214   StrCpy $PostgreSQLVersion ""
215
216   ${GetParameters} $R0
217
218   ClearErrors
219   ${GetOptions} $R0 "/noservice" $R1
220   IfErrors +2
221     StrCpy $OptService 0
222
223   ClearErrors
224   ${GetOptions} $R0 "/nostart" $R1
225   IfErrors +2
226     StrCpy $OptStart 0
227
228   IfSilent 0 +2
229     StrCpy $OptSilent 1
230
231   ReadRegStr $R0 HKLM "SOFTWARE\Microsoft\Windows NT\CurrentVersion" CurrentVersion
232   ${If} $R0 != ""
233     StrCpy $OsIsNT 1
234   ${EndIf}
235
236   Call GetComputerName
237   Pop $HostName
238
239   Call GetHostName
240   Pop $LocalHostAddress
241
242   Call GetUserName
243   Pop $ConfigDirectorMailAddress
244
245   Call FindDatabaseApps
246
247   ; Configuration Defaults
248
249   StrCpy $ConfigClientName               "$HostName-fd"
250   StrCpy $ConfigClientPort               9102
251   StrCpy $ConfigClientMaxJobs            5
252   ;StrCpy $ConfigClientPassword
253   StrCpy $ConfigClientInstallService     "$OptService"
254   StrCpy $ConfigClientStartService       "$OptStart"
255
256   StrCpy $ConfigStorageName              "$HostName-sd"
257   StrCpy $ConfigStoragePort              9103
258   StrCpy $ConfigStorageMaxJobs           10
259   ;StrCpy $ConfigStoragePassword
260   StrCpy $ConfigStorageInstallService    "$OptService"
261   StrCpy $ConfigStorageStartService      "$OptStart"
262
263   ;StrCpy $ConfigDirectorName            "$HostName-dir"
264   StrCpy $ConfigDirectorPort             9101
265   StrCpy $ConfigDirectorMaxJobs          1
266   ;StrCpy $ConfigDirectorPassword
267   StrCpy $ConfigDirectorDB               0
268   StrCpy $ConfigDirectorInstallService   "$OptService"
269   StrCpy $ConfigDirectorStartService     "$OptStart"
270
271   StrCpy $ConfigMonitorName              "$HostName-mon"
272   ;StrCpy $ConfigMonitorPassword
273
274   InitPluginsDir
275   File "/oname=$PLUGINSDIR\openssl.exe"  "${SRC_DIR}\openssl.exe"
276   File "/oname=$PLUGINSDIR\libeay32.dll" "${SRC_DIR}\libeay32.dll"
277   File "/oname=$PLUGINSDIR\ssleay32.dll" "${SRC_DIR}\ssleay32.dll"
278   File "/oname=$PLUGINSDIR\sed.exe"      "${SRC_DIR}\sed.exe"
279
280   !InsertMacro MUI_INSTALLOPTIONS_EXTRACT "InstallType.ini"
281   !InsertMacro MUI_INSTALLOPTIONS_EXTRACT "WriteTemplates.ini"
282
283   SetPluginUnload alwaysoff
284
285   nsExec::Exec '"$PLUGINSDIR\openssl.exe" rand -base64 -out $PLUGINSDIR\pw.txt 33'
286   pop $R0
287   ${If} $R0 = 0
288    FileOpen $R1 "$PLUGINSDIR\pw.txt" r
289    IfErrors +4
290      FileRead $R1 $R0
291      ${StrTrimNewLines} $ConfigClientPassword $R0
292      FileClose $R1
293   ${EndIf}
294
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} $ConfigStoragePassword $R0
302      FileClose $R1
303   ${EndIf}
304
305   nsExec::Exec '"$PLUGINSDIR\openssl.exe" rand -base64 -out $PLUGINSDIR\pw.txt 33'
306   pop $R0
307   ${If} $R0 = 0
308    FileOpen $R1 "$PLUGINSDIR\pw.txt" r
309    IfErrors +4
310      FileRead $R1 $R0
311      ${StrTrimNewLines} $LocalDirectorPassword $R0
312      FileClose $R1
313   ${EndIf}
314
315   SetPluginUnload manual
316
317   nsExec::Exec '"$PLUGINSDIR\openssl.exe" rand -base64 -out $PLUGINSDIR\pw.txt 33'
318   pop $R0
319   ${If} $R0 = 0
320    FileOpen $R1 "$PLUGINSDIR\pw.txt" r
321    IfErrors +4
322      FileRead $R1 $R0
323      ${StrTrimNewLines} $ConfigMonitorPassword $R0
324      FileClose $R1
325   ${EndIf}
326
327   Pop $R1
328   Pop $R0
329 FunctionEnd
330
331 Function .onSelChange
332   Call UpdateComponentUI
333 FunctionEnd
334
335 Function InstallCommonFiles
336   ${If} $CommonFilesDone = 0
337     SetOutPath "$INSTDIR"
338     File "Readme.txt"
339
340     SetOutPath "$INSTDIR\bin"
341 !if "${BUILD_TOOLS}" == "VC8"
342     File "${SRC_DIR}\msvcm80.dll"
343     File "${SRC_DIR}\msvcp80.dll"
344     File "${SRC_DIR}\msvcr80.dll"
345     File "${SRC_DIR}\Microsoft.VC80.CRT.manifest"
346     File "${SRC_DIR}\pthreadVCE.dll"
347 !endif
348 !if "${BUILD_TOOLS}" == "VC8_DEBUG"
349     File "${SRC_DIR}\msvcm80.dll"
350     File "${SRC_DIR}\msvcp80.dll"
351     File "${SRC_DIR}\msvcr80.dll"
352     File "${SRC_DIR}\Microsoft.VC80.CRT.manifest"
353     File "${SRC_DIR}\msvcm80d.dll"
354     File "${SRC_DIR}\msvcp80d.dll"
355     File "${SRC_DIR}\msvcr80d.dll"
356     File "${SRC_DIR}\Microsoft.VC80.DebugCRT.manifest"
357     File "${SRC_DIR}\pthreadVCE.dll"
358 !endif
359 !if "${BUILD_TOOLS}" == "MinGW"
360     File "${SRC_DIR}\mingwm10.dll"
361     File "${SRC_DIR}\pthreadGCE.dll"
362 !endif
363     File "${SRC_DIR}\libeay32.dll"
364     File "${SRC_DIR}\ssleay32.dll"
365     File "${SRC_DIR}\zlib1.dll"
366 !if "${BUILD_TOOLS}" == "VC8"
367     File "${SRC_DIR}\zlib1.dll.manifest"
368 !endif
369 !If "${BUILD_TOOLS}" == "VC8_DEBUG"
370     File "${SRC_DIR}\zlib1.dll.manifest"
371 !endif
372     File "/oname=$INSTDIR\openssl.cnf" "${SRC_DIR}\openssl.cnf"
373     File "${SRC_DIR}\openssl.exe"
374     File "${SRC_DIR}\bsleep.exe"
375     File "${SRC_DIR}\bsmtp.exe"
376     File "${SRC_DIR}\bacula.dll"
377     File "${SRC_DIR}\expr64.exe"
378     File "${SRC_DIR}\snooze.exe"
379
380     CreateShortCut "$SMPROGRAMS\Bacula\Documentation\View Readme.lnk" "write.exe" '"$INSTDIR\Readme.txt"'
381
382     StrCpy $CommonFilesDone 1
383   ${EndIf}
384 FunctionEnd
385
386 Section "-Initialize"
387   ${If} $MySQLPath != ""
388     DetailPrint "Found MySQL (version $MySQLVersion)"
389   ${EndIf}
390   ${If} $PostgreSQLPath != ""
391     DetailPrint "Found PostgreSQL (version $PostgreSQLVersion)"
392   ${EndIf}
393
394   WriteRegStr   HKLM Software\Bacula InstallLocation "$INSTDIR"
395
396   Call GetSelectedComponents
397   Pop $R2
398   WriteRegDWORD HKLM Software\Bacula Components $R2
399
400   WriteRegDWORD HKLM Software\Bacula Database $ConfigDirectorDB
401
402   ; remove start menu items
403   SetShellVarContext all
404
405   Delete /REBOOTOK "$SMPROGRAMS\Bacula\Configuration\*"
406   Delete /REBOOTOK "$SMPROGRAMS\Bacula\Documentation\*"
407   Delete /REBOOTOK "$SMPROGRAMS\Bacula\*"
408   RMDir "$SMPROGRAMS\Bacula\Configuration"
409   RMDir "$SMPROGRAMS\Bacula\Documentation"
410   RMDir "$SMPROGRAMS\Bacula"
411   CreateDirectory "$SMPROGRAMS\Bacula"
412   CreateDirectory "$SMPROGRAMS\Bacula\Configuration"
413   CreateDirectory "$SMPROGRAMS\Bacula\Documentation"
414
415   CreateDirectory "$INSTDIR"
416   CreateDirectory "$INSTDIR\bin"
417   CreateDirectory "$APPDATA\Bacula"
418   CreateDirectory "$APPDATA\Bacula\Work"
419   CreateDirectory "$APPDATA\Bacula\Spool"
420
421   SetOutPath "$INSTDIR"
422   File "..\..\..\LICENSE"
423   Delete /REBOOTOK "$INSTDIR\bin\License.txt"
424
425   FileOpen $R1 $PLUGINSDIR\config.sed w
426   FileWrite $R1 "s;@VERSION@;${VERSION};g$\r$\n"
427   FileWrite $R1 "s;@DATE@;${__DATE__};g$\r$\n"
428   FileWrite $R1 "s;@DISTNAME@;Windows;g$\r$\n"
429
430 !If "$BUILD_TOOLS" == "MinGW"
431   StrCpy $R2 "MinGW32"
432 !Else
433   StrCpy $R2 "MVS"
434 !EndIf
435
436   Call GetHostName
437   Exch $R3
438   Pop $R3
439
440   FileWrite $R1 "s;@DISTVER@;$R2;g$\r$\n"
441
442   ${StrRep} $R2 "$APPDATA\Bacula\Work" "\" "\\\\"
443   FileWrite $R1 's;@working_dir@;$R2;g$\r$\n'
444   ${StrRep} $R2 "$APPDATA\Bacula\Work" "\" "\\"
445   FileWrite $R1 's;@working_dir_cmd@;$R2;g$\r$\n'
446
447   ${StrRep} $R2 "$INSTDIR\bin" "\" "\\\\"
448   FileWrite $R1 's;@bin_dir@;$R2;g$\r$\n'
449   ${StrRep} $R2 "$INSTDIR\bin" "\" "\\"
450   FileWrite $R1 's;@bin_dir_cmd@;$R2;g$\r$\n'
451
452   ${StrRep} $R2 "$INSTDIR\bin\fdplugins" "\" "\\\\"
453   FileWrite $R1 's;@fdplugins_dir@;$R2;g$\r$\n'
454
455   ${StrRep} $R2 "$INSTDIR" "\" "/"
456   FileWrite $R1 "s;@BUILD_DIR@;$R2;g$\r$\n"
457
458   Call IsDirectorSelected
459   Pop $R2
460   ${If} $R2 = 1
461     FileWrite $R1 "s;@director_address@;$LocalHostAddress;g$\r$\n"
462   ${Else}
463     ${If} "$ConfigDirectorAddress" != ""
464       FileWrite $R1 "s;@director_address@;$ConfigDirectorAddress;g$\r$\n"
465     ${EndIf}
466   ${EndIf}
467
468   FileWrite $R1 "s;@client_address@;$LocalHostAddress;g$\r$\n"
469   FileWrite $R1 "s;@storage_address@;$LocalHostAddress;g$\r$\n"
470
471   ${If} "$ConfigClientName" != ""
472     FileWrite $R1 "s;@client_name@;$ConfigClientName;g$\r$\n"
473   ${EndIf}
474   ${If} "$ConfigClientPort" != ""
475     FileWrite $R1 "s;@client_port@;$ConfigClientPort;g$\r$\n"
476   ${EndIf}
477   ${If} "$ConfigClientMaxJobs" != ""
478     FileWrite $R1 "s;@client_maxjobs@;$ConfigClientMaxJobs;g$\r$\n"
479   ${EndIf}
480   ${If} "$ConfigClientPassword" != ""
481     FileWrite $R1 "s;@client_password@;$ConfigClientPassword;g$\r$\n"
482   ${EndIf}
483   ${If} "$ConfigStorageName" != ""
484     FileWrite $R1 "s;@storage_name@;$ConfigStorageName;g$\r$\n"
485   ${EndIf}
486   ${If} "$ConfigStoragePort" != ""
487     FileWrite $R1 "s;@storage_port@;$ConfigStoragePort;g$\r$\n"
488   ${EndIf}
489   ${If} "$ConfigStorageMaxJobs" != ""
490     FileWrite $R1 "s;@storage_maxjobs@;$ConfigStorageMaxJobs;g$\r$\n"
491   ${EndIf}
492   ${If} "$ConfigStoragePassword" != ""
493     FileWrite $R1 "s;@storage_password@;$ConfigStoragePassword;g$\r$\n"
494   ${EndIf}
495   ${If} "$ConfigDirectorName" != ""
496     FileWrite $R1 "s;@director_name@;$ConfigDirectorName;g$\r$\n"
497   ${EndIf}
498   ${If} "$ConfigDirectorPort" != ""
499     FileWrite $R1 "s;@director_port@;$ConfigDirectorPort;g$\r$\n"
500   ${EndIf}
501   ${If} "$ConfigDirectorMaxJobs" != ""
502     FileWrite $R1 "s;@director_maxjobs@;$ConfigDirectorMaxJobs;g$\r$\n"
503   ${EndIf}
504   ${If} "$ConfigDirectorPassword" != ""
505     FileWrite $R1 "s;@director_password@;$ConfigDirectorPassword;g$\r$\n"
506   ${EndIf}
507   ${If} "$ConfigDirectorMailServer" != ""
508     FileWrite $R1 "s;@smtp_host@;$ConfigDirectorMailServer;g$\r$\n"
509   ${EndIf}
510   ${If} "$ConfigDirectorMailAddress" != ""
511     FileWrite $R1 "s;@job_email@;$ConfigDirectorMailAddress;g$\r$\n"
512   ${EndIf}
513   ${If} "$ConfigMonitorName" != ""
514     FileWrite $R1 "s;@monitor_name@;$ConfigMonitorName;g$\r$\n"
515   ${EndIf}
516   ${If} "$ConfigMonitorPassword" != ""
517     FileWrite $R1 "s;@monitor_password@;$ConfigMonitorPassword;g$\r$\n"
518   ${EndIf}
519
520   ${If} $ConfigDirectorDB = 1
521     ${If} $MySQLPath != ""
522       ${StrRep} $R2 "$MySQLPath\bin" "\" "\\"
523       FileWrite $R1 "s;@SQL_BINDIR@;$R2;g$\r$\n"
524     ${EndIf}
525   ${ElseIf} $ConfigDirectorDB = 2
526     ${If} $PostgreSQLPath != ""
527       ${StrRep} $R2 "$PostgreSQLPath\bin" "\" "\\"
528       FileWrite $R1 "s;@SQL_BINDIR@;$R2;g$\r$\n"
529     ${EndIf}
530   ${EndIf}
531
532   FileClose $R1
533
534   ${If} $InstallType = ${MigrateInstall}
535     FileOpen $R1 $PLUGINSDIR\migrate.sed w
536     ${StrRep} $R2 "$APPDATA\Bacula\Work" "\" "\\\\"
537     FileWrite $R1 's;\(Working *Directory *= *\)[^ ][^ ]*.*$$;\1"$R2";$\r$\n'
538     FileWrite $R1 's;\(Pid *Directory *= *\)[^ ][^ ]*.*$$;\1"$R2";$\r$\n'
539     FileClose $R1
540   ${EndIf}
541
542   ${If} ${FileExists} "$OldInstallDir\bin\bacula-fd.exe"
543     nsExec::ExecToLog '"$OldInstallDir\bin\bacula-fd.exe" /kill'     ; Shutdown any bacula that could be running
544     Sleep 3000
545     nsExec::ExecToLog '"$OldInstallDir\bin\bacula-fd.exe" /remove'   ; Remove existing service
546   ${EndIf}
547
548   ${If} ${FileExists} "$OldInstallDir\bin\bacula-sd.exe"
549     nsExec::ExecToLog '"$OldInstallDir\bin\bacula-sd.exe" /kill'     ; Shutdown any bacula that could be running
550     Sleep 3000
551     nsExec::ExecToLog '"$OldInstallDir\bin\bacula-sd.exe" /remove'   ; Remove existing service
552   ${EndIf}
553
554   ${If} ${FileExists} "$OldInstallDir\bin\bacula-dir.exe"
555     nsExec::ExecToLog '"$OldInstallDir\bin\bacula-dir.exe" /kill'     ; Shutdown any bacula that could be running
556     Sleep 3000
557     nsExec::ExecToLog '"$OldInstallDir\bin\bacula-dir.exe" /remove'   ; Remove existing service
558   ${EndIf}
559
560 SectionEnd
561
562 SectionGroup "Client" SecGroupClient
563
564 Section "File Service" SecFileDaemon
565   SectionIn 1 2 3
566
567   SetOutPath "$INSTDIR\bin\fdplugins"
568   File "${SRC_DIR}\exchange-fd.dll"
569
570   SetOutPath "$INSTDIR\bin"
571
572   File "${SRC_DIR}\bacula-fd.exe"
573
574   ${If} $InstallType = ${MigrateInstall}
575   ${AndIf} ${FileExists} "$OldInstallDir\bin\bacula-fd.conf"
576     CopyFiles "$OldInstallDir\bin\bacula-fd.conf" "$APPDATA\Bacula"
577     nsExec::ExecToLog '$PLUGINSDIR\sed.exe -f "$PLUGINSDIR\migrate.sed" -i.bak "$APPDATA\Bacula\bacula-fd.conf"'
578   ${Else}
579     File "/oname=$PLUGINSDIR\bacula-fd.conf" "bacula-fd.conf.in"
580
581     StrCpy $0 "$APPDATA\Bacula"
582     StrCpy $1 bacula-fd.conf
583     Call ConfigEditAndCopy
584   ${EndIf}
585
586   StrCpy $0 bacula-fd
587   StrCpy $1 "File Service"
588   StrCpy $2 $ConfigClientInstallService
589   StrCpy $3 $ConfigClientStartService
590
591   Call InstallDaemon
592
593   CreateShortCut "$SMPROGRAMS\Bacula\Configuration\Edit Client Configuration.lnk" "write.exe" '"$APPDATA\Bacula\bacula-fd.conf"'
594 SectionEnd
595
596 SectionGroupEnd
597
598 SectionGroup "Server" SecGroupServer
599
600 Section "Storage Service" SecStorageDaemon
601   SectionIn 2 3
602
603   SetOutPath "$INSTDIR\bin"
604
605   File "${SRC_DIR}\loaderinfo.exe"
606   File "${SRC_DIR}\mt.exe"
607   File "${SRC_DIR}\mtx.exe"
608   File "${SRC_DIR}\scsitape.exe"
609   File "${SRC_DIR}\tapeinfo.exe"
610   File "${SRC_DIR}\bacula-sd.exe"
611   File "${SRC_DIR}\bcopy.exe"
612   File "${SRC_DIR}\bextract.exe"
613   File "${SRC_DIR}\bls.exe"
614   File "${SRC_DIR}\bscan.exe"
615   File "${SRC_DIR}\btape.exe"
616   File "${SRC_DIR}\scsilist.exe"
617   File "${SRC_DIR}\mkisofs.exe"
618   File "${SRC_DIR}\growisofs.exe"
619   File "${SRC_DIR}\dvd-ram-control.exe"
620   File "${SRC_DIR}\dvd+rw-booktype.exe"
621   File "${SRC_DIR}\dvd+rw-format.exe"
622   File "${SRC_DIR}\dvd+rw-mediainfo.exe"
623
624   File "/oname=$PLUGINSDIR\mtx-changer.cmd" "${SRC_DIR}\mtx-changer.cmd"
625
626   StrCpy $0 "$INSTDIR\bin"
627   StrCpy $1 mtx-changer.cmd
628   Call ConfigEditAndCopy
629
630   File "/oname=$PLUGINSDIR\disk-changer.cmd" "${SRC_DIR}\disk-changer.cmd"
631
632   StrCpy $0 "$INSTDIR\bin"
633   StrCpy $1 disk-changer.cmd
634   Call ConfigEditAndCopy
635
636   File "/oname=$PLUGINSDIR\dvd-handler.cmd" "${SRC_DIR}\dvd-handler.cmd"
637
638   StrCpy $0 "$INSTDIR\bin"
639   StrCpy $1 dvd-handler.cmd
640   Call ConfigEditAndCopy
641
642   File "/oname=$PLUGINSDIR\bacula-sd.conf" "bacula-sd.conf.in"
643
644   StrCpy $0 "$APPDATA\Bacula"
645   StrCpy $1 bacula-sd.conf
646   Call ConfigEditAndCopy
647
648   StrCpy $0 bacula-sd
649   StrCpy $1 "Storage Service"
650   StrCpy $2 $ConfigStorageInstallService
651   StrCpy $3 $ConfigStorageStartService
652   Call InstallDaemon
653
654   CreateShortCut "$SMPROGRAMS\Bacula\Configuration\List Devices.lnk" "$INSTDIR\bin\scsilist.exe" "/pause"
655   CreateShortCut "$SMPROGRAMS\Bacula\Configuration\Edit Storage Configuration.lnk" "write.exe" '"$APPDATA\Bacula\bacula-sd.conf"'
656 SectionEnd
657
658 Section "Director Service" SecDirectorDaemon
659   SectionIn 2 3
660
661   SetOutPath "$INSTDIR\bin"
662
663   ${If} $ConfigDirectorDB = 1
664     File /oname=bacula_cats.dll "${SRC_DIR}\cats_mysql.dll"
665     File "${SRC_DIR}\libmysql.dll"
666     File /oname=$PLUGINSDIR\create_database.cmd ${SRC_DIR}\create_mysql_database.cmd
667     File /oname=$PLUGINSDIR\drop_database.cmd ${SRC_DIR}\drop_mysql_database.cmd
668     File /oname=$PLUGINSDIR\make_tables.cmd ${SRC_DIR}\make_mysql_tables.cmd
669     File ${SRC_DIR}\make_mysql_tables.sql
670     File /oname=$PLUGINSDIR\drop_tables.cmd ${SRC_DIR}\drop_mysql_tables.cmd
671     File ${SRC_DIR}\drop_mysql_tables.sql
672     File /oname=$PLUGINSDIR\grant_privileges.cmd ${SRC_DIR}\grant_mysql_privileges.cmd
673     File ${SRC_DIR}\grant_mysql_privileges.sql
674     File /oname=$PLUGINSDIR\make_catalog_backup.cmd ${SRC_DIR}\make_mysql_catalog_backup.cmd
675   ${ElseIf} $ConfigDirectorDB = 2
676     File /oname=bacula_cats.dll "${SRC_DIR}\cats_postgresql.dll"
677     File "${SRC_DIR}\libpq.dll"
678 !if "${BUILD_TOOLS}" == "VC8"
679     File "${SRC_DIR}\comerr32.dll"
680     File "${SRC_DIR}\libintl-2.dll"
681     File "${SRC_DIR}\libiconv-2.dll"
682     File "${SRC_DIR}\krb5_32.dll"
683 !endif
684 !If "${BUILD_TOOLS}" == "VC8_DEBUG"
685     File "${SRC_DIR}\comerr32.dll"
686     File "${SRC_DIR}\libintl-2.dll"
687     File "${SRC_DIR}\libiconv-2.dll"
688     File "${SRC_DIR}\krb5_32.dll"
689 !endif
690     File /oname=$PLUGINSDIR\create_database.cmd ${SRC_DIR}\create_postgresql_database.cmd
691     File /oname=$PLUGINSDIR\drop_database.cmd ${SRC_DIR}\drop_postgresql_database.cmd
692     File /oname=$PLUGINSDIR\make_tables.cmd ${SRC_DIR}\make_postgresql_tables.cmd
693     File ${SRC_DIR}\create_postgresql_database.sql
694     File ${SRC_DIR}\make_postgresql_tables.sql
695     File /oname=$PLUGINSDIR\drop_tables.cmd ${SRC_DIR}\drop_postgresql_tables.cmd
696     File ${SRC_DIR}\drop_postgresql_tables.sql
697     File /oname=$PLUGINSDIR\grant_privileges.cmd ${SRC_DIR}\grant_postgresql_privileges.cmd
698     File ${SRC_DIR}\grant_postgresql_privileges.sql
699     File /oname=$PLUGINSDIR\make_catalog_backup.cmd ${SRC_DIR}\make_postgresql_catalog_backup.cmd
700   ${ElseIf} $ConfigDirectorDB = 3
701     File "${SRC_DIR}\sqlite3.exe"
702 !if "${BUILD_TOOLS}" == "VC8"
703     File "${SRC_DIR}\sqlite3.exe.manifest"
704 !endif
705 !If "${BUILD_TOOLS}" == "VC8_DEBUG"
706     File "${SRC_DIR}\sqlite3.exe.manifest"
707 !endif
708     File /oname=bacula_cats.dll "${SRC_DIR}\cats_sqlite3.dll"
709     File /oname=$PLUGINSDIR\create_database.cmd ${SRC_DIR}\create_sqlite3_database.cmd
710     File /oname=$PLUGINSDIR\drop_database.cmd ${SRC_DIR}\drop_sqlite3_database.cmd
711     File /oname=$PLUGINSDIR\make_tables.cmd ${SRC_DIR}\make_sqlite3_tables.cmd
712     File ${SRC_DIR}\make_sqlite3_tables.sql
713     File /oname=$PLUGINSDIR\drop_tables.cmd ${SRC_DIR}\drop_sqlite3_tables.cmd
714     File /oname=$PLUGINSDIR\grant_privileges.cmd ${SRC_DIR}\grant_sqlite3_privileges.cmd
715     File /oname=$PLUGINSDIR\make_catalog_backup.cmd ${SRC_DIR}\make_sqlite3_catalog_backup.cmd
716   ${EndIf}
717
718   File "${SRC_DIR}\bacula-dir.exe"
719   File "${SRC_DIR}\dbcheck.exe"
720
721   File "/oname=$PLUGINSDIR\delete_catalog_backup.cmd" "${SRC_DIR}\delete_catalog_backup.cmd"
722
723   StrCpy $0 "$INSTDIR\bin"
724   
725   StrCpy $1 create_database.cmd
726   Call ConfigEditAndCopy
727
728   StrCpy $1 drop_database.cmd
729   Call ConfigEditAndCopy
730
731   StrCpy $1 make_tables.cmd
732   Call ConfigEditAndCopy
733
734   StrCpy $1 drop_tables.cmd
735   Call ConfigEditAndCopy
736
737   StrCpy $1 grant_privileges.cmd
738   Call ConfigEditAndCopy
739
740   StrCpy $1 make_catalog_backup.cmd
741   Call ConfigEditAndCopy
742
743   StrCpy $1 delete_catalog_backup.cmd
744   Call ConfigEditAndCopy
745
746   File "${SRC_DIR}\query.sql"
747
748   File "/oname=$PLUGINSDIR\bacula-dir.conf" "bacula-dir.conf.in"
749
750   StrCpy $0 "$APPDATA\Bacula"
751   StrCpy $1 bacula-dir.conf
752   Call ConfigEditAndCopy
753
754   StrCpy $0 bacula-dir
755   StrCpy $1 "Director Service"
756   StrCpy $2 $ConfigDirectorInstallService
757   StrCpy $3 $ConfigDirectorStartService
758   Call InstallDaemon
759
760   CreateShortCut "$SMPROGRAMS\Bacula\Configuration\Edit Director Configuration.lnk" "write.exe" '"$APPDATA\Bacula\bacula-dir.conf"'
761 SectionEnd
762
763 SectionGroupEnd
764
765 SectionGroup "Consoles" SecGroupConsoles
766
767 Section "Command Console" SecConsole
768   SectionIn 1 2 3
769
770   SetOutPath "$INSTDIR\bin"
771
772   File "${SRC_DIR}\bconsole.exe"
773   Call InstallCommonFiles
774
775   ${If} $InstallType = ${MigrateInstall}
776   ${AndIf} ${FileExists} "$OldInstallDir\bin\bconsole.conf"
777     CopyFiles "$OldInstallDir\bin\bconsole.conf" "$APPDATA\Bacula"
778   ${Else}
779     File "/oname=$PLUGINSDIR\bconsole.conf" "bconsole.conf.in"
780     StrCpy $0 "$APPDATA\Bacula"
781     StrCpy $1 bconsole.conf
782     Call ConfigEditAndCopy
783   ${EndIf}
784
785   CreateShortCut "$SMPROGRAMS\Bacula\bconsole.lnk" "$INSTDIR\bin\bconsole.exe" '-c "$APPDATA\Bacula\bconsole.conf"' "$INSTDIR\bin\bconsole.exe" 0
786   CreateShortCut "$SMPROGRAMS\Bacula\Configuration\Edit Command Console Configuration.lnk" "write.exe" '"$APPDATA\Bacula\bconsole.conf"'
787
788 SectionEnd
789
790 Section "Bat Console" SecBatConsole
791   SectionIn 1 2 3
792   
793   SetOutPath "$INSTDIR\bin"
794
795   Call InstallCommonFiles
796   File "${SRC_DIR}\QtCore4.dll"
797   File "${SRC_DIR}\QtGui4.dll"
798
799   File "${SRC_DIR}\bat.exe"
800
801   ${If} $InstallType = ${MigrateInstall}
802   ${AndIf} ${FileExists} "$OldInstallDir\bin\bat.conf"
803     CopyFiles "$OldInstallDir\bin\bat.conf" "$APPDATA\Bacula"
804   ${Else}
805     File "/oname=$PLUGINSDIR\bat.conf" "bat.conf.in"
806     StrCpy $0 "$APPDATA\Bacula"
807     StrCpy $1 bat.conf
808     Call ConfigEditAndCopy
809   ${EndIf}
810
811   ; Create Start Menu entry
812   CreateShortCut "$SMPROGRAMS\Bacula\Bat.lnk" "$INSTDIR\bin\bat.exe" '-c "$APPDATA\Bacula\bat.conf"' "$INSTDIR\bin\bat.exe" 0
813   CreateShortCut "$SMPROGRAMS\Bacula\Configuration\Edit Bat Configuration.lnk" "write.exe" '"$APPDATA\Bacula\bat.conf"'
814 SectionEnd
815
816
817 Section "Graphical Console" SecWxConsole
818   SectionIn 1 2 3
819   
820   SetOutPath "$INSTDIR\bin"
821
822   Call InstallCommonFiles
823 !if "${BUILD_TOOLS}" == "VC8"
824   File "${SRC_DIR}\wxbase28_vc_bacula.dll"
825   File "${SRC_DIR}\wxmsw28_core_vc_bacula.dll"
826 !endif
827 !If "${BUILD_TOOLS}" == "VC8_DEBUG"
828   File "${SRC_DIR}\wxbase28_vc_bacula.dll"
829   File "${SRC_DIR}\wxmsw28_core_vc_bacula.dll"
830 !endif
831 !if "${BUILD_TOOLS}" == "MinGW"
832   File "${SRC_DIR}\wxbase28_gcc_bacula.dll"
833   File "${SRC_DIR}\wxmsw28_core_gcc_bacula.dll"
834 !endif
835
836   File "${SRC_DIR}\bwx-console.exe"
837
838   ${If} $InstallType = ${MigrateInstall}
839   ${AndIf} ${FileExists} "$OldInstallDir\bin\bwx-console.conf"
840     CopyFiles "$OldInstallDir\bin\bwx-console.conf" "$APPDATA\Bacula"
841   ${Else}
842     File "/oname=$PLUGINSDIR\bwx-console.conf" "bwx-console.conf.in"
843     StrCpy $0 "$APPDATA\Bacula"
844     StrCpy $1 bwx-console.conf
845     Call ConfigEditAndCopy
846   ${EndIf}
847
848   ; Create Start Menu entry
849   CreateShortCut "$SMPROGRAMS\Bacula\bwx-console.lnk" "$INSTDIR\bin\bwx-console.exe" '-c "$APPDATA\Bacula\bwx-console.conf"' "$INSTDIR\bin\bwx-console.exe" 0
850   CreateShortCut "$SMPROGRAMS\Bacula\Configuration\Edit Graphical Console Configuration.lnk" "write.exe" '"$APPDATA\Bacula\bwx-console.conf"'
851 SectionEnd
852
853 SectionGroupEnd
854
855 SectionGroup "Documentation" SecGroupDocumentation
856
857 Section "Documentation (Acrobat Format)" SecDocPdf
858   SectionIn 1 2 3
859
860   SetOutPath "$INSTDIR\doc"
861   CreateDirectory "$INSTDIR\doc"
862
863   File "${SRC_DIR}\docs\manuals\en\console\console.pdf"
864   File "${SRC_DIR}\docs\manuals\en\misc\misc.pdf"
865   File "${SRC_DIR}\docs\manuals\en\main\main.pdf"
866   File "${SRC_DIR}\docs\manuals\en\utility\utility.pdf"
867   File "${SRC_DIR}\docs\manuals\en\problems\problems.pdf"
868   CreateShortCut "$SMPROGRAMS\Bacula\Documentation\Console.lnk" '"$INSTDIR\doc\console.pdf"'
869   CreateShortCut "$SMPROGRAMS\Bacula\Documentation\Main.lnk" '"$INSTDIR\doc\main.pdf"'
870   CreateShortCut "$SMPROGRAMS\Bacula\Documentation\Misc.lnk" '"$INSTDIR\doc\misc.pdf"'
871   CreateShortCut "$SMPROGRAMS\Bacula\Documentation\Utility.lnk" '"$INSTDIR\doc\utility.pdf"'
872   CreateShortCut "$SMPROGRAMS\Bacula\Documentation\Problems.lnk" '"$INSTDIR\doc\problems.pdf"'
873 SectionEnd
874
875 Section "Documentation (HTML Format)" SecDocHtml
876   SectionIn 3
877
878   SetOutPath "$INSTDIR\doc"
879   CreateDirectory "$INSTDIR\doc"
880
881 ; File "${SRC_DIR}\manual\bacula\*.html"
882 ; File "${SRC_DIR}\manual\bacula\*.png"
883 ; File "${SRC_DIR}\manual\bacula\*.css"
884 ; CreateShortCut "$SMPROGRAMS\Bacula\Documentation\Manual (HTML).lnk" '"$INSTDIR\doc\index.html"'
885 SectionEnd
886
887 SectionGroupEnd
888
889 Section "-Finish"
890   Push $R0
891
892   ${If} $OsIsNT = 1
893     nsExec::ExecToLog 'cmd.exe /C echo Y|cacls "$INSTDIR" /T /G SYSTEM:F Administrators:F'
894     nsExec::ExecToLog 'cmd.exe /C echo Y|cacls "$APPDATA\Bacula" /T /G SYSTEM:F Administrators:F'
895   ${EndIf}
896
897   ; Write the uninstall keys for Windows & create Start Menu entry
898   WriteRegStr   HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\Bacula" "DisplayName" "Bacula"
899   WriteRegStr   HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\Bacula" "InstallLocation" "$INSTDIR"
900   WriteRegStr   HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\Bacula" "DisplayVersion" "${VERSION}"
901   ${StrTok} $R0 "${VERSION}" "." 0 0
902   WriteRegDWORD HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\Bacula" "VersionMajor" $R0
903   ${StrTok} $R0 "${VERSION}" "." 1 0
904   WriteRegDWORD HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\Bacula" "VersionMinor" $R0
905   WriteRegDWORD HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\Bacula" "NoModify" 1
906   WriteRegDWORD HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\Bacula" "NoRepair" 1
907   WriteRegStr   HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\Bacula" "URLUpdateInfo" "http://sourceforge.net/project/showfiles.php?group_id=50727"
908   WriteRegStr   HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\Bacula" "URLInfoAbout" "http://www.bacula.org"
909   WriteRegStr   HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\Bacula" "HelpLink" "http://www.bacula.org/?page=support"
910   WriteRegStr   HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\Bacula" "UninstallString" '"$INSTDIR\uninstall.exe"'
911   WriteUninstaller "$INSTDIR\Uninstall.exe"
912   CreateShortCut "$SMPROGRAMS\Bacula\Uninstall Bacula.lnk" "$INSTDIR\Uninstall.exe" "" "$INSTDIR\Uninstall.exe" 0
913   Pop $R0
914 SectionEnd
915
916 ; Extra Page descriptions
917
918 LangString DESC_SecFileDaemon ${LANG_ENGLISH} "Install Bacula File Daemon on this system."
919 LangString DESC_SecStorageDaemon ${LANG_ENGLISH} "Install Bacula Storage Daemon on this system."
920 LangString DESC_SecDirectorDaemon ${LANG_ENGLISH} "Install Bacula Director Daemon on this system."
921 LangString DESC_SecConsole ${LANG_ENGLISH} "Install command console program on this system."
922 LangString DESC_SecBatConsole ${LANG_ENGLISH} "Install Bat graphical console program on this system."
923 LangString DESC_SecWxConsole ${LANG_ENGLISH} "Install wxWidgets graphical console program on this system."
924 LangString DESC_SecDocPdf ${LANG_ENGLISH} "Install documentation in Acrobat format on this system."
925 LangString DESC_SecDocHtml ${LANG_ENGLISH} "Install documentation in HTML format on this system."
926
927 LangString TITLE_ConfigPage1 ${LANG_ENGLISH} "Configuration"
928 LangString SUBTITLE_ConfigPage1 ${LANG_ENGLISH} "Set installation configuration."
929
930 LangString TITLE_ConfigPage2 ${LANG_ENGLISH} "Configuration (continued)"
931 LangString SUBTITLE_ConfigPage2 ${LANG_ENGLISH} "Set installation configuration."
932
933 LangString TITLE_InstallType ${LANG_ENGLISH} "Installation Type"
934 LangString SUBTITLE_InstallType ${LANG_ENGLISH} "Choose installation type."
935
936 LangString TITLE_WriteTemplates ${LANG_ENGLISH} "Create Templates"
937 LangString SUBTITLE_WriteTemplates ${LANG_ENGLISH} "Create resource templates for inclusion in the Director's configuration file."
938
939 !InsertMacro MUI_FUNCTION_DESCRIPTION_BEGIN
940   !InsertMacro MUI_DESCRIPTION_TEXT ${SecFileDaemon} $(DESC_SecFileDaemon)
941   !InsertMacro MUI_DESCRIPTION_TEXT ${SecStorageDaemon} $(DESC_SecStorageDaemon)
942   !InsertMacro MUI_DESCRIPTION_TEXT ${SecDirectorDaemon} $(DESC_SecDirectorDaemon)
943   !InsertMacro MUI_DESCRIPTION_TEXT ${SecConsole} $(DESC_SecConsole)
944   !InsertMacro MUI_DESCRIPTION_TEXT ${SecBatConsole} $(DESC_SecBatConsole)
945   !InsertMacro MUI_DESCRIPTION_TEXT ${SecWxConsole} $(DESC_SecWxConsole)
946   !InsertMacro MUI_DESCRIPTION_TEXT ${SecDocPdf} $(DESC_SecDocPdf)
947   !InsertMacro MUI_DESCRIPTION_TEXT ${SecDocHtml} $(DESC_SecDocHtml)
948 !InsertMacro MUI_FUNCTION_DESCRIPTION_END
949
950 ; Uninstall section
951
952 UninstallText "This will uninstall Bacula. Hit next to continue."
953
954 Section "Uninstall"
955   ; Shutdown any baculum that could be running
956   nsExec::ExecToLog '"$INSTDIR\bin\bacula-fd.exe" /kill'
957   nsExec::ExecToLog '"$INSTDIR\bin\bacula-sd.exe" /kill'
958   nsExec::ExecToLog '"$INSTDIR\bin\bacula-dir.exe" /kill'
959   Sleep 3000
960
961   ReadRegDWORD $R0 HKLM "Software\Bacula" "Service_Bacula-fd"
962   ${If} $R0 = 1
963     ; Remove bacula service
964     nsExec::ExecToLog '"$INSTDIR\bin\bacula-fd.exe" /remove'
965     nsExec::ExecToLog '"$INSTDIR\bin\exchange-fd.dll" /remove'
966   ${EndIf}
967   
968   ReadRegDWORD $R0 HKLM "Software\Bacula" "Service_Bacula-sd"
969   ${If} $R0 = 1
970     ; Remove bacula service
971     nsExec::ExecToLog '"$INSTDIR\bin\bacula-sd.exe" /remove'
972   ${EndIf}
973   
974   ReadRegDWORD $R0 HKLM "Software\Bacula" "Service_Bacula-dir"
975   ${If} $R0 = 1
976     ; Remove bacula service
977     nsExec::ExecToLog '"$INSTDIR\bin\bacula-dir.exe" /remove'
978   ${EndIf}
979   
980   ; remove registry keys
981   DeleteRegKey HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\Bacula"
982   DeleteRegKey HKLM "Software\Bacula"
983
984   ; remove start menu items
985   SetShellVarContext all
986   Delete /REBOOTOK "$SMPROGRAMS\Bacula\*"
987   RMDir "$SMPROGRAMS\Bacula"
988
989   ; remove files and uninstaller (preserving config for now)
990   Delete /REBOOTOK "$INSTDIR\bin\*"
991   Delete /REBOOTOK "$INSTDIR\doc\*"
992   Delete /REBOOTOK "$INSTDIR\*"
993
994   ; Check for existing installation
995   MessageBox MB_YESNO|MB_ICONQUESTION \
996   "Would you like to delete the current configuration files and the working state file?" IDNO NoDel
997     Delete /REBOOTOK "$APPDATA\Bacula\*"
998     Delete /REBOOTOK "$APPDATA\Bacula\Work\*"
999     Delete /REBOOTOK "$APPDATA\Bacula\Spool\*"
1000     Delete /REBOOTOK "$PLUGINSDIR\bacula-*.conf"
1001     Delete /REBOOTOK "$PLUGINSDIR\*console.conf"
1002     Delete /REBOOTOK "$PLUGINSDIR\*conf.in"
1003     Delete /REBOOTOK "$PLUGINSDIR\openssl.exe"
1004     Delete /REBOOTOK "$PLUGINSDIR\libeay32.dll"
1005     Delete /REBOOTOK "$PLUGINSDIR\ssleay32.dll"
1006     Delete /REBOOTOK "$PLUGINSDIR\sed.exe"    
1007     Delete /REBOOTOK "$PLUGINSDIR\pw.txt"     
1008     Delete /REBOOTOK "$PLUGINSDIR\*.sed" 
1009     Delete /REBOOTOK "$PLUGINSDIR\*.cmd"    
1010     Delete /REBOOTOK "$PLUGINSDIR\*.sql"    
1011     RMDir "$APPDATA\Bacula\Work"
1012     RMDir "$APPDATA\Bacula\Spool"
1013     RMDir "$APPDATA\Bacula"
1014 NoDel:
1015
1016   ; remove directories used
1017   RMDir "$INSTDIR\bin"
1018   RMDir "$INSTDIR\doc"
1019   RMDir "$INSTDIR"
1020 SectionEnd
1021
1022 ;
1023 ; $0 - Service Name (ie Bacula-FD)
1024 ; $1 - Service Description (ie Bacula File Daemon)
1025 ; $2 - Install as Service
1026 ; $3 - Start Service now
1027 ;
1028 Function InstallDaemon
1029   Call InstallCommonFiles
1030
1031   WriteRegDWORD HKLM "Software\Bacula" "Service_$0" $2
1032   
1033   ${If} $2 = 1
1034     nsExec::ExecToLog '"$INSTDIR\bin\$0.exe" /install -c "$APPDATA\Bacula\$0.conf"'
1035
1036     ${If} $OsIsNT <> 1
1037       File "Start.bat"
1038       File "Stop.bat"
1039     ${EndIf}
1040
1041     ; Start the service?
1042
1043     ${If} $3 = 1  
1044       ${If} $OsIsNT = 1
1045         nsExec::ExecToLog 'net start $0'
1046       ${Else}
1047         Exec '"$INSTDIR\bin\$0.exe" -c "$APPDATA\Bacula\$0.conf"'
1048       ${EndIf}
1049     ${EndIf}
1050   ${Else}
1051     CreateShortCut "$SMPROGRAMS\Bacula\Start $1.lnk" "$INSTDIR\bin\$0.exe" '-c "$APPDATA\Bacula\$0.conf"' "$INSTDIR\bin\$0.exe" 0
1052   ${EndIf}
1053 FunctionEnd
1054
1055 Function GetComputerName
1056   Push $R0
1057   Push $R1
1058   Push $R2
1059
1060   System::Call "kernel32::GetComputerNameA(t .R0, *i ${NSIS_MAX_STRLEN} R1) i.R2"
1061
1062   ${StrCase} $R0 $R0 "L"
1063
1064   Pop $R2
1065   Pop $R1
1066   Exch $R0
1067 FunctionEnd
1068
1069 !define ComputerNameDnsFullyQualified   3
1070
1071 Function GetHostName
1072   Push $R0
1073   Push $R1
1074   Push $R2
1075
1076   ${If} $OsIsNT = 1
1077     System::Call "kernel32::GetComputerNameExA(i ${ComputerNameDnsFullyQualified}, t .R0, *i ${NSIS_MAX_STRLEN} R1) i.R2 ?e"
1078     ${If} $R2 = 0
1079       Pop $R2
1080       DetailPrint "GetComputerNameExA failed - LastError = $R2"
1081       Call GetComputerName
1082       Pop $R0
1083     ${Else}
1084       Pop $R2
1085     ${EndIf}
1086   ${Else}
1087     Call GetComputerName
1088     Pop $R0
1089   ${EndIf}
1090
1091   Pop $R2
1092   Pop $R1
1093   Exch $R0
1094 FunctionEnd
1095
1096 !define NameUserPrincipal 8
1097
1098 Function GetUserName
1099   Push $R0
1100   Push $R1
1101   Push $R2
1102
1103   ${If} $OsIsNT = 1
1104     System::Call "secur32::GetUserNameExA(i ${NameUserPrincipal}, t .R0, *i ${NSIS_MAX_STRLEN} R1) i.R2 ?e"
1105     ${If} $R2 = 0
1106       Pop $R2
1107       DetailPrint "GetUserNameExA failed - LastError = $R2"
1108       Pop $R0
1109       StrCpy $R0 ""
1110     ${Else}
1111       Pop $R2
1112     ${EndIf}
1113   ${Else}
1114       StrCpy $R0 ""
1115   ${EndIf}
1116
1117   ${If} $R0 == ""
1118     System::Call "advapi32::GetUserNameA(t .R0, *i ${NSIS_MAX_STRLEN} R1) i.R2 ?e"
1119     ${If} $R2 = 0
1120       Pop $R2
1121       DetailPrint "GetUserNameA failed - LastError = $R2"
1122       StrCpy $R0 ""
1123     ${Else}
1124       Pop $R2
1125     ${EndIf}
1126   ${EndIf}
1127
1128   Pop $R2
1129   Pop $R1
1130   Exch $R0
1131 FunctionEnd
1132
1133 Function ConfigEditAndCopy
1134   Push $R1
1135
1136   ${If} ${FileExists} "$0\$1"
1137     StrCpy $R1 ".new"
1138   ${Else}
1139     StrCpy $R1 ""
1140   ${EndIf}
1141
1142   nsExec::ExecToLog '$PLUGINSDIR\sed.exe -f "$PLUGINSDIR\config.sed" -i.bak "$PLUGINSDIR\$1"'
1143   CopyFiles "$PLUGINSDIR\$1" "$0\$1$R1"
1144
1145   Pop $R1
1146 FunctionEnd
1147
1148 Function FindDatabaseApps
1149   Push $R1
1150
1151   ReadRegStr $0 HKLM "Software\MySQL AB\MySQL Server 5.0" "Location"
1152
1153   ${If} $0 != ""
1154     Call RemoveTrailingSlash
1155     StrCpy $MySQLPath $0
1156     ReadRegStr $0 HKLM "Software\MySQL AB\MySQL Server 5.0" "Version"
1157     StrCpy $MySQLVersion $0
1158   ${EndIf}
1159
1160   EnumRegKey $R1 HKLM "Software\PostgreSQL\Installations" 0
1161   ${If} $R1 != ""
1162     ReadRegStr $0 HKLM "Software\PostgreSQL\Installations\$R1" "Base Directory"
1163     Call RemoveTrailingSlash
1164     StrCpy $PostgreSQLPath $0
1165     ReadRegStr $0 HKLM "Software\PostgreSQL\Installations\$R1" "Version"
1166     StrCpy $PostgreSQLVersion $0
1167   ${EndIf}
1168
1169   Pop $R1
1170 FunctionEnd
1171
1172 Function RemoveTrailingSlash
1173   Push $R1
1174   StrCpy $R1 $0 "" -1
1175   ${If} $R1 == "\"
1176     StrCpy $0 $0 -1
1177   ${EndIf}
1178   Pop $R1
1179 FunctionEnd
1180
1181 Function IsDirectorSelected
1182   Push $R0
1183   SectionGetFlags ${SecDirectorDaemon} $R0
1184   IntOp $R0 $R0 & ${SF_SELECTED}
1185   Exch $R0
1186 FunctionEnd
1187
1188 Function GetSelectedComponents
1189   Push $R0
1190   StrCpy $R0 0
1191   ${If} ${SectionIsSelected} ${SecFileDaemon}
1192     IntOp $R0 $R0 | ${ComponentFile}
1193   ${EndIf}
1194   ${If} ${SectionIsSelected} ${SecStorageDaemon}
1195     IntOp $R0 $R0 | ${ComponentStorage}
1196   ${EndIf}
1197   ${If} ${SectionIsSelected} ${SecDirectorDaemon}
1198     IntOp $R0 $R0 | ${ComponentDirector}
1199   ${EndIf}
1200   ${If} ${SectionIsSelected} ${SecConsole}
1201     IntOp $R0 $R0 | ${ComponentTextConsole}
1202   ${EndIf}
1203   ${If} ${SectionIsSelected} ${SecBatConsole}
1204     IntOp $R0 $R0 | ${ComponentBatConsole}
1205   ${EndIf}
1206   ${If} ${SectionIsSelected} ${SecWxConsole}
1207     IntOp $R0 $R0 | ${ComponentGUIConsole}
1208   ${EndIf}
1209   ${If} ${SectionIsSelected} ${SecDocPdf}
1210     IntOp $R0 $R0 | ${ComponentPDFDocs}
1211   ${EndIf}
1212   ${If} ${SectionIsSelected} ${SecDocHtml}
1213     IntOp $R0 $R0 | ${ComponentHTMLDocs}
1214   ${EndIf}
1215   Exch $R0
1216 FunctionEnd
1217
1218 Function PageComponentsShow
1219   ${If} $OsIsNT <> 1
1220     Call DisableServerSections
1221   ${EndIf}
1222
1223   Call SelectPreviousComponents
1224   Call UpdateComponentUI
1225 FunctionEnd
1226
1227 Function PageDirectoryPre
1228   ${If} $AutomaticInstall = 1
1229   ${OrIf} $InstallType = ${UpgradeInstall}
1230     Abort
1231   ${EndIf}
1232 FunctionEnd
1233
1234 Function LeaveInstallPage
1235   Push "$INSTDIR\install.log"
1236   Call DumpLog
1237 FunctionEnd
1238
1239 Function EnterWriteTemplates
1240   Push $R0
1241   Push $R1
1242
1243   Call GetSelectedComponents
1244   Pop $R0
1245
1246   IntOp $R0 $R0 & ${ComponentDirector}
1247   IntOp $R1 $NewComponents & ${ComponentsFileAndStorage}
1248
1249   ${If} $R0 <> 0
1250   ${OrIf} $R1 = 0
1251     Pop $R1
1252     Pop $R0
1253     Abort
1254   ${EndIf}
1255
1256   IntOp $R0 $NewComponents & ${ComponentFile}
1257   ${If} $R0 = 0
1258     WriteINIStr "$PLUGINSDIR\WriteTemplates.ini" "Field 2" State 0
1259     WriteINIStr "$PLUGINSDIR\WriteTemplates.ini" "Field 2" Flags DISABLED
1260     DeleteINIStr "$PLUGINSDIR\WriteTemplates.ini" "Field 3" State
1261     WriteINIStr "$PLUGINSDIR\WriteTemplates.ini" "Field 3" Flags REQ_SAVE|FILE_EXPLORER|WARN_IF_EXIST|DISABLED
1262   ${Else}
1263     WriteINIStr "$PLUGINSDIR\WriteTemplates.ini" "Field 2" State 1
1264     DeleteINIStr "$PLUGINSDIR\WriteTemplates.ini" "Field 2" Flags
1265     WriteINIStr "$PLUGINSDIR\WriteTemplates.ini" "Field 3" State "C:\$ConfigClientName.conf"
1266     WriteINIStr "$PLUGINSDIR\WriteTemplates.ini" "Field 5" Flags REQ_SAVE|FILE_EXPLORER|WARN_IF_EXIST
1267   ${EndIf}
1268
1269   IntOp $R0 $NewComponents & ${ComponentStorage}
1270   ${If} $R0 = 0
1271     WriteINIStr "$PLUGINSDIR\WriteTemplates.ini" "Field 4" State 0
1272     WriteINIStr "$PLUGINSDIR\WriteTemplates.ini" "Field 4" Flags DISABLED
1273     DeleteINIStr "$PLUGINSDIR\WriteTemplates.ini" "Field 5" State
1274     WriteINIStr "$PLUGINSDIR\WriteTemplates.ini" "Field 5" Flags REQ_SAVE|FILE_EXPLORER|WARN_IF_EXIST|DISABLED
1275   ${Else}
1276     WriteINIStr "$PLUGINSDIR\WriteTemplates.ini" "Field 4" State 1
1277     DeleteINIStr "$PLUGINSDIR\WriteTemplates.ini" "Field 4" Flags
1278     WriteINIStr "$PLUGINSDIR\WriteTemplates.ini" "Field 5" State "C:\$ConfigStorageName.conf"
1279     WriteINIStr "$PLUGINSDIR\WriteTemplates.ini" "Field 5" Flags REQ_SAVE|FILE_EXPLORER|WARN_IF_EXIST
1280   ${EndIf}
1281
1282   !InsertMacro MUI_HEADER_TEXT "$(TITLE_WriteTemplates)" "$(SUBTITLE_WriteTemplates)"
1283   !InsertMacro MUI_INSTALLOPTIONS_DISPLAY "WriteTemplates.ini"
1284
1285   !InsertMacro MUI_INSTALLOPTIONS_READ $R0 "WriteTemplates.ini" "Field 2" State
1286   ${If} $R0 <> 0
1287     File "/oname=$PLUGINSDIR\client.conf.in" "client.conf.in"
1288
1289     nsExec::ExecToLog '$PLUGINSDIR\sed.exe -f "$PLUGINSDIR\config.sed" -i.bak "$PLUGINSDIR\client.conf.in"'
1290     !InsertMacro MUI_INSTALLOPTIONS_READ $R0 "WriteTemplates.ini" "Field 3" State
1291     ${If} $R0 != ""
1292       CopyFiles "$PLUGINSDIR\client.conf.in" "$R0"
1293     ${EndIf}
1294   ${EndIf}
1295
1296   !InsertMacro MUI_INSTALLOPTIONS_READ $R0 "WriteTemplates.ini" "Field 4" State
1297   ${If} $R0 <> 0
1298     File "/oname=$PLUGINSDIR\storage.conf.in" "storage.conf.in"
1299
1300     nsExec::ExecToLog '$PLUGINSDIR\sed.exe -f "$PLUGINSDIR\config.sed" -i.bak "$PLUGINSDIR\storage.conf.in"'
1301     !InsertMacro MUI_INSTALLOPTIONS_READ $R0 "WriteTemplates.ini" "Field 5" State
1302     ${If} $R0 != ""
1303       CopyFiles "$PLUGINSDIR\storage.conf.in" "$R0"
1304     ${EndIf}
1305   ${EndIf}
1306
1307   Pop $R1
1308   Pop $R0
1309 FunctionEnd
1310
1311 Function SelectPreviousComponents
1312   ${If} $InstallType <> ${NewInstall}
1313     IntOp $R1 $PreviousComponents & ${ComponentFile}
1314     ${If} $R1 <> 0
1315       !InsertMacro SelectSection ${SecFileDaemon}
1316       !InsertMacro SetSectionFlag ${SecFileDaemon} ${SF_RO}
1317     ${Else}
1318       !InsertMacro UnselectSection ${SecFileDaemon}
1319       !InsertMacro ClearSectionFlag ${SecFileDaemon} ${SF_RO}
1320     ${EndIf}
1321     IntOp $R1 $PreviousComponents & ${ComponentStorage}
1322     ${If} $R1 <> 0
1323       !InsertMacro SelectSection ${SecStorageDaemon}
1324       !InsertMacro SetSectionFlag ${SecStorageDaemon} ${SF_RO}
1325     ${Else}
1326       !InsertMacro UnselectSection ${SecStorageDaemon}
1327       !InsertMacro ClearSectionFlag ${SecStorageDaemon} ${SF_RO}
1328     ${EndIf}
1329     IntOp $R1 $PreviousComponents & ${ComponentDirector}
1330     ${If} $R1 <> 0
1331       !InsertMacro SelectSection ${SecDirectorDaemon}
1332       !InsertMacro SetSectionFlag ${SecDirectorDaemon} ${SF_RO}
1333     ${Else}
1334       !InsertMacro UnselectSection ${SecDirectorDaemon}
1335       !InsertMacro ClearSectionFlag ${SecDirectorDaemon} ${SF_RO}
1336     ${EndIf}
1337     IntOp $R1 $PreviousComponents & ${ComponentTextConsole}
1338     ${If} $R1 <> 0
1339       !InsertMacro SelectSection ${SecConsole}
1340       !InsertMacro SetSectionFlag ${SecConsole} ${SF_RO}
1341     ${Else}
1342       !InsertMacro UnselectSection ${SecConsole}
1343       !InsertMacro ClearSectionFlag ${SecConsole} ${SF_RO}
1344     ${EndIf}
1345     IntOp $R1 $PreviousComponents & ${ComponentBatConsole}
1346     ${If} $R1 <> 0
1347       !InsertMacro SelectSection ${SecBatConsole}
1348       !InsertMacro SetSectionFlag ${SecBatConsole} ${SF_RO}
1349     ${Else}
1350       !InsertMacro UnselectSection ${SecBatConsole}
1351       !InsertMacro ClearSectionFlag ${SecBatConsole} ${SF_RO}
1352     ${EndIf}
1353     IntOp $R1 $PreviousComponents & ${ComponentGUIConsole}
1354     ${If} $R1 <> 0
1355       !InsertMacro SelectSection ${SecWxConsole}
1356       !InsertMacro SetSectionFlag ${SecWxConsole} ${SF_RO}
1357     ${Else}
1358       !InsertMacro UnselectSection ${SecWxConsole}
1359       !InsertMacro ClearSectionFlag ${SecWxConsole} ${SF_RO}
1360     ${EndIf}
1361     IntOp $R1 $PreviousComponents & ${ComponentPDFDocs}
1362     ${If} $R1 <> 0
1363       !InsertMacro SelectSection ${SecDocPdf}
1364       !InsertMacro SetSectionFlag ${SecDocPdf} ${SF_RO}
1365     ${Else}
1366       !InsertMacro UnselectSection ${SecDocPdf}
1367       !InsertMacro ClearSectionFlag ${SecDocPdf} ${SF_RO}
1368     ${EndIf}
1369     IntOp $R1 $PreviousComponents & ${ComponentHTMLDocs}
1370     ${If} $R1 <> 0
1371       !InsertMacro SelectSection ${SecDocHtml}
1372       !InsertMacro SetSectionFlag ${SecDocHtml} ${SF_RO}
1373     ${Else}
1374       !InsertMacro UnselectSection ${SecDocHtml}
1375       !InsertMacro ClearSectionFlag ${SecDocHtml} ${SF_RO}
1376     ${EndIf}
1377   ${EndIf}
1378 FunctionEnd
1379
1380 Function DisableServerSections
1381   !InsertMacro UnselectSection ${SecGroupServer}
1382   !InsertMacro SetSectionFlag  ${SecGroupServer} ${SF_RO}
1383   !InsertMacro UnselectSection ${SecStorageDaemon}
1384   !InsertMacro SetSectionFlag  ${SecStorageDaemon} ${SF_RO}
1385   !InsertMacro UnselectSection ${SecDirectorDaemon}
1386   !InsertMacro SetSectionFlag  ${SecDirectorDaemon} ${SF_RO}
1387 FunctionEnd
1388
1389 Function UpdateComponentUI
1390   Push $R0
1391   Push $R1
1392
1393   Call GetSelectedComponents
1394   Pop $R0
1395
1396   IntOp $R1 $R0 ^ $PreviousComponents
1397   IntOp $NewComponents $R0 & $R1
1398
1399   ${If} $InstallType <> ${NewInstall}
1400     IntOp $R1 $NewComponents & ${ComponentFile}
1401     ${If} $R1 <> 0
1402       !InsertMacro SetSectionFlag ${SecFileDaemon} ${SF_BOLD}
1403     ${Else}
1404       !InsertMacro ClearSectionFlag ${SecFileDaemon} ${SF_BOLD}
1405     ${EndIf}
1406     IntOp $R1 $NewComponents & ${ComponentStorage}
1407     ${If} $R1 <> 0
1408       !InsertMacro SetSectionFlag ${SecStorageDaemon} ${SF_BOLD}
1409     ${Else}
1410       !InsertMacro ClearSectionFlag ${SecStorageDaemon} ${SF_BOLD}
1411     ${EndIf}
1412     IntOp $R1 $NewComponents & ${ComponentDirector}
1413     ${If} $R1 <> 0
1414       !InsertMacro SetSectionFlag ${SecDirectorDaemon} ${SF_BOLD}
1415     ${Else}
1416       !InsertMacro ClearSectionFlag ${SecDirectorDaemon} ${SF_BOLD}
1417     ${EndIf}
1418     IntOp $R1 $NewComponents & ${ComponentTextConsole}
1419     ${If} $R1 <> 0
1420       !InsertMacro SetSectionFlag ${SecConsole} ${SF_BOLD}
1421     ${Else}
1422       !InsertMacro ClearSectionFlag ${SecConsole} ${SF_BOLD}
1423     ${EndIf}
1424     IntOp $R1 $NewComponents & ${ComponentBatConsole}
1425     ${If} $R1 <> 0
1426       !InsertMacro SetSectionFlag ${SecBatConsole} ${SF_BOLD}
1427     ${Else}
1428       !InsertMacro ClearSectionFlag ${SecBatConsole} ${SF_BOLD}
1429     ${EndIf}
1430     IntOp $R1 $NewComponents & ${ComponentGUIConsole}
1431     ${If} $R1 <> 0
1432       !InsertMacro SetSectionFlag ${SecWxConsole} ${SF_BOLD}
1433     ${Else}
1434       !InsertMacro ClearSectionFlag ${SecWxConsole} ${SF_BOLD}
1435     ${EndIf}
1436     IntOp $R1 $NewComponents & ${ComponentPDFDocs}
1437     ${If} $R1 <> 0
1438       !InsertMacro SetSectionFlag ${SecDocPdf} ${SF_BOLD}
1439     ${Else}
1440       !InsertMacro ClearSectionFlag ${SecDocPdf} ${SF_BOLD}
1441     ${EndIf}
1442     IntOp $R1 $NewComponents & ${ComponentHTMLDocs}
1443     ${If} $R1 <> 0
1444       !InsertMacro SetSectionFlag ${SecDocHtml} ${SF_BOLD}
1445     ${Else}
1446       !InsertMacro ClearSectionFlag ${SecDocHtml} ${SF_BOLD}
1447     ${EndIf}
1448   ${EndIf}
1449
1450   GetDlgItem $R0 $HWNDPARENT 1
1451
1452   IntOp $R1 $NewComponents & ${ComponentsRequiringUserConfig}
1453   ${If} $R1 = 0
1454     SendMessage $R0 ${WM_SETTEXT} 0 "STR:Install"
1455   ${Else}
1456     SendMessage $R0 ${WM_SETTEXT} 0 "STR:&Next >"
1457   ${EndIf}
1458
1459   Pop $R1
1460   Pop $R0
1461 FunctionEnd
1462
1463 !include "InstallType.nsh"
1464 !include "ConfigPage1.nsh"
1465 !include "ConfigPage2.nsh"
1466 !include "DumpLog.nsh"