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