]> git.sur5r.net Git - bacula/bacula/blob - bacula/src/win32/winbacula.nsi.in
Complete port to Windows
[bacula/bacula] / bacula / src / win32 / winbacula.nsi.in
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 wx-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 ; Pretty much rewritten
26 ; Use LogicLib.nsh
27 ; Added Bacula-SD and Bacula-DIR
28 ; Replaced ParameterGiven with standard GetOptions
29
30 ;
31 ; Command line options:
32 ;
33 ; /cygwin     -  do cygwin install into c:\cygwin\bacula
34 ; /service    - 
35 ; /start
36
37 !define PRODUCT "Bacula"
38 !define VERSION "@VERSION@"
39
40 !define PTHREADS_DIR    "..\..\..\depkgs-win32\pthreads\release"
41 !define MINGW_DIR       "C:\MinGW\bin"
42
43 !define BUILD_TOOLS     "MinGW"
44
45 ;!define BUILD_TOOLS     "VC8"
46 ;!define VC_REDIST_DIR "C:\Program Files\Microsoft Visual Studio 8\VC\redist\x86\Microsoft.VC80.CRT"
47
48 ;
49 ; Include the Modern UI
50 ;
51 !include "MUI.nsh"
52 !include "LogicLib.nsh"
53 !include "FileFunc.nsh"
54
55 ;
56 ; Basics
57 ;
58   Name "Bacula"
59   OutFile "winbacula-${VERSION}.exe"
60   SetCompressor lzma
61   InstallDir "$PROGRAMFILES\Bacula"
62   InstallDirRegKey HKLM Software\Bacula InstallLocation
63
64   InstType "Client"
65   InstType "Server"
66   InstType "Full"
67
68 ;
69 ; Pull in pages
70 ;
71
72  !insertmacro MUI_PAGE_WELCOME
73 ;  !insertmacro MUI_PAGE_LICENSE "..\..\LICENSE"
74  !insertmacro MUI_PAGE_COMPONENTS
75  !insertmacro MUI_PAGE_DIRECTORY
76  Page custom EnterClientConfig LeaveClientConfig
77  Page custom EnterOptions
78  !insertmacro MUI_PAGE_INSTFILES
79  !insertmacro MUI_PAGE_FINISH
80
81  !insertmacro MUI_UNPAGE_WELCOME
82  !insertmacro MUI_UNPAGE_CONFIRM
83  !insertmacro MUI_UNPAGE_INSTFILES
84  !insertmacro MUI_UNPAGE_FINISH
85
86  !define      MUI_ABORTWARNING
87
88  !insertmacro MUI_LANGUAGE "English"
89
90  !insertmacro GetParameters
91  !insertmacro GetOptions
92
93 DirText "Setup will install Bacula ${VERSION} to the directory specified below. To install in a different folder, click Browse and select another folder.$\n$\nNote to CYGWIN users: please choose your CYGWIN root directory."
94
95 ;
96 ; Reserve Files
97 ;
98  ReserveFile "ClientConfig.ini"
99  !insertmacro MUI_RESERVEFILE_INSTALLOPTIONS
100 ;
101 ; Global Variables
102 ;
103 Var OptCygwin
104 Var OptService
105 Var OptStart
106 Var OptSilent
107
108 Var DependenciesDone
109
110 Var OsIsNT
111
112 Var ConfigClientName
113 Var ConfigClientPort
114 Var ConfigMaxJobs
115 Var ConfigDirectorName
116 Var ConfigDirectorPW
117 Var ConfigMonitorName
118 Var ConfigMonitorPW
119
120 Var OptionsClientService
121 Var OptionsClientStart
122 Var OptionsStorageService
123 Var OptionsStorageStart
124 Var OptionsDirectorService
125 Var OptionsDirectorStart
126 Var OptionsDirectorDB
127
128 Var HDLG
129 Var HCTL
130
131 Function .onInit
132   Push $R0
133   Push $R1
134   
135   ; Process Command Line Options
136   StrCpy $OptCygwin 0
137   StrCpy $OptService 0
138   StrCpy $OptStart 0
139   StrCpy $OptSilent 0
140   StrCpy $DependenciesDone 0
141   StrCpy $OsIsNT 0
142   
143   ${GetParameters} $R0
144   
145   ClearErrors
146   ${GetOptions} $R0 "/cygwin" $R1
147   IfErrors +2
148     StrCpy $OptCygwin 1
149   
150   ClearErrors
151   ${GetOptions} $R0 "/service" $R1
152   IfErrors +2
153     StrCpy $OptService 1
154
155   ClearErrors
156   ${GetOptions} $R0 "/start" $R1
157   IfErrors +2
158     StrCpy $OptStart 1
159
160   IfSilent 0 +2
161     StrCpy $OptSilent 1
162     
163   ${If} $OptCygwin = 1
164     StrCpy $INSTDIR "C:\cygwin\bacula"
165   ${EndIf}
166
167   ReadRegStr $R0 HKLM "SOFTWARE\Microsoft\Windows NT\CurrentVersion" CurrentVersion
168   ${If} $R0 != ""
169     StrCpy $OsIsNT 1
170   ${EndIf}
171
172   !insertmacro MUI_INSTALLOPTIONS_EXTRACT "ClientConfig.ini"
173   
174   Pop $R1
175   Pop $R0
176 FunctionEnd
177
178 Function CopyDependencies
179   SetOutPath "$INSTDIR\bin"
180
181   ${If} $DependenciesDone = 0
182 !if BUILD_TOOLS == "VC8"
183     File "${PTHREADS_DIR}\pthreadVCE.dll"
184     File "${VC_REDIST_DIR}\msvcm80.dll"
185     File "${VC_REDIST_DIR}\msvcp80.dll"
186     File "${VC_REDIST_DIR}\msvcr80.dll"
187     File "${VC_REDIST_DIR}\Microsoft.VC80.CRT.manifest"
188 !endif
189 !if BUILD_TOOLS == "MinGW"
190     File "${PTHREADS_DIR}\pthreadGCE.dll"
191     File "${MINGW_DIR}\mingwm10.dll"
192 !endif
193     StrCpy $DependenciesDone 1
194   ${EndIf}
195 FunctionEnd
196
197 Section "-Initialize"
198   ; Create Start Menu Directory
199
200   WriteRegStr HKLM Software\Bacula InstallLocation "$INSTDIR"
201
202   SetShellVarContext all
203   CreateDirectory "$SMPROGRAMS\Bacula"
204
205   CreateDirectory "$INSTDIR"
206   CreateDirectory "$INSTDIR\bin"
207   CreateDirectory "$APPDATA\Bacula"
208
209   File ..\..\LICENSE
210   Delete /REBOOTOK "$INSTDIR\bin\License.txt"
211 SectionEnd
212
213 SectionGroup "Client"
214
215 Section "File Service" SecFileDaemon
216   SectionIn 1 2 3
217
218   SetOutPath "$INSTDIR\bin"
219   File "Release\bacula-fd.exe"
220
221   StrCpy $R0 0
222   StrCpy $R1 "$APPDATA\Bacula\bacula-fd.conf"
223   IfFileExists $R1 0 +3
224     StrCpy $R0 1
225     StrCpy $R1 "$R1.new"
226     
227   File /oname=$R1 ..\filed\bacula-fd.conf.in
228   
229   ${If} $OptSilent <> 1
230   ${AndIf} $R0 <> 1
231     MessageBox MB_OK \
232         "Please edit the configuration file $R1 to fit your installation. When you click the OK button Wordpad will open to allow you to do this. Be sure to save your changes before closing Wordpad."
233     Exec 'write "$R1"'  ; spawn wordpad with the file to be edited
234   ${EndIf}
235   ${If} $OsIsNT = 1
236     ExecWait 'cmd.exe /C echo Y|cacls "$R1" /G SYSTEM:F Administrators:F'
237   ${EndIf}
238
239   StrCpy $0 bacula-fd
240   StrCpy $1 "File Service"
241   StrCpy $2 $OptionsClientService
242   StrCpy $3 $OptionsClientStart
243   
244   Call InstallDaemon
245
246   CreateShortCut "$SMPROGRAMS\Bacula\Edit Client Configuration.lnk" "write.exe" '"$APPDATA\Bacula\bacula-fd.conf"'
247 SectionEnd
248
249 SectionGroupEnd
250
251 SectionGroup "Server"
252
253 Section "Storage Service" SecStorageDaemon
254   SectionIn 2 3
255   
256   SetOutPath "$INSTDIR\bin"
257   File "Release\bacula-sd.exe"
258   File "Release\bcopy.exe"
259   File "Release\bextract.exe"
260   File "Release\bls.exe"
261   File "Release\bscan.exe"
262   File "Release\btape.exe"
263
264   StrCpy $R0 0
265   StrCpy $R1 "$APPDATA\Bacula\bacula-sd.conf"
266   IfFileExists $R1 0 +3
267     StrCpy $R0 1
268     StrCpy $R1 "$R1.new"
269     
270   File /oname=$R1 ..\stored\bacula-sd.conf.in
271   
272   ${If} $OptSilent <> 1
273   ${AndIf} $R0 <> 1
274     MessageBox MB_OK \
275         "Please edit the configuration file $R1 to fit your installation. When you click the OK button Wordpad will open to allow you to do this. Be sure to save your changes before closing Wordpad."
276     Exec 'write "$R1"'  ; spawn wordpad with the file to be edited
277   ${EndIf}
278   ${If} $OsIsNT = 1
279     ExecWait 'cmd.exe /C echo Y|cacls "$R1" /G SYSTEM:F Administrators:F'
280   ${EndIf}
281
282   StrCpy $0 bacula-sd
283   StrCpy $1 "Storage Service"
284   StrCpy $2 $OptionsStorageService
285   StrCpy $3 $OptionsStorageStart
286   Call InstallDaemon
287
288   CreateShortCut "$SMPROGRAMS\Bacula\Edit Storage Configuration.lnk" "write.exe" '"$APPDATA\Bacula\bacula-sd.conf"'
289 SectionEnd
290
291 Section "Director Service" SecDirectorDaemon
292   SectionIn 2 3
293
294   SetOutPath "$INSTDIR\bin"
295   File "Release\bacula-dir.exe"
296   File "Release\dbcheck.exe"
297
298   StrCpy $R0 0
299   StrCpy $R1 "$APPDATA\Bacula\bacula-dir.conf"
300   IfFileExists $R1 0 +3
301     StrCpy $R0 1
302     StrCpy $R1 "$R1.new"
303     
304   File /oname=$R1 ..\dird\bacula-dir.conf.in
305   
306   ${If} $OptSilent <> 1
307   ${AndIf} $R0 <> 1
308     MessageBox MB_OK \
309         "Please edit the configuration file $R1 to fit your installation. When you click the OK button Wordpad will open to allow you to do this. Be sure to save your changes before closing Wordpad."
310     Exec 'write "$R1"'  ; spawn wordpad with the file to be edited
311   ${EndIf}
312   ${If} $OsIsNT = 1
313     ExecWait 'cmd.exe /C echo Y|cacls "$R1" /G SYSTEM:F Administrators:F'
314   ${EndIf}
315
316   StrCpy $0 bacula-dir
317   StrCpy $1 "Director Service"
318   StrCpy $2 $OptionsDirectorService
319   StrCpy $3 $OptionsDirectorStart
320   Call InstallDaemon
321
322   CreateShortCut "$SMPROGRAMS\Bacula\Edit Director Configuration.lnk" "write.exe" '"$APPDATA\Bacula\bacula-dir.conf"'
323 SectionEnd
324
325 SectionGroupEnd
326
327 SectionGroup "Consoles"
328
329 Section "Command Console" SecConsole
330   SectionIn 3
331
332   File Release\bconsole.exe
333   Call CopyDependencies
334
335   StrCpy $R0 0
336   StrCpy $R1 "$APPDATA\Bacula\bconsole.conf"
337   IfFileExists $R1 0 +3
338     StrCpy $R0 1
339     StrCpy $R1 "$R1.new"
340     
341   File /oname=$R1 ..\console\bconsole.conf.in
342   
343   ${If} $OptSilent <> 1
344   ${AndIf} $R0 <> 1
345     MessageBox MB_OK \
346         "Please edit the configuration file $R1 to fit your installation. When you click the OK button Wordpad will open to allow you to do this. Be sure to save your changes before closing Wordpad."
347     Exec 'write "$R1"'  ; spawn wordpad with the file to be edited
348   ${EndIf}
349   ${If} $OsIsNT = 1
350     ExecWait 'cmd.exe /C echo Y|cacls "$R1" /G SYSTEM:F Administrators:F'
351   ${EndIf}
352
353   CreateShortCut "$SMPROGRAMS\Bacula\Edit Command Console Configuration.lnk" "write.exe" '"$APPDATA\Bacula\bconsole.conf"'
354
355 SectionEnd
356
357 Section "Graphical Console" SecWxConsole
358   SectionIn 1 2 3
359   
360   File Release\wx-console.exe
361   Call CopyDependencies
362
363   StrCpy $R0 0
364   StrCpy $R1 "$APPDATA\Bacula\wx-console.conf"
365   IfFileExists $R1 0 +3
366     StrCpy $R0 1
367     StrCpy $R1 "$R1.new"
368     
369   File /oname=$R1 ..\wx-console\wx-console.conf.in
370   
371   ${If} $OptSilent <> 1
372   ${AndIf} $R0 <> 1
373     MessageBox MB_OK \
374         "Please edit the configuration file $R1 to fit your installation. When you click the OK button Wordpad will open to allow you to do this. Be sure to save your changes before closing Wordpad."
375     Exec 'write "$R1"'  ; spawn wordpad with the file to be edited
376   ${EndIf}
377   ${If} $OsIsNT = 1
378     ExecWait 'cmd.exe /C echo Y|cacls "$R1" /G SYSTEM:F Administrators:F'
379   ${EndIf}
380
381   ; Create Start Menu entry
382   CreateShortCut "$SMPROGRAMS\Bacula\Console.lnk" "$INSTDIR\bin\wx-console.exe" '-c "$APPDATA\Bacula\wx-console.conf"' "$INSTDIR\bin\wx-console.exe" 0
383   CreateShortCut "$SMPROGRAMS\Bacula\Edit Graphical Console Configuration.lnk" "write.exe" '"$APPDATA\Bacula\wx-console.conf"'
384 SectionEnd
385
386 SectionGroupEnd
387
388 SectionGroup "Documentation"
389
390 Section "Documentation (Acrobat Format)" SecDocPdf
391   SectionIn 1 2 3
392
393   SetOutPath "$INSTDIR\doc"
394   CreateDirectory "$INSTDIR\doc"
395   File ..\..\..\docs\manual\bacula.pdf
396   CreateShortCut "$SMPROGRAMS\Bacula\Manual.lnk" '"$INSTDIR\doc\bacula.pdf"'
397 SectionEnd
398
399 Section "Documentation (HTML Format)" SecDocHtml
400   SectionIn 3
401
402   SetOutPath "$INSTDIR\doc"
403   CreateDirectory "$INSTDIR\doc"
404   File ..\..\..\docs\manual\bacula\*.html
405   File ..\..\..\docs\manual\bacula\*.png
406   File ..\..\..\docs\manual\bacula\*.css
407   CreateShortCut "$SMPROGRAMS\Bacula\Manual (HTML).lnk" '"$INSTDIR\doc\bacula.html"'
408 SectionEnd
409
410 SectionGroupEnd
411
412 Section "-Write Installer"
413   ; Write the uninstall keys for Windows & create Start Menu entry
414   WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\Bacula" "DisplayName" "Bacula"
415   WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\Bacula" "UninstallString" '"$INSTDIR\uninstall.exe"'
416   WriteUninstaller "$INSTDIR\Uninstall.exe"
417   CreateShortCut "$SMPROGRAMS\Bacula\Uninstall Bacula.lnk" "$INSTDIR\Uninstall.exe" "" "$INSTDIR\Uninstall.exe" 0
418 SectionEnd
419
420 ;
421 ; Extra Page descriptions
422 ;
423
424   LangString DESC_SecFileDaemon ${LANG_ENGLISH} "Install Bacula File Daemon on this system."
425   LangString DESC_SecStorageDaemon ${LANG_ENGLISH} "Install Bacula Storage Daemon on this system."
426   LangString DESC_SecDirectorDaemon ${LANG_ENGLISH} "Install Bacula Director Daemon on this system."
427   LangString DESC_SecConsole ${LANG_ENGLISH} "Install command console program on this system."
428   LangString DESC_SecWxConsole ${LANG_ENGLISH} "Install graphical console program on this system."
429   LangString DESC_SecDocPdf ${LANG_ENGLISH} "Install documentation in Acrobat format on this system."
430   LangString DESC_SecDocHtml ${LANG_ENGLISH} "Install documentation in HTML format on this system."
431
432   LangString TITLE_ClientConfig ${LANG_ENGLISH} "Configure Client"
433   LangString SUBTITLE_ClientConfig ${LANG_ENGLISH} "Create initial configuration for Client."
434
435   LangString TITLE_Options ${LANG_ENGLISH} "Options"
436   LangString SUBTITLE_Options ${LANG_ENGLISH} "Set installation options."
437
438   !insertmacro MUI_FUNCTION_DESCRIPTION_BEGIN
439     !insertmacro MUI_DESCRIPTION_TEXT ${SecFileDaemon} $(DESC_SecFileDaemon)
440     !insertmacro MUI_DESCRIPTION_TEXT ${SecStorageDaemon} $(DESC_SecStorageDaemon)
441     !insertmacro MUI_DESCRIPTION_TEXT ${SecDirectorDaemon} $(DESC_SecDirectorDaemon)
442     !insertmacro MUI_DESCRIPTION_TEXT ${SecConsole} $(DESC_SecConsole)
443     !insertmacro MUI_DESCRIPTION_TEXT ${SecWxConsole} $(DESC_SecWxConsole)
444     !insertmacro MUI_DESCRIPTION_TEXT ${SecDocPdf} $(DESC_SecDocPdf)
445     !insertmacro MUI_DESCRIPTION_TEXT ${SecDocHtml} $(DESC_SecDocHtml)
446   !insertmacro MUI_FUNCTION_DESCRIPTION_END
447
448 ; Uninstall section
449
450 UninstallText "This will uninstall Bacula. Hit next to continue."
451
452 Section "Uninstall"
453   ; Shutdown any baculum that could be running
454   ExecWait '"$INSTDIR\bin\bacula-fd.exe" /kill'
455   ExecWait '"$INSTDIR\bin\bacula-sd.exe" /kill'
456   ExecWait '"$INSTDIR\bin\bacula-dir.exe" /kill'
457
458   ReadRegDWORD $R0 HKLM "Software\Bacula" "Installed_Bacula-fd"
459   ${If} $R0 = 1
460     ; Remove bacula service
461     ExecWait '"$INSTDIR\bin\bacula-fd.exe" /remove'
462   ${EndIf}
463   
464   ReadRegDWORD $R0 HKLM "Software\Bacula" "Installed_Bacula-sd"
465   ${If} $R0 = 1
466     ; Remove bacula service
467     ExecWait '"$INSTDIR\bin\bacula-sd.exe" /remove'
468   ${EndIf}
469   
470   ReadRegDWORD $R0 HKLM "Software\Bacula" "Installed_Bacula-dir"
471   ${If} $R0 = 1
472     ; Remove bacula service
473     ExecWait '"$INSTDIR\bin\bacula-dir.exe" /remove'
474   ${EndIf}
475   
476   ; remove registry keys
477   DeleteRegKey HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\Bacula"
478   DeleteRegKey HKLM "Software\Bacula"
479
480   ; remove start menu items
481   SetShellVarContext all
482   Delete /REBOOTOK "$SMPROGRAMS\Bacula\*"
483   RMDir "$SMPROGRAMS\Bacula"
484
485   ; remove files and uninstaller (preserving config for now)
486   Delete /REBOOTOK "$INSTDIR\bin\*.*"
487   Delete /REBOOTOK "$INSTDIR\doc\*.*"
488   Delete /REBOOTOK "$INSTDIR\Uninstall.exe"
489
490   ; Check for existing installation
491   MessageBox MB_YESNO|MB_ICONQUESTION \
492   "Would you like to delete the current configuration files and the working state file?" IDNO +3
493     Delete /REBOOTOK "$APPDATA\Bacula\*"
494     RMDir "$APPDATA\Bacula"
495
496   ; remove directories used
497   RMDir "$INSTDIR\bin"
498   RMDir "$INSTDIR\doc"
499   RMDir "$INSTDIR"
500 SectionEnd
501
502 Function EnterClientConfig
503   SectionGetFlags ${SecFileDaemon} $R0
504   IntOp $R0 $R0 & 1
505   
506   SectionGetFlags ${SecStorageDaemon} $R1
507   IntOp $R1 $R1 & 1
508   
509   SectionGetFlags ${SecDirectorDaemon} $R2
510   IntOp $R2 $R2 & 1
511   
512   ${If} $R0 = 0
513   ${OrIf} $R1 = 1
514   ${OrIf} $R2 = 1
515     Abort
516   ${EndIf}
517   
518   !insertmacro MUI_HEADER_TEXT "$(TITLE_ClientConfig)" "$(SUBTITLE_ClientConfig)"
519   !insertmacro MUI_INSTALLOPTIONS_INITDIALOG "ClientConfig.ini"
520   Pop $HDLG ;HWND of dialog
521
522   ; Initialize Controls
523   ; Client Name
524   !insertmacro MUI_INSTALLOPTIONS_READ $HCTL "ClientConfig.ini" "Field 3" "HWND"
525   SendMessage $HCTL ${EM_LIMITTEXT} 30 0
526   
527   ; Client Port Number
528   !insertmacro MUI_INSTALLOPTIONS_READ $HCTL "ClientConfig.ini" "Field 6" "HWND"
529   SendMessage $HCTL ${EM_LIMITTEXT} 5 0
530   SendMessage $HCTL ${WM_SETTEXT} 0 "STR:9102"
531
532   ; Max Jobs
533   !insertmacro MUI_INSTALLOPTIONS_READ $HCTL "ClientConfig.ini" "Field 8" "HWND"
534   SendMessage $HCTL ${EM_LIMITTEXT} 2 0
535   SendMessage $HCTL ${WM_SETTEXT} 0 "STR:20"
536
537   ; Director Name
538   !insertmacro MUI_INSTALLOPTIONS_READ $HCTL "ClientConfig.ini" "Field 11" "HWND"
539   SendMessage $HCTL ${EM_LIMITTEXT} 30 0
540
541   ; Director Password
542   !insertmacro MUI_INSTALLOPTIONS_READ $HCTL "ClientConfig.ini" "Field 14" "HWND"
543   SendMessage $HCTL ${EM_LIMITTEXT} 60 0
544
545   ; Monitor Name
546   !insertmacro MUI_INSTALLOPTIONS_READ $HCTL "ClientConfig.ini" "Field 17" "HWND"
547   SendMessage $HCTL ${EM_LIMITTEXT} 30 0
548
549   ; Monitor Password
550   !insertmacro MUI_INSTALLOPTIONS_READ $HCTL "ClientConfig.ini" "Field 20" "HWND"
551   SendMessage $HCTL ${EM_LIMITTEXT} 60 0
552
553   !insertmacro MUI_INSTALLOPTIONS_SHOW
554   
555   ;
556   ; Process results
557   ;
558   ; Client Name
559   !insertmacro MUI_INSTALLOPTIONS_READ $ConfigClientName "ClientConfig.ini" "Field 3" "State"
560   ; Client Port Number
561   !insertmacro MUI_INSTALLOPTIONS_READ $ConfigClientPort "ClientConfig.ini" "Field 6" "State"
562   ; Max Jobs
563   !insertmacro MUI_INSTALLOPTIONS_READ $ConfigMaxJobs "ClientConfig.ini" "Field 8" "State"
564
565   ; Director Name
566   !insertmacro MUI_INSTALLOPTIONS_READ $ConfigDirectorName "ClientConfig.ini" "Field 11" "State"
567   ; Director Password
568   !insertmacro MUI_INSTALLOPTIONS_READ $ConfigDirectorPW "ClientConfig.ini" "Field 14" "State"
569
570   ; Monitor Name
571   !insertmacro MUI_INSTALLOPTIONS_READ $ConfigMonitorName "ClientConfig.ini" "Field 17" "State"
572   ; Monitor Password
573   !insertmacro MUI_INSTALLOPTIONS_READ $ConfigMonitorPW "ClientConfig.ini" "Field 20" "State"
574 FunctionEnd
575
576 Function LeaveClientConfig
577   ; Client Port Number
578   !insertmacro MUI_INSTALLOPTIONS_READ $R0 "ClientConfig.ini" "Field 6" "State"
579   ${If} $R0 < 1024
580   ${OrIf} $R0 > 65535
581     MessageBox MB_OK "Port must be between 1024 and 65535 inclusive."
582     Abort
583   ${EndIf}
584   
585   ; Max Jobs
586   !insertmacro MUI_INSTALLOPTIONS_READ $R0 "ClientConfig.ini" "Field 8" "State"
587   ${If} $R0 < 1
588   ${OrIf} $R0 > 99
589     MessageBox MB_OK "Max Jobs must be between 1 and 99 inclusive."
590     Abort
591   ${EndIf}
592 FunctionEnd
593
594 Function EnterOptions
595   SectionGetFlags ${SecFileDaemon} $R0
596   IntOp $R0 $R0 & 1
597   
598   SectionGetFlags ${SecStorageDaemon} $R1
599   IntOp $R1 $R1 & 1
600   
601   SectionGetFlags ${SecDirectorDaemon} $R2
602   IntOp $R2 $R2 & 1
603   
604   ${If} $R0 = 0
605   ${AndIf} $R1 = 0
606   ${AndIf} $R2 = 0
607     Abort
608   ${EndIf}
609   
610   FileOpen $R3 "$PLUGINSDIR\options.ini" w
611
612   StrCpy $R4 1  ; Field Number
613   StrCpy $R5 0  ; Top
614   
615   ${If} $R0 = 1
616     IntOp $R6 $R5 + 34
617
618     FileWrite $R3 '[Field $R4]$\r$\n'
619     FileWrite $R3 'Type="GroupBox"$\r$\nText="Client"$\r$\nLeft=0$\r$\nTop=$R5$\r$\nRight=300$\r$\nBottom=$R6$\r$\n'
620
621     IntOp $R4 $R4 + 1
622     IntOp $R5 $R5 + 8
623     IntOp $R6 $R5 + 12
624
625     FileWrite $R3 '[Field $R4]$\r$\nType="Checkbox"$\r$\nState=$OptService$\r$\nText="Install as service"$\r$\nLeft=6$\r$\nTop=$R5$\r$\nRight=280$\r$\nBottom=$R6$\r$\n'
626
627     IntOp $R4 $R4 + 1
628     StrCpy $R5 $R6
629     IntOp $R6 $R5 + 12
630
631     FileWrite $R3 '[Field $R4]$\r$\nType="Checkbox"$\r$\nState=$OptStart$\r$\nText="Start after install"$\r$\nLeft=6$\r$\nTop=$R5$\r$\nRight=280$\r$\nBottom=$R6$\r$\n'
632
633     IntOp $R4 $R4 + 1
634     IntOp $R5 $R6 + 8
635   ${Endif}
636   
637   ${If} $R1 = 1
638     IntOp $R6 $R5 + 34 
639
640     FileWrite $R3 '[Field $R4]$\r$\n'
641     FileWrite $R3 'Type="GroupBox"$\r$\nText="Storage"$\r$\nLeft=0$\r$\nTop=$R5$\r$\nRight=300$\r$\nBottom=$R6$\r$\n'
642
643     IntOp $R4 $R4 + 1
644     IntOp $R5 $R5 + 8
645     IntOp $R6 $R5 + 12
646
647     FileWrite $R3 '[Field $R4]$\r$\nType="Checkbox"$\r$\nState=$OptService$\r$\nText="Install as service"$\r$\nLeft=6$\r$\nTop=$R5$\r$\nRight=280$\r$\nBottom=$R6$\r$\n'
648
649     IntOp $R4 $R4 + 1
650     StrCpy $R5 $R6
651     IntOp $R6 $R5 + 12
652
653     FileWrite $R3 '[Field $R4]$\r$\nType="Checkbox"$\r$\nState=$OptStart$\r$\nText="Start after install"$\r$\nLeft=6$\r$\nTop=$R5$\r$\nRight=280$\r$\nBottom=$R6$\r$\n'
654
655     IntOp $R4 $R4 + 1
656     IntOp $R5 $R6 + 8
657   ${Endif}
658   
659   ${If} $R2 = 1
660     IntOp $R6 $R5 + 46
661
662     FileWrite $R3 '[Field $R4]$\r$\n'
663     FileWrite $R3 'Type="GroupBox"$\r$\nText="Director"$\r$\nLeft=0$\r$\nTop=$R5$\r$\nRight=300$\r$\nBottom=$R6$\r$\n'
664
665     IntOp $R4 $R4 + 1
666     IntOp $R5 $R5 + 8
667     IntOp $R6 $R5 + 12
668
669     FileWrite $R3 '[Field $R4]$\r$\nType="Checkbox"$\r$\nState=$OptService$\r$\nText="Install as service"$\r$\nLeft=6$\r$\nTop=$R5$\r$\nRight=280$\r$\nBottom=$R6$\r$\n'
670
671     IntOp $R4 $R4 + 1
672     StrCpy $R5 $R6
673     IntOp $R6 $R5 + 12
674
675     FileWrite $R3 '[Field $R4]$\r$\nType="Checkbox"$\r$\nState=$OptStart$\r$\nText="Start after install"$\r$\nLeft=6$\r$\nTop=$R5$\r$\nRight=280$\r$\nBottom=$R6$\r$\n'
676
677     IntOp $R4 $R4 + 1
678     IntOp $R5 $R6 + 2
679     IntOp $R6 $R5 + 8
680
681     FileWrite $R3 '[Field $R4]$\r$\nType="Label"$\r$\nText="Database:"$\r$\nLeft=6$\r$\nTop=$R5$\r$\nRight=46$\r$\nBottom=$R6$\r$\n'
682
683     IntOp $R4 $R4 + 1
684     IntOp $R5 $R5 - 2
685     IntOp $R6 $R5 + 12
686
687     FileWrite $R3 '[Field $R4]$\r$\nType="RadioButton"$\r$\nState=1$\r$\nText="MySQL"$\r$\nFlags="GROUP"$\r$\nLeft=46$\r$\nTop=$R5$\r$\nRight=86$\r$\nBottom=$R6$\r$\n'
688
689     IntOp $R4 $R4 + 1
690     IntOp $R6 $R5 + 12
691
692     FileWrite $R3 '[Field $R4]$\r$\nType="RadioButton"$\r$\nState=0$\r$\nText="PostgreSQL"$\r$\nFlags="NOTABSTOP"$\r$\nLeft=86$\r$\nTop=$R5$\r$\nRight=142$\r$\nBottom=$R6$\r$\n'
693
694     IntOp $R4 $R4 + 1
695     IntOp $R6 $R5 + 12
696
697     FileWrite $R3 '[Field $R4]$\r$\nType="RadioButton"$\r$\nState=0$\r$\nText="Builtin"$\r$\nFlags="NOTABSTOP"$\r$\nLeft=142$\r$\nTop=$R5$\r$\nRight=182$\r$\nBottom=$R6$\r$\n'
698
699     IntOp $R4 $R4 + 1
700     IntOp $R5 $R6 + 8
701   ${Endif}
702  
703   IntOp $R4 $R4 - 1
704     
705   FileWrite $R3 "[Settings]$\r$\nNumFields=$R4$\r$\n"
706   
707   FileClose $R3
708    
709   !insertmacro MUI_HEADER_TEXT "$(TITLE_Options)" "$(SUBTITLE_Options)"
710   !insertmacro MUI_INSTALLOPTIONS_DISPLAY "Options.ini"
711   
712   ;
713   ; Process results
714   ;
715   StrCpy $R4 2
716   
717   ${If} $R0 = 1
718     ; Client
719     !insertmacro MUI_INSTALLOPTIONS_READ $OptionsClientService "Options.ini" "Field $R4" "State"
720     IntOp $R4 $R4 + 1
721     !insertmacro MUI_INSTALLOPTIONS_READ $OptionsClientStart "Options.ini" "Field $R4" "State"
722     IntOp $R4 $R4 + 2
723   ${EndIf}
724   
725   ${If} $R0 = 1
726     ; Client
727     !insertmacro MUI_INSTALLOPTIONS_READ $OptionsStorageService "Options.ini" "Field $R4" "State"
728     IntOp $R4 $R4 + 1
729     !insertmacro MUI_INSTALLOPTIONS_READ $OptionsStorageStart "Options.ini" "Field $R4" "State"
730     IntOp $R4 $R4 + 2
731   ${EndIf}
732   
733   ${If} $R0 = 1
734     ; Client
735     !insertmacro MUI_INSTALLOPTIONS_READ $OptionsDirectorService "Options.ini" "Field $R4" "State"
736     IntOp $R4 $R4 + 1
737     !insertmacro MUI_INSTALLOPTIONS_READ $OptionsDirectorStart "Options.ini" "Field $R4" "State"
738     IntOp $R4 $R4 + 2
739     !insertmacro MUI_INSTALLOPTIONS_READ $R3 "Options.ini" "Field $R4" "State"
740     ${If} $R3 = 1
741       StrCpy $OptionsDirectorDB 1
742     ${Else}
743       IntOp $R4 $R4 + 1
744       !insertmacro MUI_INSTALLOPTIONS_READ $R3 "Options.ini" "Field $R4" "State"
745       ${If} $R3 = 1
746         StrCpy $OptionsDirectorDB 2
747       ${Else}
748         StrCpy $OptionsDirectorDB 3
749       ${Endif}
750     ${Endif}
751   ${EndIf}
752 FunctionEnd
753
754 ;
755 ; $0 - Service Name (ie Bacula-FD)
756 ; $1 - Service Description (ie Bacula File Daemon)
757 ; $2 - Install as Service
758 ; $3 - Start Service now
759 ;
760 Function InstallDaemon
761   Call CopyDependencies
762
763   IfFileExists "$APPDATA\Bacula\$0.conf" 0 +3
764     ExecWait '"$INSTDIR\bin\$0.exe" /kill' ; Shutdown any bacula that could be running
765     Sleep 3000  ; give it some time to shutdown
766
767   WriteRegDWORD HKLM "Software\Bacula" "Service_$0" $2
768   
769   ${If} $2 = 1
770     ExecWait '"$INSTDIR\bin\$0.exe" /install'
771
772     ${If} $OsIsNT <> 1
773       File Start.bat
774       File Stop.bat
775     ${EndIf}
776
777     ; Start the service? (default skipped if silent, use /start to force starting)
778
779     ${If} $3 = 1  
780       ${If} $OsIsNT = 1
781         Exec 'net start bacula'
782         Sleep 3000
783       ${Else}
784         Exec '"$INSTDIR\bin\$0.exe" -c "$APPDATA\Bacula\$0.conf"'
785       ${EndIf}
786     ${EndIf}
787   ${Else}
788     CreateShortCut "$SMPROGRAMS\Bacula\Start $1.lnk" "$INSTDIR\bin\$0.exe" '-c "$APPDATA\Bacula\$0.conf"' "$INSTDIR\bin\$0.exe" 0
789   ${EndIf}
790 FunctionEnd