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