]> git.sur5r.net Git - bacula/bacula/blob - bacula/src/win32/installer/winbacula.nsi
Fix Windows' daemons so that messages print to stdout if not running as a service.
[bacula/bacula] / bacula / src / 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 wx-console.conf
10 ; better explanation in dialog boxes for editing config files
11 ; added Start Menu items
12 ; fix uninstall of config files to do all not just bacula-fd.conf
13 ;
14 ; D. Scott Barninger Dec 05 2004
15 ; added specification of default permissions for bacula-fd.conf
16 ;   - thanks to Jamie Ffolliott for pointing me at cacls
17 ; added removal of working-dir files if user selects to remove config
18 ; uninstall is now 100% clean
19 ;
20 ; D. Scott Barninger Apr 17 2005
21 ; 1.36.3 release docs update
22 ; add pdf manual and menu shortcut
23 ;
24 ; Robert Nelson May 15 2006
25 ; Pretty much rewritten
26 ; Use LogicLib.nsh
27 ; Added Bacula-SD and Bacula-DIR
28 ; Replaced ParameterGiven with standard GetOptions
29
30 ;
31 ; Command line options:
32 ;
33 ; /cygwin     -  do cygwin install into c:\cygwin\bacula
34 ; /service    - 
35 ; /start
36
37 !define PRODUCT "Bacula"
38
39 ;
40 ; Include the Modern UI
41 ;
42
43 !include "MUI.nsh"
44 !include "LogicLib.nsh"
45 !include "FileFunc.nsh"
46 !include "Sections.nsh"
47 !include "StrFunc.nsh"
48 !include "WinMessages.nsh"
49 ;
50 ; Basics
51 ;
52 Name "Bacula"
53 OutFile "${OUT_DIR}\winbacula-${VERSION}.exe"
54 SetCompressor lzma
55 InstallDir "$PROGRAMFILES\Bacula"
56 InstallDirRegKey HKLM "Software\Bacula" "InstallLocation"
57
58 InstType "Client"
59 InstType "Server"
60 InstType "Full"
61
62 !insertmacro GetParent
63
64 ${StrCase}
65 ${StrRep}
66 ${StrTok}
67 ${StrTrimNewLines}
68
69 ;
70 ; Pull in pages
71 ;
72
73 !define      MUI_COMPONENTSPAGE_SMALLDESC
74
75 !define      MUI_HEADERIMAGE
76 !define      MUI_BGCOLOR                739AB9
77 !define      MUI_HEADERIMAGE_BITMAP     "bacula-logo.bmp"
78
79 !InsertMacro MUI_PAGE_WELCOME
80 ;  !InsertMacro MUI_PAGE_LICENSE "..\..\LICENSE"
81 Page custom EnterInstallType
82 !define      MUI_PAGE_CUSTOMFUNCTION_SHOW PageComponentsShow
83 !InsertMacro MUI_PAGE_COMPONENTS
84 !define      MUI_PAGE_CUSTOMFUNCTION_PRE PageDirectoryPre
85 !InsertMacro MUI_PAGE_DIRECTORY
86 Page custom EnterConfigPage1 LeaveConfigPage1
87 Page custom EnterConfigPage2 LeaveConfigPage2
88 !Define      MUI_PAGE_CUSTOMFUNCTION_LEAVE LeaveInstallPage
89 !InsertMacro MUI_PAGE_INSTFILES
90 Page custom EnterWriteTemplates
91 !Define      MUI_FINISHPAGE_SHOWREADME $INSTDIR\Readme.txt
92 !InsertMacro MUI_PAGE_FINISH
93
94 !InsertMacro MUI_UNPAGE_WELCOME
95 !InsertMacro MUI_UNPAGE_CONFIRM
96 !InsertMacro MUI_UNPAGE_INSTFILES
97 !InsertMacro MUI_UNPAGE_FINISH
98
99 !define      MUI_ABORTWARNING
100
101 !InsertMacro MUI_LANGUAGE "English"
102
103 !InsertMacro GetParameters
104 !InsertMacro GetOptions
105
106 DirText "Setup will install Bacula ${VERSION} to the directory specified below. To install in a different folder, click Browse and select another folder."
107
108 !InsertMacro MUI_RESERVEFILE_INSTALLOPTIONS
109 ;
110 ; Global Variables
111 ;
112 Var OptCygwin
113 Var OptService
114 Var OptStart
115 Var OptSilent
116
117 Var CommonFilesDone
118 Var DatabaseDone
119
120 Var OsIsNT
121
122 Var HostName
123
124 Var ConfigClientName
125 Var ConfigClientPort
126 Var ConfigClientMaxJobs
127 Var ConfigClientPassword
128 Var ConfigClientInstallService
129 Var ConfigClientStartService
130
131 Var ConfigStorageName
132 Var ConfigStoragePort
133 Var ConfigStorageMaxJobs
134 Var ConfigStoragePassword
135 Var ConfigStorageInstallService
136 Var ConfigStorageStartService
137
138 Var ConfigDirectorName
139 Var ConfigDirectorPort
140 Var ConfigDirectorMaxJobs
141 Var ConfigDirectorPassword
142 Var ConfigDirectorAddress
143 Var ConfigDirectorMailServer
144 Var ConfigDirectorMailAddress
145 Var ConfigDirectorDB
146 Var ConfigDirectorInstallService
147 Var ConfigDirectorStartService
148
149 Var ConfigMonitorName
150 Var ConfigMonitorPassword
151
152 Var LocalDirectorPassword
153 Var LocalHostAddress
154
155 Var AutomaticInstall
156 Var InstallType
157 !define NewInstall      0
158 !define UpgradeInstall  1
159 !define MigrateInstall  2
160
161 Var OldInstallDir
162 Var PreviousComponents
163 Var NewComponents
164
165 ; Bit 0 = File Service
166 ;     1 = Storage Service
167 ;     2 = Director Service
168 ;     3 = Command Console
169 ;     4 = Graphical Console
170 ;     5 = Documentation (PDF)
171 ;     6 = Documentation (HTML)
172
173 !define ComponentFile                   1
174 !define ComponentStorage                2
175 !define ComponentDirector               4
176 !define ComponentTextConsole            8
177 !define ComponentGUIConsole             16
178 !define ComponentPDFDocs                32
179 !define ComponentHTMLDocs               64
180
181 !define ComponentsRequiringUserConfig           31
182 !define ComponentsFileAndStorage                3
183 !define ComponentsFileAndStorageAndDirector     7
184 !define ComponentsDirectorAndTextGuiConsoles    28
185 !define ComponentsTextAndGuiConsoles            24
186
187 Var HDLG
188 Var HCTL
189
190 Function .onInit
191   Push $R0
192   Push $R1
193
194   ; Process Command Line Options
195   StrCpy $OptCygwin 0
196   StrCpy $OptService 1
197   StrCpy $OptStart 1
198   StrCpy $OptSilent 0
199   StrCpy $CommonFilesDone 0
200   StrCpy $DatabaseDone 0
201   StrCpy $OsIsNT 0
202   StrCpy $AutomaticInstall 0
203   StrCpy $InstallType ${NewInstall}
204   StrCpy $OldInstallDir ""
205   StrCpy $PreviousComponents 0
206   StrCpy $NewComponents 0
207
208   ${GetParameters} $R0
209
210   ClearErrors
211   ${GetOptions} $R0 "/cygwin" $R1
212   IfErrors +2
213     StrCpy $OptCygwin 1
214
215   ClearErrors
216   ${GetOptions} $R0 "/noservice" $R1
217   IfErrors +2
218     StrCpy $OptService 0
219
220   ClearErrors
221   ${GetOptions} $R0 "/nostart" $R1
222   IfErrors +2
223     StrCpy $OptStart 0
224
225   IfSilent 0 +2
226     StrCpy $OptSilent 1
227
228   ${If} $OptCygwin = 1
229     StrCpy $INSTDIR "C:\cygwin\bacula"
230   ${EndIf}
231
232   ReadRegStr $R0 HKLM "SOFTWARE\Microsoft\Windows NT\CurrentVersion" CurrentVersion
233   ${If} $R0 != ""
234     StrCpy $OsIsNT 1
235   ${EndIf}
236
237   Call GetComputerName
238   Pop $HostName
239
240   Call GetHostName
241   Pop $LocalHostAddress
242
243   Call GetUserName
244   Pop $ConfigDirectorMailAddress
245
246   ; Configuration Defaults
247
248   StrCpy $ConfigClientName              "$HostName-fd"
249   StrCpy $ConfigClientPort              "9102"
250   StrCpy $ConfigClientMaxJobs           "2"
251   ;StrCpy $ConfigClientPassword
252   StrCpy $ConfigClientInstallService    "$OptService"
253   StrCpy $ConfigClientStartService      "$OptStart"
254
255   StrCpy $ConfigStorageName             "$HostName-sd"
256   StrCpy $ConfigStoragePort             "9103"
257   StrCpy $ConfigStorageMaxJobs          "10"
258   ;StrCpy $ConfigStoragePassword
259   StrCpy $ConfigStorageInstallService   "$OptService"
260   StrCpy $ConfigStorageStartService     "$OptStart"
261
262   ;StrCpy $ConfigDirectorName            "$HostName-dir"
263   StrCpy $ConfigDirectorPort            "9101"
264   StrCpy $ConfigDirectorMaxJobs         "1"
265   ;StrCpy $ConfigDirectorPassword
266   StrCpy $ConfigDirectorDB              "1"
267   StrCpy $ConfigDirectorInstallService  "$OptService"
268   StrCpy $ConfigDirectorStartService    "$OptStart"
269
270   StrCpy $ConfigMonitorName            "$HostName-mon"
271   ;StrCpy $ConfigMonitorPassword
272
273   InitPluginsDir
274   File "/oname=$PLUGINSDIR\openssl.exe"  "${DEPKGS_BIN}\openssl.exe"
275   File "/oname=$PLUGINSDIR\libeay32.dll" "${DEPKGS_BIN}\libeay32.dll"
276   File "/oname=$PLUGINSDIR\ssleay32.dll" "${DEPKGS_BIN}\ssleay32.dll"
277   File "/oname=$PLUGINSDIR\sed.exe" "${DEPKGS_BIN}\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   nsExec::Exec '"$PLUGINSDIR\openssl.exe" rand -base64 -out $PLUGINSDIR\pw.txt 33'
295   pop $R0
296   ${If} $R0 = 0
297    FileOpen $R1 "$PLUGINSDIR\pw.txt" r
298    IfErrors +4
299      FileRead $R1 $R0
300      ${StrTrimNewLines} $ConfigStoragePassword $R0
301      FileClose $R1
302   ${EndIf}
303
304   nsExec::Exec '"$PLUGINSDIR\openssl.exe" rand -base64 -out $PLUGINSDIR\pw.txt 33'
305   pop $R0
306   ${If} $R0 = 0
307    FileOpen $R1 "$PLUGINSDIR\pw.txt" r
308    IfErrors +4
309      FileRead $R1 $R0
310      ${StrTrimNewLines} $LocalDirectorPassword $R0
311      FileClose $R1
312   ${EndIf}
313
314   SetPluginUnload manual
315
316   nsExec::Exec '"$PLUGINSDIR\openssl.exe" rand -base64 -out $PLUGINSDIR\pw.txt 33'
317   pop $R0
318   ${If} $R0 = 0
319    FileOpen $R1 "$PLUGINSDIR\pw.txt" r
320    IfErrors +4
321      FileRead $R1 $R0
322      ${StrTrimNewLines} $ConfigMonitorPassword $R0
323      FileClose $R1
324   ${EndIf}
325
326   Pop $R1
327   Pop $R0
328 FunctionEnd
329
330 Function .onSelChange
331   Call UpdateComponentUI
332 FunctionEnd
333
334 Function InstallCommonFiles
335   ${If} $CommonFilesDone = 0
336     SetOutPath "$INSTDIR"
337     File "Readme.txt"
338
339     SetOutPath "$INSTDIR\bin"
340 !if "${BUILD_TOOLS}" == "VC8"
341     File "${VC_REDIST_DIR}\msvcm80.dll"
342     File "${VC_REDIST_DIR}\msvcp80.dll"
343     File "${VC_REDIST_DIR}\msvcr80.dll"
344     File "${VC_REDIST_DIR}\Microsoft.VC80.CRT.manifest"
345     File "${DEPKGS_BIN}\pthreadVCE.dll"
346 !endif
347 !if "${BUILD_TOOLS}" == "VC8_DEBUG"
348     File "${VC_REDIST_DIR}\msvcm80.dll"
349     File "${VC_REDIST_DIR}\msvcp80.dll"
350     File "${VC_REDIST_DIR}\msvcr80.dll"
351     File "${VC_REDIST_DIR}\Microsoft.VC80.CRT.manifest"
352     File "${VC_REDIST_DIR}\msvcm80d.dll"
353     File "${VC_REDIST_DIR}\msvcp80d.dll"
354     File "${VC_REDIST_DIR}\msvcr80d.dll"
355     File "${VC_REDIST_DIR}\Microsoft.VC80.DebugCRT.manifest"
356     File "${DEPKGS_BIN}\pthreadVCE.dll"
357 !endif
358 !if "${BUILD_TOOLS}" == "MinGW"
359     File "${MINGW_BIN}\..\mingw32\bin\mingwm10.dll"
360     File "${DEPKGS_BIN}\pthreadGCE.dll"
361 !endif
362     File "${DEPKGS_BIN}\libeay32.dll"
363     File "${DEPKGS_BIN}\ssleay32.dll"
364     File "${DEPKGS_BIN}\zlib1.dll"
365 !if "${BUILD_TOOLS}" == "VC8"
366     File "${DEPKGS_BIN}\zlib1.dll.manifest"
367     File "/oname=$INSTDIR\openssl.cnf" "${DEPKGS_BIN}\..\openssl.cnf"
368 !endif
369 !If "${BUILD_TOOLS}" == "VC8_DEBUG"
370     File "${DEPKGS_BIN}\zlib1.dll.manifest"
371     File "/oname=$INSTDIR\openssl.cnf" "${DEPKGS_BIN}\..\openssl.cnf"
372 !endif
373 !if "${BUILD_TOOLS}" == "MinGW"
374     File "/oname=$INSTDIR\openssl.cnf" "${DEPKGS_BIN}\..\ssl\openssl.cnf"
375 !endif
376     File "${DEPKGS_BIN}\openssl.exe"
377     File "${BACULA_BIN}\bsleep.exe"
378     File "${BACULA_BIN}\bsmtp.exe"
379     File "${BACULA_BIN}\bacula.dll"
380
381     CreateShortCut "$SMPROGRAMS\Bacula\View Readme.lnk" "write.exe" '"$INSTDIR\Readme.txt"'
382
383     StrCpy $CommonFilesDone 1
384   ${EndIf}
385 FunctionEnd
386
387 Function InstallDatabase
388   SetOutPath "$INSTDIR\bin"
389
390   ${If} $DatabaseDone = 0
391     ${If} $ConfigDirectorDB = 1
392       File /oname=bacula_cats.dll "${BACULA_BIN}\cats_mysql.dll"
393       File "${DEPKGS_BIN}\libmysql.dll"
394     ${ElseIf} $ConfigDirectorDB = 2
395       File /oname=bacula_cats.dll "${BACULA_BIN}\cats_pgsql.dll"
396       File "${DEPKGS_BIN}\libpq.dll"
397 !if "${BUILD_TOOLS}" == "VC8"
398       File "${DEPKGS_BIN}\comerr32.dll"
399       File "${DEPKGS_BIN}\libintl-2.dll"
400       File "${DEPKGS_BIN}\libiconv-2.dll"
401       File "${DEPKGS_BIN}\krb5_32.dll"
402 !endif
403 !If "${BUILD_TOOLS}" == "VC8_DEBUG"
404       File "${DEPKGS_BIN}\comerr32.dll"
405       File "${DEPKGS_BIN}\libintl-2.dll"
406       File "${DEPKGS_BIN}\libiconv-2.dll"
407       File "${DEPKGS_BIN}\krb5_32.dll"
408 !endif
409     ${ElseIf} $ConfigDirectorDB = 4
410       File /oname=bacula_cats.dll "${BACULA_BIN}\cats_bdb.dll"
411     ${EndIf}
412
413     StrCpy $DatabaseDone 1
414   ${EndIf}
415 FunctionEnd
416
417 Section "-Initialize"
418   WriteRegStr   HKLM Software\Bacula InstallLocation "$INSTDIR"
419
420   Call GetSelectedComponents
421   Pop $R2
422   WriteRegDWORD HKLM Software\Bacula Components $R2
423
424   SetShellVarContext all
425   CreateDirectory "$SMPROGRAMS\Bacula"
426
427   CreateDirectory "$INSTDIR"
428   CreateDirectory "$INSTDIR\bin"
429   CreateDirectory "$APPDATA\Bacula"
430   CreateDirectory "$APPDATA\Bacula\Work"
431   CreateDirectory "$APPDATA\Bacula\Spool"
432
433   File "..\..\..\LICENSE"
434   Delete /REBOOTOK "$INSTDIR\bin\License.txt"
435
436   FileOpen $R1 $PLUGINSDIR\config.sed w
437   FileWrite $R1 "s;@VERSION@;${VERSION};$\r$\n"
438   FileWrite $R1 "s;@DATE@;${__DATE__};$\r$\n"
439   FileWrite $R1 "s;@DISTNAME@;Windows;$\r$\n"
440
441 !If "$BUILD_TOOLS" == "MinGW"
442   StrCpy $R2 "MinGW32"
443 !Else
444   StrCpy $R2 "MVS"
445 !EndIf
446
447   Call GetHostName
448   Exch $R3
449   Pop $R3
450
451   FileWrite $R1 "s;@DISTVER@;$R2;$\r$\n"
452
453   ${StrRep} $R2 "$APPDATA\Bacula\Work" "\" "\\\\"
454   FileWrite $R1 's;@working_dir@;$R2;$\r$\n'
455   ${StrRep} $R2 "$APPDATA\Bacula\Work" "\" "\\"
456   FileWrite $R1 's;@working_dir_cmd@;$R2;$\r$\n'
457
458   ${StrRep} $R2 "$INSTDIR\bin" "\" "\\\\"
459   FileWrite $R1 's;@bin_dir@;$R2;$\r$\n'
460   ${StrRep} $R2 "$INSTDIR\bin" "\" "\\"
461   FileWrite $R1 's;@bin_dir_cmd@;$R2;$\r$\n'
462
463   Call IsDirectorSelected
464   Pop $R2
465   ${If} $R2 = 1
466     FileWrite $R1 "s;@director_address@;$LocalHostAddress;$\r$\n"
467   ${Else}
468     ${If} "$ConfigDirectorAddress" != ""
469       FileWrite $R1 "s;@director_address@;$ConfigDirectorAddress;$\r$\n"
470     ${EndIf}
471   ${EndIf}
472
473   FileWrite $R1 "s;@client_address@;$LocalHostAddress;$\r$\n"
474   FileWrite $R1 "s;@storage_address@;$LocalHostAddress;$\r$\n"
475
476   ${If} "$ConfigClientName" != ""
477     FileWrite $R1 "s;@client_name@;$ConfigClientName;$\r$\n"
478   ${EndIf}
479   ${If} "$ConfigClientPort" != ""
480     FileWrite $R1 "s;@client_port@;$ConfigClientPort;$\r$\n"
481   ${EndIf}
482   ${If} "$ConfigClientMaxJobs" != ""
483     FileWrite $R1 "s;@client_maxjobs@;$ConfigClientMaxJobs;$\r$\n"
484   ${EndIf}
485   ${If} "$ConfigClientPassword" != ""
486     FileWrite $R1 "s;@client_password@;$ConfigClientPassword;$\r$\n"
487   ${EndIf}
488   ${If} "$ConfigStorageName" != ""
489     FileWrite $R1 "s;@storage_name@;$ConfigStorageName;$\r$\n"
490   ${EndIf}
491   ${If} "$ConfigStoragePort" != ""
492     FileWrite $R1 "s;@storage_port@;$ConfigStoragePort;$\r$\n"
493   ${EndIf}
494   ${If} "$ConfigStorageMaxJobs" != ""
495     FileWrite $R1 "s;@storage_maxjobs@;$ConfigStorageMaxJobs;$\r$\n"
496   ${EndIf}
497   ${If} "$ConfigStoragePassword" != ""
498     FileWrite $R1 "s;@storage_password@;$ConfigStoragePassword;$\r$\n"
499   ${EndIf}
500   ${If} "$ConfigDirectorName" != ""
501     FileWrite $R1 "s;@director_name@;$ConfigDirectorName;$\r$\n"
502   ${EndIf}
503   ${If} "$ConfigDirectorPort" != ""
504     FileWrite $R1 "s;@director_port@;$ConfigDirectorPort;$\r$\n"
505   ${EndIf}
506   ${If} "$ConfigDirectorMaxJobs" != ""
507     FileWrite $R1 "s;@director_maxjobs@;$ConfigDirectorMaxJobs;$\r$\n"
508   ${EndIf}
509   ${If} "$ConfigDirectorPassword" != ""
510     FileWrite $R1 "s;@director_password@;$ConfigDirectorPassword;$\r$\n"
511   ${EndIf}
512   ${If} "$ConfigDirectorMailServer" != ""
513     FileWrite $R1 "s;@smtp_host@;$ConfigDirectorMailServer;$\r$\n"
514   ${EndIf}
515   ${If} "$ConfigDirectorMailAddress" != ""
516     FileWrite $R1 "s;@job_email@;$ConfigDirectorMailAddress;$\r$\n"
517   ${EndIf}
518   ${If} "$ConfigMonitorName" != ""
519     FileWrite $R1 "s;@monitor_name@;$ConfigMonitorName;$\r$\n"
520   ${EndIf}
521   ${If} "$ConfigMonitorPassword" != ""
522     FileWrite $R1 "s;@monitor_password@;$ConfigMonitorPassword;$\r$\n"
523   ${EndIf}
524
525   FileClose $R1
526
527   ${If} $InstallType = ${MigrateInstall}
528     FileOpen $R1 $PLUGINSDIR\migrate.sed w
529     ${StrRep} $R2 "$APPDATA\Bacula\Work" "\" "\\\\"
530     FileWrite $R1 's;\(Working *Directory *= *\)[^ ][^ ]*.*$$;\1"$R2";$\r$\n'
531     FileWrite $R1 's;\(Pid *Directory *= *\)[^ ][^ ]*.*$$;\1"$R2";$\r$\n'
532     FileClose $R1
533   ${EndIf}
534
535   ${If} ${FileExists} "$OldInstallDir\bin\bacula-fd.exe"
536     ${If} $InstallType <> ${MigrateInstall}
537       nsExec::ExecToLog '"$OldInstallDir\bin\bacula-fd.exe" /silent /kill'     ; Shutdown any bacula that could be running
538       Sleep 3000
539       nsExec::ExecToLog '"$OldInstallDir\bin\bacula-fd.exe" /silent /remove'   ; Remove existing service
540     ${Else}
541       nsExec::ExecToLog '"$OldInstallDir\bin\bacula-fd.exe" /kill'     ; Shutdown any bacula that could be running
542       Sleep 3000
543       nsExec::ExecToLog '"$OldInstallDir\bin\bacula-fd.exe" /remove'   ; Remove existing service
544     ${EndIf}
545   ${EndIf}
546
547   ${If} ${FileExists} "$OldInstallDir\bin\bacula-sd.exe"
548     nsExec::ExecToLog '"$OldInstallDir\bin\bacula-sd.exe" /silent /kill'     ; Shutdown any bacula that could be running
549     Sleep 3000
550     nsExec::ExecToLog '"$OldInstallDir\bin\bacula-sd.exe" /silent /remove'   ; Remove existing service
551   ${EndIf}
552
553   ${If} ${FileExists} "$OldInstallDir\bin\bacula-dir.exe"
554     nsExec::ExecToLog '"$OldInstallDir\bin\bacula-dir.exe" /silent /kill'     ; Shutdown any bacula that could be running
555     Sleep 3000
556     nsExec::ExecToLog '"$OldInstallDir\bin\bacula-dir.exe" /silent /remove'   ; Remove existing service
557   ${EndIf}
558
559 SectionEnd
560
561 SectionGroup "Client" SecGroupClient
562
563 Section "File Service" SecFileDaemon
564   SectionIn 1 2 3
565
566   SetOutPath "$INSTDIR\bin"
567
568   File "${BACULA_BIN}\bacula-fd.exe"
569
570   ${If} $InstallType = ${MigrateInstall}
571   ${AndIf} ${FileExists} "$OldInstallDir\bin\bacula-fd.conf"
572     CopyFiles "$OldInstallDir\bin\bacula-fd.conf" "$APPDATA\Bacula"
573     nsExec::ExecToLog '$PLUGINSDIR\sed.exe -f "$PLUGINSDIR\migrate.sed" -i.bak "$APPDATA\Bacula\bacula-fd.conf"'
574   ${Else}
575     ${Unless} ${FileExists} "$APPDATA\Bacula\bacula-fd.conf"
576       File "/oname=$PLUGINSDIR\bacula-fd.conf.in" "bacula-fd.conf.in"
577
578       nsExec::ExecToLog '$PLUGINSDIR\sed.exe -f "$PLUGINSDIR\config.sed" -i.bak "$PLUGINSDIR\bacula-fd.conf.in"'
579       CopyFiles "$PLUGINSDIR\bacula-fd.conf.in" "$APPDATA\Bacula\bacula-fd.conf"
580     ${EndUnless}
581   ${EndIf}
582
583   ${If} $OsIsNT = 1
584     nsExec::ExecToLog 'cmd.exe /C echo Y|cacls "$R1" /G SYSTEM:F Administrators:F'
585   ${EndIf}
586
587   StrCpy $0 bacula-fd
588   StrCpy $1 "File Service"
589   StrCpy $2 $ConfigClientInstallService
590   StrCpy $3 $ConfigClientStartService
591
592   Call InstallDaemon
593
594   CreateShortCut "$SMPROGRAMS\Bacula\Edit Client Configuration.lnk" "write.exe" '"$APPDATA\Bacula\bacula-fd.conf"'
595 SectionEnd
596
597 SectionGroupEnd
598
599 SectionGroup "Server" SecGroupServer
600
601 Section "Storage Service" SecStorageDaemon
602   SectionIn 2 3
603
604   SetOutPath "$INSTDIR\bin"
605
606   File "${DEPKGS_BIN}\loaderinfo.exe"
607   File "${DEPKGS_BIN}\mt.exe"
608   File "${DEPKGS_BIN}\mtx.exe"
609   File "${DEPKGS_BIN}\scsitape.exe"
610   File "${DEPKGS_BIN}\tapeinfo.exe"
611   File "${BACULA_BIN}\bacula-sd.exe"
612   File "${BACULA_BIN}\bcopy.exe"
613   File "${BACULA_BIN}\bextract.exe"
614   File "${BACULA_BIN}\bls.exe"
615   File "${BACULA_BIN}\bscan.exe"
616   File "${BACULA_BIN}\btape.exe"
617   File "${BACULA_BIN}\scsilist.exe"
618
619   ${Unless} ${FileExists} "${BACULA_BIN}\mtx-changer.cmd"
620     File "/oname=$PLUGINSDIR\mtx-changer.cmd" "${SCRIPT_DIR}\mtx-changer.cmd"
621
622     nsExec::ExecToLog '$PLUGINSDIR\sed.exe -f "$PLUGINSDIR\config.sed" -i.bak "$PLUGINSDIR\mtx-changer.cmd"'
623     CopyFiles "$PLUGINSDIR\mtx-changer.cmd" "$INSTDIR\bin\mtx-changer.cmd"
624   ${EndUnless}
625
626   ${Unless} ${FileExists} "$APPDATA\Bacula\bacula-sd.conf"
627     File "/oname=$PLUGINSDIR\bacula-sd.conf.in" "bacula-sd.conf.in"
628
629     nsExec::ExecToLog '$PLUGINSDIR\sed.exe -f "$PLUGINSDIR\config.sed" -i.bak "$PLUGINSDIR\bacula-sd.conf.in"'
630     CopyFiles "$PLUGINSDIR\bacula-sd.conf.in" "$APPDATA\Bacula\bacula-sd.conf"
631   ${EndUnless}
632
633   ${If} $OsIsNT = 1
634     nsExec::ExecToLog 'cmd.exe /C echo Y|cacls "$R1" /G SYSTEM:F Administrators:F'
635   ${EndIf}
636
637   StrCpy $0 bacula-sd
638   StrCpy $1 "Storage Service"
639   StrCpy $2 $ConfigStorageInstallService
640   StrCpy $3 $ConfigStorageStartService
641   Call InstallDaemon
642
643   CreateShortCut "$SMPROGRAMS\Bacula\List Devices.lnk" "$INSTDIR\bin\scsilist.exe" "/pause"
644   CreateShortCut "$SMPROGRAMS\Bacula\Edit Storage Configuration.lnk" "write.exe" '"$APPDATA\Bacula\bacula-sd.conf"'
645 SectionEnd
646
647 Section "Director Service" SecDirectorDaemon
648   SectionIn 2 3
649
650   SetOutPath "$INSTDIR\bin"
651
652   Call InstallDatabase
653   File "${BACULA_BIN}\bacula-dir.exe"
654   File "${BACULA_BIN}\dbcheck.exe"
655
656   ${If} $ConfigDirectorDB = 1
657     File /oname=create_database.cmd ${CATS_DIR}\create_mysql_database.cmd
658     File /oname=drop_database.cmd ${CATS_DIR}\drop_mysql_database.cmd
659     File /oname=make_tables.cmd ${CATS_DIR}\make_mysql_tables.cmd
660     File ${CATS_DIR}\make_mysql_tables.sql
661     File /oname=drop_tables.cmd ${CATS_DIR}\drop_mysql_tables.cmd
662     File ${CATS_DIR}\drop_mysql_tables.sql
663     File /oname=update_tables.cmd ${CATS_DIR}\update_mysql_tables.cmd
664     File ${CATS_DIR}\update_mysql_tables.sql
665     File /oname=grant_privileges.cmd ${CATS_DIR}\grant_mysql_privileges.cmd
666     File ${CATS_DIR}\grant_mysql_privileges.sql
667   ${ElseIf} $ConfigDirectorDB = 2
668     File /oname=create_database.cmd ${CATS_DIR}\create_postgresql_database.cmd
669     File /oname=drop_database.cmd ${CATS_DIR}\drop_postgresql_database.cmd
670     File /oname=make_tables.cmd ${CATS_DIR}\make_postgresql_tables.cmd
671     File ${CATS_DIR}\make_postgresql_tables.sql
672     File /oname=drop_tables.cmd ${CATS_DIR}\drop_postgresql_tables.cmd
673     File ${CATS_DIR}\drop_postgresql_tables.sql
674     File /oname=update_tables.cmd ${CATS_DIR}\update_postgresql_tables.cmd
675     File ${CATS_DIR}\update_postgresql_tables.sql
676     File /oname=grant_privileges.cmd ${CATS_DIR}\grant_postgresql_privileges.cmd
677     File ${CATS_DIR}\grant_postgresql_privileges.sql
678   ${ElseIf} $ConfigDirectorDB = 4
679     File /oname=create_database.cmd ${CATS_DIR}\create_bdb_database.cmd
680     File /oname=drop_database.cmd ${CATS_DIR}\drop_bdb_database.cmd
681     File /oname=make_tables.cmd ${CATS_DIR}\make_bdb_tables.cmd
682     File /oname=drop_tables.cmd ${CATS_DIR}\drop_bdb_tables.cmd
683     File /oname=update_tables.cmd ${CATS_DIR}\update_bdb_tables.cmd
684     File /oname=grant_privileges.cmd ${CATS_DIR}\grant_bdb_privileges.cmd
685   ${EndIf}
686   File ${CATS_DIR}\make_catalog_backup.cmd
687   File ${CATS_DIR}\delete_catalog_backup.cmd
688
689   ${Unless} ${FileExists} "$APPDATA\Bacula\bacula-dir.conf"
690     File "/oname=$PLUGINSDIR\bacula-dir.conf.in" "bacula-dir.conf.in"
691     nsExec::ExecToLog '$PLUGINSDIR\sed.exe -f "$PLUGINSDIR\config.sed" -i.bak "$PLUGINSDIR\bacula-dir.conf.in"'
692     CopyFiles "$PLUGINSDIR\bacula-dir.conf.in" "$APPDATA\Bacula\bacula-dir.conf"
693   ${EndUnless}
694
695   ${If} $OsIsNT = 1
696     nsExec::ExecToLog 'cmd.exe /C echo Y|cacls "$R1" /G SYSTEM:F Administrators:F'
697   ${EndIf}
698
699   StrCpy $0 bacula-dir
700   StrCpy $1 "Director Service"
701   StrCpy $2 $ConfigDirectorInstallService
702   StrCpy $3 $ConfigDirectorStartService
703   Call InstallDaemon
704
705   CreateShortCut "$SMPROGRAMS\Bacula\Edit Director Configuration.lnk" "write.exe" '"$APPDATA\Bacula\bacula-dir.conf"'
706 SectionEnd
707
708 SectionGroupEnd
709
710 SectionGroup "Consoles" SecGroupConsoles
711
712 Section "Command Console" SecConsole
713   SectionIn 1 2 3
714
715   SetOutPath "$INSTDIR\bin"
716
717   File "${BACULA_BIN}\bconsole.exe"
718   Call InstallCommonFiles
719
720   ${If} $InstallType = ${MigrateInstall}
721   ${AndIf} ${FileExists} "$OldInstallDir\bin\bconsole.conf"
722     CopyFiles "$OldInstallDir\bin\bconsole.conf" "$APPDATA\Bacula"
723   ${Else}
724     ${Unless} ${FileExists} "$APPDATA\Bacula\bconsole.conf"
725       File "/oname=$PLUGINSDIR\bconsole.conf.in" "bconsole.conf.in"
726       nsExec::ExecToLog '$PLUGINSDIR\sed.exe -f "$PLUGINSDIR\config.sed" -i.bak "$PLUGINSDIR\bconsole.conf.in"'
727       CopyFiles "$PLUGINSDIR\bconsole.conf.in" "$APPDATA\Bacula\bconsole.conf"
728     ${EndUnless}
729   ${EndIf}
730
731   ${If} $OsIsNT = 1
732     nsExec::ExecToLog 'cmd.exe /C echo Y|cacls "$R1" /G SYSTEM:F Administrators:F'
733   ${EndIf}
734
735   CreateShortCut "$SMPROGRAMS\Bacula\bconsole.lnk" "$INSTDIR\bin\bconsole.exe" '-c "$APPDATA\Bacula\bconsole.conf"' "$INSTDIR\bin\bconsole.exe" 0
736   CreateShortCut "$SMPROGRAMS\Bacula\Edit Command Console Configuration.lnk" "write.exe" '"$APPDATA\Bacula\bconsole.conf"'
737
738 SectionEnd
739
740 Section "Graphical Console" SecWxConsole
741   SectionIn 1 2 3
742   
743   SetOutPath "$INSTDIR\bin"
744
745   Call InstallCommonFiles
746 !if "${BUILD_TOOLS}" == "VC8"
747   File "${DEPKGS_BIN}\wxbase270_vc_bacula.dll"
748   File "${DEPKGS_BIN}\wxmsw270_core_vc_bacula.dll"
749 !endif
750 !If "${BUILD_TOOLS}" == "VC8_DEBUG"
751   File "${DEPKGS_BIN}\wxbase270_vc_bacula.dll"
752   File "${DEPKGS_BIN}\wxmsw270_core_vc_bacula.dll"
753 !endif
754 !if "${BUILD_TOOLS}" == "MinGW"
755   File "${DEPKGS_BIN}\wxbase26_gcc_bacula.dll"
756   File "${DEPKGS_BIN}\wxmsw26_core_gcc_bacula.dll"
757 !endif
758
759   File "${BACULA_BIN}\wx-console.exe"
760
761   ${If} $InstallType = ${MigrateInstall}
762   ${AndIf} ${FileExists} "$OldInstallDir\bin\wx-console.conf"
763     CopyFiles "$OldInstallDir\bin\wx-console.conf" "$APPDATA\Bacula"
764   ${Else}
765     ${Unless} ${FileExists} "$APPDATA\Bacula\wx-console.conf"
766       File "/oname=$PLUGINSDIR\wx-console.conf.in" "wx-console.conf.in"
767       nsExec::ExecToLog '$PLUGINSDIR\sed.exe -f "$PLUGINSDIR\config.sed" -i.bak "$PLUGINSDIR\wx-console.conf.in"'
768       CopyFiles "$PLUGINSDIR\wx-console.conf.in" "$APPDATA\Bacula\wx-console.conf"
769     ${EndUnless}
770   ${EndIf}
771
772   ${If} $OsIsNT = 1
773     nsExec::ExecToLog 'cmd.exe /C echo Y|cacls "$R1" /G SYSTEM:F Administrators:F'
774   ${EndIf}
775
776   ; Create Start Menu entry
777   CreateShortCut "$SMPROGRAMS\Bacula\wx-console.lnk" "$INSTDIR\bin\wx-console.exe" '-c "$APPDATA\Bacula\wx-console.conf"' "$INSTDIR\bin\wx-console.exe" 0
778   CreateShortCut "$SMPROGRAMS\Bacula\Edit Graphical Console Configuration.lnk" "write.exe" '"$APPDATA\Bacula\wx-console.conf"'
779 SectionEnd
780
781 SectionGroupEnd
782
783 SectionGroup "Documentation" SecGroupDocumentation
784
785 Section "Documentation (Acrobat Format)" SecDocPdf
786   SectionIn 1 2 3
787
788   SetOutPath "$INSTDIR\doc"
789   CreateDirectory "$INSTDIR\doc"
790
791   File "${DOC_DIR}\manual\bacula.pdf"
792   CreateShortCut "$SMPROGRAMS\Bacula\Manual.lnk" '"$INSTDIR\doc\bacula.pdf"'
793 SectionEnd
794
795 Section "Documentation (HTML Format)" SecDocHtml
796   SectionIn 3
797
798   SetOutPath "$INSTDIR\doc"
799   CreateDirectory "$INSTDIR\doc"
800
801   File "${DOC_DIR}\manual\bacula\*.html"
802   File "${DOC_DIR}\manual\bacula\*.png"
803   File "${DOC_DIR}\manual\bacula\*.css"
804   CreateShortCut "$SMPROGRAMS\Bacula\Manual (HTML).lnk" '"$INSTDIR\doc\bacula.html"'
805 SectionEnd
806
807 SectionGroupEnd
808
809 Section "-Write Uninstaller"
810   Push $R0
811   ; Write the uninstall keys for Windows & create Start Menu entry
812   WriteRegStr   HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\Bacula" "DisplayName" "Bacula"
813   WriteRegStr   HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\Bacula" "InstallLocation" "$INSTDIR"
814   WriteRegStr   HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\Bacula" "DisplayVersion" "${VERSION}"
815   ${StrTok} $R0 "${VERSION}" "." 0 0
816   WriteRegDWORD HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\Bacula" "VersionMajor" $R0
817   ${StrTok} $R0 "${VERSION}" "." 1 0
818   WriteRegDWORD HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\Bacula" "VersionMinor" $R0
819   WriteRegDWORD HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\Bacula" "NoModify" 1
820   WriteRegDWORD HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\Bacula" "NoRepair" 1
821   WriteRegStr   HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\Bacula" "URLUpdateInfo" "http://sourceforge.net/project/showfiles.php?group_id=50727"
822   WriteRegStr   HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\Bacula" "URLInfoAbout" "http://www.bacula.org"
823   WriteRegStr   HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\Bacula" "HelpLink" "http://www.bacula.org/?page=support"
824   WriteRegStr   HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\Bacula" "UninstallString" '"$INSTDIR\uninstall.exe"'
825   WriteUninstaller "$INSTDIR\Uninstall.exe"
826   CreateShortCut "$SMPROGRAMS\Bacula\Uninstall Bacula.lnk" "$INSTDIR\Uninstall.exe" "" "$INSTDIR\Uninstall.exe" 0
827   Pop $R0
828 SectionEnd
829
830 ; Extra Page descriptions
831
832 LangString DESC_SecFileDaemon ${LANG_ENGLISH} "Install Bacula File Daemon on this system."
833 LangString DESC_SecStorageDaemon ${LANG_ENGLISH} "Install Bacula Storage Daemon on this system."
834 LangString DESC_SecDirectorDaemon ${LANG_ENGLISH} "Install Bacula Director Daemon on this system."
835 LangString DESC_SecConsole ${LANG_ENGLISH} "Install command console program on this system."
836 LangString DESC_SecWxConsole ${LANG_ENGLISH} "Install graphical console program on this system."
837 LangString DESC_SecDocPdf ${LANG_ENGLISH} "Install documentation in Acrobat format on this system."
838 LangString DESC_SecDocHtml ${LANG_ENGLISH} "Install documentation in HTML format on this system."
839
840 LangString TITLE_ConfigPage1 ${LANG_ENGLISH} "Configuration"
841 LangString SUBTITLE_ConfigPage1 ${LANG_ENGLISH} "Set installation configuration."
842
843 LangString TITLE_ConfigPage2 ${LANG_ENGLISH} "Configuration (continued)"
844 LangString SUBTITLE_ConfigPage2 ${LANG_ENGLISH} "Set installation configuration."
845
846 LangString TITLE_InstallType ${LANG_ENGLISH} "Installation Type"
847 LangString SUBTITLE_InstallType ${LANG_ENGLISH} "Choose installation type."
848
849 LangString TITLE_WriteTemplates ${LANG_ENGLISH} "Create Templates"
850 LangString SUBTITLE_WriteTemplates ${LANG_ENGLISH} "Create resource templates for inclusion in the Director's configuration file."
851
852 !InsertMacro MUI_FUNCTION_DESCRIPTION_BEGIN
853   !InsertMacro MUI_DESCRIPTION_TEXT ${SecFileDaemon} $(DESC_SecFileDaemon)
854   !InsertMacro MUI_DESCRIPTION_TEXT ${SecStorageDaemon} $(DESC_SecStorageDaemon)
855   !InsertMacro MUI_DESCRIPTION_TEXT ${SecDirectorDaemon} $(DESC_SecDirectorDaemon)
856   !InsertMacro MUI_DESCRIPTION_TEXT ${SecConsole} $(DESC_SecConsole)
857   !InsertMacro MUI_DESCRIPTION_TEXT ${SecWxConsole} $(DESC_SecWxConsole)
858   !InsertMacro MUI_DESCRIPTION_TEXT ${SecDocPdf} $(DESC_SecDocPdf)
859   !InsertMacro MUI_DESCRIPTION_TEXT ${SecDocHtml} $(DESC_SecDocHtml)
860 !InsertMacro MUI_FUNCTION_DESCRIPTION_END
861
862 ; Uninstall section
863
864 UninstallText "This will uninstall Bacula. Hit next to continue."
865
866 Section "Uninstall"
867   ; Shutdown any baculum that could be running
868   nsExec::ExecToLog '"$INSTDIR\bin\bacula-fd.exe" /silent /kill'
869   nsExec::ExecToLog '"$INSTDIR\bin\bacula-sd.exe" /silent /kill'
870   nsExec::ExecToLog '"$INSTDIR\bin\bacula-dir.exe" /silent /kill'
871   Sleep 3000
872
873   ReadRegDWORD $R0 HKLM "Software\Bacula" "Service_Bacula-fd"
874   ${If} $R0 = 1
875     ; Remove bacula service
876     nsExec::ExecToLog '"$INSTDIR\bin\bacula-fd.exe" /silent /remove'
877   ${EndIf}
878   
879   ReadRegDWORD $R0 HKLM "Software\Bacula" "Service_Bacula-sd"
880   ${If} $R0 = 1
881     ; Remove bacula service
882     nsExec::ExecToLog '"$INSTDIR\bin\bacula-sd.exe" /silent /remove'
883   ${EndIf}
884   
885   ReadRegDWORD $R0 HKLM "Software\Bacula" "Service_Bacula-dir"
886   ${If} $R0 = 1
887     ; Remove bacula service
888     nsExec::ExecToLog '"$INSTDIR\bin\bacula-dir.exe" /silent /remove'
889   ${EndIf}
890   
891   ; remove registry keys
892   DeleteRegKey HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\Bacula"
893   DeleteRegKey HKLM "Software\Bacula"
894
895   ; remove start menu items
896   SetShellVarContext all
897   Delete /REBOOTOK "$SMPROGRAMS\Bacula\*"
898   RMDir "$SMPROGRAMS\Bacula"
899
900   ; remove files and uninstaller (preserving config for now)
901   Delete /REBOOTOK "$INSTDIR\bin\*"
902   Delete /REBOOTOK "$INSTDIR\doc\*"
903   Delete /REBOOTOK "$INSTDIR\*"
904
905   ; Check for existing installation
906   MessageBox MB_YESNO|MB_ICONQUESTION \
907   "Would you like to delete the current configuration files and the working state file?" IDNO +7
908     Delete /REBOOTOK "$APPDATA\Bacula\*"
909     Delete /REBOOTOK "$APPDATA\Bacula\Work\*"
910     Delete /REBOOTOK "$APPDATA\Bacula\Spool\*"
911     RMDir "$APPDATA\Bacula\Work"
912     RMDir "$APPDATA\Bacula\Spool"
913     RMDir "$APPDATA\Bacula"
914
915   ; remove directories used
916   RMDir "$INSTDIR\bin"
917   RMDir "$INSTDIR\doc"
918   RMDir "$INSTDIR"
919 SectionEnd
920
921 ;
922 ; $0 - Service Name (ie Bacula-FD)
923 ; $1 - Service Description (ie Bacula File Daemon)
924 ; $2 - Install as Service
925 ; $3 - Start Service now
926 ;
927 Function InstallDaemon
928   Call InstallCommonFiles
929
930   WriteRegDWORD HKLM "Software\Bacula" "Service_$0" $2
931   
932   ${If} $2 = 1
933     nsExec::ExecToLog '"$INSTDIR\bin\$0.exe" /silent /install -c "$APPDATA\Bacula\$0.conf"'
934
935     ${If} $OsIsNT <> 1
936       File "Start.bat"
937       File "Stop.bat"
938     ${EndIf}
939
940     ; Start the service? (default skipped if silent, use /start to force starting)
941
942     ${If} $3 = 1  
943       ${If} $OsIsNT = 1
944         nsExec::ExecToLog 'net start $0'
945       ${Else}
946         Exec '"$INSTDIR\bin\$0.exe" -c "$APPDATA\Bacula\$0.conf"'
947       ${EndIf}
948     ${EndIf}
949   ${Else}
950     CreateShortCut "$SMPROGRAMS\Bacula\Start $1.lnk" "$INSTDIR\bin\$0.exe" '-c "$APPDATA\Bacula\$0.conf"' "$INSTDIR\bin\$0.exe" 0
951   ${EndIf}
952 FunctionEnd
953
954 Function GetComputerName
955   Push $R0
956   Push $R1
957   Push $R2
958
959   System::Call "kernel32::GetComputerNameA(t .R0, *i ${NSIS_MAX_STRLEN} R1) i.R2"
960
961   ${StrCase} $R0 $R0 "L"
962
963   Pop $R2
964   Pop $R1
965   Exch $R0
966 FunctionEnd
967
968 !define ComputerNameDnsFullyQualified   3
969
970 Function GetHostName
971   Push $R0
972   Push $R1
973   Push $R2
974
975   ${If} $OsIsNT = 1
976     System::Call "kernel32::GetComputerNameExA(i ${ComputerNameDnsFullyQualified}, t .R0, *i ${NSIS_MAX_STRLEN} R1) i.R2 ?e"
977     ${If} $R2 = 0
978       Pop $R2
979       DetailPrint "GetComputerNameExA failed - LastError = $R2"
980       Call GetComputerName
981       Pop $R0
982     ${Else}
983       Pop $R2
984     ${EndIf}
985   ${Else}
986     Call GetComputerName
987     Pop $R0
988   ${EndIf}
989
990   Pop $R2
991   Pop $R1
992   Exch $R0
993 FunctionEnd
994
995 !define NameUserPrincipal 8
996
997 Function GetUserName
998   Push $R0
999   Push $R1
1000   Push $R2
1001
1002   ${If} $OsIsNT = 1
1003     System::Call "secur32::GetUserNameExA(i ${NameUserPrincipal}, t .R0, *i ${NSIS_MAX_STRLEN} R1) i.R2 ?e"
1004     ${If} $R2 = 0
1005       Pop $R2
1006       DetailPrint "GetUserNameExA failed - LastError = $R2"
1007       Pop $R0
1008       StrCpy $R0 ""
1009     ${Else}
1010       Pop $R2
1011     ${EndIf}
1012   ${Else}
1013       StrCpy $R0 ""
1014   ${EndIf}
1015
1016   ${If} $R0 == ""
1017     System::Call "advapi32::GetUserNameA(t .R0, *i ${NSIS_MAX_STRLEN} R1) i.R2 ?e"
1018     ${If} $R2 = 0
1019       Pop $R2
1020       DetailPrint "GetUserNameA failed - LastError = $R2"
1021       StrCpy $R0 ""
1022     ${Else}
1023       Pop $R2
1024     ${EndIf}
1025   ${EndIf}
1026
1027   Pop $R2
1028   Pop $R1
1029   Exch $R0
1030 FunctionEnd
1031
1032 Function IsDirectorSelected
1033   Push $R0
1034   SectionGetFlags ${SecDirectorDaemon} $R0
1035   IntOp $R0 $R0 & ${SF_SELECTED}
1036   Exch $R0
1037 FunctionEnd
1038
1039 Function GetSelectedComponents
1040   Push $R0
1041   StrCpy $R0 0
1042   ${If} ${SectionIsSelected} ${SecFileDaemon}
1043     IntOp $R0 $R0 | ${ComponentFile}
1044   ${EndIf}
1045   ${If} ${SectionIsSelected} ${SecStorageDaemon}
1046     IntOp $R0 $R0 | ${ComponentStorage}
1047   ${EndIf}
1048   ${If} ${SectionIsSelected} ${SecDirectorDaemon}
1049     IntOp $R0 $R0 | ${ComponentDirector}
1050   ${EndIf}
1051   ${If} ${SectionIsSelected} ${SecConsole}
1052     IntOp $R0 $R0 | ${ComponentTextConsole}
1053   ${EndIf}
1054   ${If} ${SectionIsSelected} ${SecWxConsole}
1055     IntOp $R0 $R0 | ${ComponentGUIConsole}
1056   ${EndIf}
1057   ${If} ${SectionIsSelected} ${SecDocPdf}
1058     IntOp $R0 $R0 | ${ComponentPDFDocs}
1059   ${EndIf}
1060   ${If} ${SectionIsSelected} ${SecDocHtml}
1061     IntOp $R0 $R0 | ${ComponentHTMLDocs}
1062   ${EndIf}
1063   Exch $R0
1064 FunctionEnd
1065
1066 Function PageComponentsShow
1067   ${If} $OsIsNT != 1
1068     Call DisableServerSections
1069   ${EndIf}
1070
1071   Call SelectPreviousComponents
1072   Call UpdateComponentUI
1073 FunctionEnd
1074
1075 Function PageDirectoryPre
1076   ${If} $AutomaticInstall = 1
1077   ${OrIf} $InstallType = ${UpgradeInstall}
1078     Abort
1079   ${EndIf}
1080 FunctionEnd
1081
1082 Function LeaveInstallPage
1083   Push "$INSTDIR\install.log"
1084   Call DumpLog
1085 FunctionEnd
1086
1087 Function EnterWriteTemplates
1088   Push $R0
1089   Push $R1
1090
1091   Call GetSelectedComponents
1092   Pop $R0
1093
1094   IntOp $R0 $R0 & ${ComponentDirector}
1095   IntOp $R1 $NewComponents & ${ComponentsFileAndStorage}
1096
1097   ${If} $R0 <> 0
1098   ${OrIf} $R1 = 0
1099     Pop $R1
1100     Pop $R0
1101     Abort
1102   ${EndIf}
1103
1104   IntOp $R0 $NewComponents & ${ComponentFile}
1105   ${If} $R0 = 0
1106     WriteINIStr "$PLUGINSDIR\WriteTemplates.ini" "Field 2" State 0
1107     WriteINIStr "$PLUGINSDIR\WriteTemplates.ini" "Field 2" Flags DISABLED
1108     DeleteINIStr "$PLUGINSDIR\WriteTemplates.ini" "Field 3" State
1109     WriteINIStr "$PLUGINSDIR\WriteTemplates.ini" "Field 3" Flags REQ_SAVE|FILE_EXPLORER|WARN_IF_EXIST|DISABLED
1110   ${Else}
1111     WriteINIStr "$PLUGINSDIR\WriteTemplates.ini" "Field 2" State 1
1112     DeleteINIStr "$PLUGINSDIR\WriteTemplates.ini" "Field 2" Flags
1113     WriteINIStr "$PLUGINSDIR\WriteTemplates.ini" "Field 3" State "C:\$ConfigClientName.conf"
1114     WriteINIStr "$PLUGINSDIR\WriteTemplates.ini" "Field 5" Flags REQ_SAVE|FILE_EXPLORER|WARN_IF_EXIST
1115   ${EndIf}
1116
1117   IntOp $R0 $NewComponents & ${ComponentStorage}
1118   ${If} $R0 = 0
1119     WriteINIStr "$PLUGINSDIR\WriteTemplates.ini" "Field 4" State 0
1120     WriteINIStr "$PLUGINSDIR\WriteTemplates.ini" "Field 4" Flags DISABLED
1121     DeleteINIStr "$PLUGINSDIR\WriteTemplates.ini" "Field 5" State
1122     WriteINIStr "$PLUGINSDIR\WriteTemplates.ini" "Field 5" Flags REQ_SAVE|FILE_EXPLORER|WARN_IF_EXIST|DISABLED
1123   ${Else}
1124     WriteINIStr "$PLUGINSDIR\WriteTemplates.ini" "Field 4" State 1
1125     DeleteINIStr "$PLUGINSDIR\WriteTemplates.ini" "Field 4" Flags
1126     WriteINIStr "$PLUGINSDIR\WriteTemplates.ini" "Field 5" State "C:\$ConfigStorageName.conf"
1127     WriteINIStr "$PLUGINSDIR\WriteTemplates.ini" "Field 5" Flags REQ_SAVE|FILE_EXPLORER|WARN_IF_EXIST
1128   ${EndIf}
1129
1130   !InsertMacro MUI_HEADER_TEXT "$(TITLE_WriteTemplates)" "$(SUBTITLE_WriteTemplates)"
1131   !InsertMacro MUI_INSTALLOPTIONS_DISPLAY "WriteTemplates.ini"
1132
1133   !InsertMacro MUI_INSTALLOPTIONS_READ $R0 "WriteTemplates.ini" "Field 2" State
1134   ${If} $R0 <> 0
1135     File "/oname=$PLUGINSDIR\client.conf.in" "client.conf.in"
1136
1137     nsExec::ExecToLog '$PLUGINSDIR\sed.exe -f "$PLUGINSDIR\config.sed" -i.bak "$PLUGINSDIR\client.conf.in"'
1138     !InsertMacro MUI_INSTALLOPTIONS_READ $R0 "WriteTemplates.ini" "Field 3" State
1139     ${If} $R0 != ""
1140       CopyFiles "$PLUGINSDIR\client.conf.in" "$R0"
1141     ${EndIf}
1142   ${EndIf}
1143
1144   !InsertMacro MUI_INSTALLOPTIONS_READ $R0 "WriteTemplates.ini" "Field 4" State
1145   ${If} $R0 <> 0
1146     File "/oname=$PLUGINSDIR\storage.conf.in" "storage.conf.in"
1147
1148     nsExec::ExecToLog '$PLUGINSDIR\sed.exe -f "$PLUGINSDIR\config.sed" -i.bak "$PLUGINSDIR\storage.conf.in"'
1149     !InsertMacro MUI_INSTALLOPTIONS_READ $R0 "WriteTemplates.ini" "Field 5" State
1150     ${If} $R0 != ""
1151       CopyFiles "$PLUGINSDIR\storage.conf.in" "$R0"
1152     ${EndIf}
1153   ${EndIf}
1154
1155   Pop $R1
1156   Pop $R0
1157 FunctionEnd
1158
1159 Function SelectPreviousComponents
1160   ${If} $InstallType <> ${NewInstall}
1161     IntOp $R1 $PreviousComponents & ${ComponentFile}
1162     ${If} $R1 <> 0
1163       !InsertMacro SelectSection ${SecFileDaemon}
1164       !InsertMacro SetSectionFlag ${SecFileDaemon} ${SF_RO}
1165     ${Else}
1166       !InsertMacro UnselectSection ${SecFileDaemon}
1167       !InsertMacro ClearSectionFlag ${SecFileDaemon} ${SF_RO}
1168     ${EndIf}
1169     IntOp $R1 $PreviousComponents & ${ComponentStorage}
1170     ${If} $R1 <> 0
1171       !InsertMacro SelectSection ${SecStorageDaemon}
1172       !InsertMacro SetSectionFlag ${SecStorageDaemon} ${SF_RO}
1173     ${Else}
1174       !InsertMacro UnselectSection ${SecStorageDaemon}
1175       !InsertMacro ClearSectionFlag ${SecStorageDaemon} ${SF_RO}
1176     ${EndIf}
1177     IntOp $R1 $PreviousComponents & ${ComponentDirector}
1178     ${If} $R1 <> 0
1179       !InsertMacro SelectSection ${SecDirectorDaemon}
1180       !InsertMacro SetSectionFlag ${SecDirectorDaemon} ${SF_RO}
1181     ${Else}
1182       !InsertMacro UnselectSection ${SecDirectorDaemon}
1183       !InsertMacro ClearSectionFlag ${SecDirectorDaemon} ${SF_RO}
1184     ${EndIf}
1185     IntOp $R1 $PreviousComponents & ${ComponentTextConsole}
1186     ${If} $R1 <> 0
1187       !InsertMacro SelectSection ${SecConsole}
1188       !InsertMacro SetSectionFlag ${SecConsole} ${SF_RO}
1189     ${Else}
1190       !InsertMacro UnselectSection ${SecConsole}
1191       !InsertMacro ClearSectionFlag ${SecConsole} ${SF_RO}
1192     ${EndIf}
1193     IntOp $R1 $PreviousComponents & ${ComponentGUIConsole}
1194     ${If} $R1 <> 0
1195       !InsertMacro SelectSection ${SecWxConsole}
1196       !InsertMacro SetSectionFlag ${SecWxConsole} ${SF_RO}
1197     ${Else}
1198       !InsertMacro UnselectSection ${SecWxConsole}
1199       !InsertMacro ClearSectionFlag ${SecWxConsole} ${SF_RO}
1200     ${EndIf}
1201     IntOp $R1 $PreviousComponents & ${ComponentPDFDocs}
1202     ${If} $R1 <> 0
1203       !InsertMacro SelectSection ${SecDocPdf}
1204       !InsertMacro SetSectionFlag ${SecDocPdf} ${SF_RO}
1205     ${Else}
1206       !InsertMacro UnselectSection ${SecDocPdf}
1207       !InsertMacro ClearSectionFlag ${SecDocPdf} ${SF_RO}
1208     ${EndIf}
1209     IntOp $R1 $PreviousComponents & ${ComponentHTMLDocs}
1210     ${If} $R1 <> 0
1211       !InsertMacro SelectSection ${SecDocHtml}
1212       !InsertMacro SetSectionFlag ${SecDocHtml} ${SF_RO}
1213     ${Else}
1214       !InsertMacro UnselectSection ${SecDocHtml}
1215       !InsertMacro ClearSectionFlag ${SecDocHtml} ${SF_RO}
1216     ${EndIf}
1217   ${EndIf}
1218 FunctionEnd
1219
1220 Function DisableServerSections
1221   !InsertMacro UnselectSection ${SecGroupServer}
1222   !InsertMacro SetSectionFlag  ${SecGroupServer} ${SF_RO}
1223   !InsertMacro UnselectSection ${SecStorageDaemon}
1224   !InsertMacro SetSectionFlag  ${SecStorageDaemon} ${SF_RO}
1225   !InsertMacro UnselectSection ${SecDirectorDaemon}
1226   !InsertMacro SetSectionFlag  ${SecDirectorDaemon} ${SF_RO}
1227 FunctionEnd
1228
1229 Function UpdateComponentUI
1230   Push $R0
1231   Push $R1
1232
1233   Call GetSelectedComponents
1234   Pop $R0
1235
1236   IntOp $R1 $R0 ^ $PreviousComponents
1237   IntOp $NewComponents $R0 & $R1
1238
1239   ${If} $InstallType <> ${NewInstall}
1240     IntOp $R1 $NewComponents & ${ComponentFile}
1241     ${If} $R1 <> 0
1242       !InsertMacro SetSectionFlag ${SecFileDaemon} ${SF_BOLD}
1243     ${Else}
1244       !InsertMacro ClearSectionFlag ${SecFileDaemon} ${SF_BOLD}
1245     ${EndIf}
1246     IntOp $R1 $NewComponents & ${ComponentStorage}
1247     ${If} $R1 <> 0
1248       !InsertMacro SetSectionFlag ${SecStorageDaemon} ${SF_BOLD}
1249     ${Else}
1250       !InsertMacro ClearSectionFlag ${SecStorageDaemon} ${SF_BOLD}
1251     ${EndIf}
1252     IntOp $R1 $NewComponents & ${ComponentDirector}
1253     ${If} $R1 <> 0
1254       !InsertMacro SetSectionFlag ${SecDirectorDaemon} ${SF_BOLD}
1255     ${Else}
1256       !InsertMacro ClearSectionFlag ${SecDirectorDaemon} ${SF_BOLD}
1257     ${EndIf}
1258     IntOp $R1 $NewComponents & ${ComponentTextConsole}
1259     ${If} $R1 <> 0
1260       !InsertMacro SetSectionFlag ${SecConsole} ${SF_BOLD}
1261     ${Else}
1262       !InsertMacro ClearSectionFlag ${SecConsole} ${SF_BOLD}
1263     ${EndIf}
1264     IntOp $R1 $NewComponents & ${ComponentGUIConsole}
1265     ${If} $R1 <> 0
1266       !InsertMacro SetSectionFlag ${SecWxConsole} ${SF_BOLD}
1267     ${Else}
1268       !InsertMacro ClearSectionFlag ${SecWxConsole} ${SF_BOLD}
1269     ${EndIf}
1270     IntOp $R1 $NewComponents & ${ComponentPDFDocs}
1271     ${If} $R1 <> 0
1272       !InsertMacro SetSectionFlag ${SecDocPdf} ${SF_BOLD}
1273     ${Else}
1274       !InsertMacro ClearSectionFlag ${SecDocPdf} ${SF_BOLD}
1275     ${EndIf}
1276     IntOp $R1 $NewComponents & ${ComponentHTMLDocs}
1277     ${If} $R1 <> 0
1278       !InsertMacro SetSectionFlag ${SecDocHtml} ${SF_BOLD}
1279     ${Else}
1280       !InsertMacro ClearSectionFlag ${SecDocHtml} ${SF_BOLD}
1281     ${EndIf}
1282   ${EndIf}
1283
1284   GetDlgItem $R0 $HWNDPARENT 1
1285
1286   IntOp $R1 $NewComponents & ${ComponentsRequiringUserConfig}
1287   ${If} $R1 = 0
1288     SendMessage $R0 ${WM_SETTEXT} 0 "STR:Install"
1289   ${Else}
1290     SendMessage $R0 ${WM_SETTEXT} 0 "STR:&Next >"
1291   ${EndIf}
1292
1293   Pop $R1
1294   Pop $R0
1295 FunctionEnd
1296
1297 !include "InstallType.nsh"
1298 !include "ConfigPage1.nsh"
1299 !include "ConfigPage2.nsh"
1300 !include "DumpLog.nsh"