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