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