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