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