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