]> git.sur5r.net Git - bacula/bacula/blob - bacula/src/win32/win64_installer/winbacula.nsi
Fix build of Windows bat -- Qt depends on libgcc_s_dw2-1.dll
[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 = Bat Console
189 ;     5 = wxWidgits Console
190 ;     6 = Documentation (PDF)
191 ;     7 = Documentation (HTML)
192
193 !define ComponentFile                   1
194 !define ComponentStorage                2
195 !define ComponentDirector               4
196 !define ComponentTextConsole            8
197 !define ComponentBatConsole             16
198 !define ComponentGUIConsole             32
199 !define ComponentPDFDocs                64
200 !define ComponentHTMLDocs               128
201
202 !define ComponentsRequiringUserConfig           63
203 !define ComponentsFileAndStorage                3
204 !define ComponentsFileAndStorageAndDirector     7
205 !define ComponentsDirectorAndTextGuiConsoles    60
206 !define ComponentsTextAndGuiConsoles            56
207
208 Var HDLG
209 Var HCTL
210
211 Function .onInit
212   Push $R0
213   Push $R1
214
215   ; Process Command Line Options
216   StrCpy $OptService 1
217   StrCpy $OptStart 1
218   StrCpy $OptSilent 0
219   StrCpy $CommonFilesDone 0
220   StrCpy $OsIsNT 0
221   StrCpy $AutomaticInstall 0
222   StrCpy $InstallType ${NewInstall}
223   StrCpy $OldInstallDir ""
224   StrCpy $PreviousComponents 0
225   StrCpy $NewComponents 0
226   StrCpy $MySQLPath ""
227   StrCpy $MySQLVersion ""
228   StrCpy $PostgreSQLPath ""
229   StrCpy $PostgreSQLVersion ""
230   StrCpy $LocalDirectorPassword ""
231
232   ${GetParameters} $R0
233
234   ClearErrors
235   ${GetOptions} $R0 "/noservice" $R1
236   IfErrors +2
237     StrCpy $OptService 0
238
239   ClearErrors
240   ${GetOptions} $R0 "/nostart" $R1
241   IfErrors +2
242     StrCpy $OptStart 0
243
244   IfSilent 0 +2
245     StrCpy $OptSilent 1
246
247   ReadRegStr $R0 HKLM "SOFTWARE\Microsoft\Windows NT\CurrentVersion" CurrentVersion
248   ${If} $R0 != ""
249     StrCpy $OsIsNT 1
250   ${EndIf}
251
252   Call GetComputerName
253   Pop $HostName
254
255   Call GetHostName
256   Pop $LocalHostAddress
257
258   Call GetUserName
259
260   ; Configuration Defaults
261
262   StrCpy $ConfigClientName               "$HostName-fd"
263   StrCpy $ConfigClientPort               9102
264   StrCpy $ConfigClientMaxJobs            10
265   ;StrCpy $ConfigClientPassword
266   StrCpy $ConfigClientInstallService     "$OptService"
267   StrCpy $ConfigClientStartService       "$OptStart"
268
269   StrCpy $ConfigDirectorPort             9101
270
271   StrCpy $ConfigMonitorName              "$HostName-mon"
272   ;StrCpy $ConfigMonitorPassword
273
274 ; PLUGINSDIR refers to temporary helper programs and not Bacula plugins!
275   InitPluginsDir
276   File "/oname=$PLUGINSDIR\openssl.exe"  "${SRC_DIR}\openssl.exe"
277   File "/oname=$PLUGINSDIR\ssleay32-0.9.8.dll" "${SRC_DIR}\ssleay32-0.9.8.dll"
278   File "/oname=$PLUGINSDIR\cryptoeay32-0.9.8.dll" "${SRC_DIR}\cryptoeay32-0.9.8.dll"        
279 ;  File "/oname=$PLUGINSDIR\libeay32.dll" "${SRC_DIR}\libeay32.dll"
280 ;  File "/oname=$PLUGINSDIR\ssleay32.dll" "${SRC_DIR}\ssleay32.dll"
281   File "/oname=$PLUGINSDIR\sed.exe"      "${SRC_DIR}\sed.exe"
282
283   !InsertMacro MUI_INSTALLOPTIONS_EXTRACT "InstallType.ini"
284   !InsertMacro MUI_INSTALLOPTIONS_EXTRACT "WriteTemplates.ini"
285
286   SetPluginUnload alwaysoff
287
288 ; Set client password
289   nsExec::Exec '"$PLUGINSDIR\openssl.exe" rand -base64 -out $PLUGINSDIR\pw.txt 33'
290   pop $R0
291   ${If} $R0 = 0
292    FileOpen $R1 "$PLUGINSDIR\pw.txt" r
293    IfErrors +4
294      FileRead $R1 $R0
295      ${StrTrimNewLines} $ConfigClientPassword $R0
296      FileClose $R1
297   ${EndIf}
298
299   SetPluginUnload manual
300
301 ; Set monitor password
302   nsExec::Exec '"$PLUGINSDIR\openssl.exe" rand -base64 -out $PLUGINSDIR\pw.txt 33'
303   pop $R0
304   ${If} $R0 = 0
305    FileOpen $R1 "$PLUGINSDIR\pw.txt" r
306    IfErrors +4
307      FileRead $R1 $R0
308      ${StrTrimNewLines} $ConfigMonitorPassword $R0
309      FileClose $R1
310   ${EndIf}
311
312   Pop $R1
313   Pop $R0
314 FunctionEnd
315
316 Function .onSelChange
317   Call UpdateComponentUI
318 FunctionEnd
319
320 Function InstallCommonFiles
321   ${If} $CommonFilesDone = 0
322     SetOutPath "$INSTDIR"
323     File "Readme.txt"
324
325     SetOutPath "$INSTDIR"
326 !if "${BUILD_TOOLS}" == "MinGW32"
327     File "${SRC_DIR}\mingwm10.dll"
328     File "${SRC_DIR}\pthreadGCE.dll"
329     File "${SRC_DIR}\zlib1.dll"
330     File "${SRC_DIR}\ssleay32.dll"
331     File "${SRC_DIR}\libeay32.dll"
332 !endif
333 !if "${BUILD_TOOLS}" == "MinGW64"
334     File "${SRC_DIR}\pthreadGCE.dll"
335     File "${SRC_DIR}\cryptoeay32-0.9.8.dll"
336     File "${SRC_DIR}\ssleay32-0.9.8.dll"
337     File "${SRC_DIR}\zlib1.dll"
338 !endif
339     File "${SRC_DIR}\bacula.dll"
340     File "/oname=$INSTDIR\openssl.cnf" "${SRC_DIR}\openssl.cnf"
341     File "${SRC_DIR}\openssl.exe"
342     File "${SRC_DIR}\bsleep.exe"
343     File "${SRC_DIR}\bsmtp.exe"
344     File "${SRC_DIR}\expr64.exe"
345     File "${SRC_DIR}\snooze.exe"
346
347     CreateShortCut "$SMPROGRAMS\Bacula\Documentation\View Readme.lnk" "write.exe" '"$INSTDIR\Readme.txt"'
348
349     StrCpy $CommonFilesDone 1
350   ${EndIf}
351 FunctionEnd
352
353 Section "-Initialize"
354
355   WriteRegStr   HKLM Software\Bacula InstallLocation "$INSTDIR"
356
357   Call GetSelectedComponents
358   Pop $R2
359   WriteRegDWORD HKLM Software\Bacula Components $R2
360
361   ; remove start menu items
362   SetShellVarContext all
363
364   Delete /REBOOTOK "$SMPROGRAMS\Bacula\Configuration\*"
365   Delete /REBOOTOK "$SMPROGRAMS\Bacula\Documentation\*"
366   Delete /REBOOTOK "$SMPROGRAMS\Bacula\*"
367   RMDir "$SMPROGRAMS\Bacula\Configuration"
368   RMDir "$SMPROGRAMS\Bacula\Documentation"
369   RMDir "$SMPROGRAMS\Bacula"
370   CreateDirectory "$SMPROGRAMS\Bacula"
371   CreateDirectory "$SMPROGRAMS\Bacula\Configuration"
372   CreateDirectory "$SMPROGRAMS\Bacula\Documentation"
373
374   CreateDirectory "$INSTDIR"
375   CreateDirectory "$INSTDIR\working"
376
377   SetOutPath "$INSTDIR"
378   File "..\..\..\LICENSE"
379   Delete /REBOOTOK "$INSTDIR\License.txt"
380
381 ; Output a series of SED commands to configure the .conf file(s)
382   FileOpen $R1 $PLUGINSDIR\config.sed w
383   FileWrite $R1 "s;@VERSION@;${VERSION};g$\r$\n"
384   FileWrite $R1 "s;@DATE@;${__DATE__};g$\r$\n"
385   FileWrite $R1 "s;@DISTNAME@;Windows;g$\r$\n"
386
387   StrCpy $R2 ${BUILD_TOOLS}
388
389   Call GetHostName
390   Exch $R3
391   Pop $R3
392
393   FileWrite $R1 "s;@DISTVER@;$R2;g$\r$\n"
394
395   ${StrRep} $R2 "$INSTDIR\working" "\" "\\\\"
396   FileWrite $R1 's;@working_dir@;$R2;g$\r$\n'
397   ${StrRep} $R2 "$INSTDIR\working" "\" "\\"
398   FileWrite $R1 's;@working_dir_cmd@;$R2;g$\r$\n'
399
400   ${StrRep} $R2 "$INSTDIR" "\" "\\\\"
401   FileWrite $R1 's;@bin_dir@;$R2;g$\r$\n'
402   ${StrRep} $R2 "$INSTDIR" "\" "\\"
403   FileWrite $R1 's;@bin_dir_cmd@;$R2;g$\r$\n'
404
405   ${StrRep} $R2 "$INSTDIR\plugins" "\" "\\\\"
406   FileWrite $R1 's;@fdplugins_dir@;$R2;g$\r$\n'
407
408   ${StrRep} $R2 "$INSTDIR" "\" "/"
409   FileWrite $R1 "s;@BUILD_DIR@;$R2;g$\r$\n"
410
411   FileWrite $R1 "s;@client_address@;$LocalHostAddress;g$\r$\n"
412
413   ${If} "$ConfigClientName" != ""
414     FileWrite $R1 "s;@client_name@;$ConfigClientName;g$\r$\n"
415   ${EndIf}
416   ${If} "$ConfigClientPort" != ""
417     FileWrite $R1 "s;@client_port@;$ConfigClientPort;g$\r$\n"
418   ${EndIf}
419   ${If} "$ConfigClientMaxJobs" != ""
420     FileWrite $R1 "s;@client_maxjobs@;$ConfigClientMaxJobs;g$\r$\n"
421   ${EndIf}
422   ${If} "$ConfigClientPassword" != ""
423     FileWrite $R1 "s;@client_password@;$ConfigClientPassword;g$\r$\n"
424   ${EndIf}
425   ${If} "$ConfigDirectorName" != ""
426     FileWrite $R1 "s;@director_name@;$ConfigDirectorName;g$\r$\n"
427   ${EndIf}
428   ${If} "$ConfigDirectorPort" != ""
429     FileWrite $R1 "s;@director_port@;$ConfigDirectorPort;g$\r$\n"
430   ${EndIf}
431   ${If} "$ConfigDirectorPassword" != ""
432     FileWrite $R1 "s;@director_password@;$ConfigDirectorPassword;g$\r$\n"
433   ${EndIf}
434   ${If} "$ConfigDirectorAddress" != ""
435     FileWrite $R1 "s;@director_address@;$ConfigDirectorAddress;g$\r$\n"
436   ${EndIf}
437   ${If} "$ConfigMonitorName" != ""
438     FileWrite $R1 "s;@monitor_name@;$ConfigMonitorName;g$\r$\n"
439   ${EndIf}
440   ${If} "$ConfigMonitorPassword" != ""
441     FileWrite $R1 "s;@monitor_password@;$ConfigMonitorPassword;g$\r$\n"
442   ${EndIf}
443
444   FileClose $R1
445
446   ${If} ${FileExists} "$OldInstallDir\bacula-fd.exe"
447     nsExec::ExecToLog '"$OldInstallDir\bacula-fd.exe" /kill'     ; Shutdown any bacula that could be running
448     Sleep 3000
449     nsExec::ExecToLog '"$OldInstallDir\bacula-fd.exe" /remove'   ; Remove existing service
450   ${EndIf}
451
452 SectionEnd
453
454 SectionGroup "Client" SecGroupClient
455
456 Section "File Service" SecFileDaemon
457   SectionIn 1 2 3
458
459   SetOutPath "$INSTDIR\plugins"
460   File "${SRC_DIR}\exchange-fd.dll"
461
462   SetOutPath "$INSTDIR"
463
464   File "${SRC_DIR}\bacula-fd.exe"
465
466   File "/oname=$PLUGINSDIR\bacula-fd.conf" "bacula-fd.conf.in"
467
468   StrCpy $0 "$INSTDIR"
469   StrCpy $1 bacula-fd.conf
470   Call ConfigEditAndCopy
471
472   StrCpy $0 bacula-fd
473   StrCpy $1 "File Service"
474   StrCpy $2 $ConfigClientInstallService
475   StrCpy $3 $ConfigClientStartService
476
477   Call InstallDaemon
478
479   CreateShortCut "$SMPROGRAMS\Bacula\Configuration\Edit Client Configuration.lnk" "write.exe" '"$INSTDIR\bacula-fd.conf"'
480 SectionEnd
481
482 SectionGroupEnd
483
484 SectionGroup "Consoles" SecGroupConsoles
485
486 Section "Command Console" SecConsole
487   SectionIn 1 2 3
488
489   SetOutPath "$INSTDIR"
490
491   File "${SRC_DIR}\bconsole.exe"
492   Call InstallCommonFiles
493
494   File "/oname=$PLUGINSDIR\bconsole.conf" "bconsole.conf.in"
495   StrCpy $0 "$INSTDIR"
496   StrCpy $1 bconsole.conf
497   Call ConfigEditAndCopy
498
499   CreateShortCut "$SMPROGRAMS\Bacula\bconsole.lnk" "$INSTDIR\bconsole.exe" '-c "$INSTDIR\bconsole.conf"' "$INSTDIR\bconsole.exe" 0
500   CreateShortCut "$SMPROGRAMS\Bacula\Configuration\Edit Command Console Configuration.lnk" "write.exe" '"$INSTDIR\bconsole.conf"'
501
502 SectionEnd
503
504 Section "Bat Console" SecBatConsole
505   SectionIn 1 2 3
506
507   SetOutPath "$INSTDIR\bin32"
508
509   Call InstallCommonFiles
510   File "${SRC_DIR}\QtCore4.dll"
511   File "${SRC_DIR}\QtGui4.dll"
512   File "${SRC_DIR}\libgcc_s_dw2-1.dll"
513   File "${SRC_DIR}\mingwm10.dll"
514   File "${SRC_DIR}\ssleay32.dll"
515   File "${SRC_DIR}\libeay32.dll"
516   File "${SRC_DIR}\bat.exe"
517   File "/oname=$INSTDIR\bin32\bacula.dll" "${SRC_DIR}\bacula32.dll"
518   File "/oname=$INSTDIR\bin32\pthreadGCE.dll" "${SRC_DIR}\pthreadGCE32.dll"
519   File "/oname=$INSTDIR\bin32\zlib1.dll" "${SRC_DIR}\zlib132.dll"
520
521   File "/oname=$PLUGINSDIR\bat.conf" "bat.conf.in"
522   StrCpy $0 "$INSTDIR\bin32"
523   StrCpy $1 bat.conf
524   Call ConfigEditAndCopy
525
526   SetOutPath "$INSTDIR\help"
527   File "${SRC_DIR}\help\*"
528   SetOutPath "$INSTDIR"
529
530
531   ; Create Start Menu entry
532   CreateShortCut "$SMPROGRAMS\Bacula\Bat.lnk" "$INSTDIR\bin32\bat.exe" '-c "$INSTDIR\bin32\bat.conf"' "$INSTDIR\bin32\bat.exe" 0
533   CreateShortCut "$SMPROGRAMS\Bacula\Configuration\Edit Bat Configuration.lnk" "write.exe" '"$INSTDIR\bin32\bat.conf"'
534   SetOutPath "$INSTDIR"
535 SectionEnd
536
537 SectionGroupEnd
538
539
540 Section "-Finish"
541   Push $R0
542
543   ${If} $OsIsNT = 1
544 ;   nsExec::ExecToLog 'cmd.exe /C echo Y|cacls "$INSTDIR" /T /G SYSTEM:F Administrators:F'
545   ${EndIf}
546
547   ; Write the uninstall keys for Windows & create Start Menu entry
548   WriteRegStr   HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\Bacula" "DisplayName" "Bacula"
549   WriteRegStr   HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\Bacula" "InstallLocation" "$INSTDIR"
550   WriteRegStr   HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\Bacula" "DisplayVersion" "${VERSION}"
551   ${StrTok} $R0 "${VERSION}" "." 0 0
552   WriteRegDWORD HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\Bacula" "VersionMajor" $R0
553   ${StrTok} $R0 "${VERSION}" "." 1 0
554   WriteRegDWORD HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\Bacula" "VersionMinor" $R0
555   WriteRegDWORD HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\Bacula" "NoModify" 1
556   WriteRegDWORD HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\Bacula" "NoRepair" 1
557   WriteRegStr   HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\Bacula" "URLUpdateInfo" "http://www.bacula.org"
558   WriteRegStr   HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\Bacula" "URLInfoAbout" "http://www.bacula.org"
559   WriteRegStr   HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\Bacula" "HelpLink" "http://www.bacula.org?page=support"
560   WriteRegStr   HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\Bacula" "UninstallString" '"$INSTDIR\uninstall.exe"'
561   WriteUninstaller "$INSTDIR\Uninstall.exe"
562   CreateShortCut "$SMPROGRAMS\Bacula\Uninstall Bacula.lnk" "$INSTDIR\Uninstall.exe" "" "$INSTDIR\Uninstall.exe" 0
563   Pop $R0
564 SectionEnd
565
566 ; Extra Page descriptions
567
568 LangString DESC_SecFileDaemon ${LANG_ENGLISH} "Install Bacula File Daemon on this system."
569 LangString DESC_SecConsole ${LANG_ENGLISH} "Install command console program on this system."
570 LangString DESC_SecBatConsole ${LANG_ENGLISH} "Install Bat graphical console program on this system."
571
572 LangString TITLE_ConfigPage1 ${LANG_ENGLISH} "Configuration"
573 LangString SUBTITLE_ConfigPage1 ${LANG_ENGLISH} "Set installation configuration."
574
575 LangString TITLE_ConfigPage2 ${LANG_ENGLISH} "Configuration (continued)"
576 LangString SUBTITLE_ConfigPage2 ${LANG_ENGLISH} "Set installation configuration."
577
578 LangString TITLE_InstallType ${LANG_ENGLISH} "Installation Type"
579 LangString SUBTITLE_InstallType ${LANG_ENGLISH} "Choose installation type."
580
581 LangString TITLE_WriteTemplates ${LANG_ENGLISH} "Create Templates"
582 LangString SUBTITLE_WriteTemplates ${LANG_ENGLISH} "Create a resource template for inclusion in the Director's configuration file."
583
584 !InsertMacro MUI_FUNCTION_DESCRIPTION_BEGIN
585   !InsertMacro MUI_DESCRIPTION_TEXT ${SecFileDaemon} $(DESC_SecFileDaemon)
586   !InsertMacro MUI_DESCRIPTION_TEXT ${SecConsole} $(DESC_SecConsole)
587   !InsertMacro MUI_DESCRIPTION_TEXT ${SecBatConsole} $(DESC_SecBatConsole)
588 !InsertMacro MUI_FUNCTION_DESCRIPTION_END
589
590 ; Uninstall section
591
592 UninstallText "This will uninstall Bacula. Click Uninstall to continue."
593
594 Section "Uninstall"
595   ; Shutdown any baculum that could be running
596   nsExec::ExecToLog '"$INSTDIR\bacula-fd.exe" /kill'
597   Sleep 3000
598
599 ; ReadRegDWORD $R0 HKLM "Software\Bacula" "Service_Bacula-fd"
600   ; Remove bacula service
601   nsExec::ExecToLog '"$INSTDIR\bacula-fd.exe" /remove'
602   nsExec::ExecToLog '"$INSTDIR\plugins\exchange-fd.dll" /remove'
603   
604   ; remove registry keys
605   DeleteRegKey HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\Bacula"
606   DeleteRegKey HKLM "Software\Bacula"
607
608   ; remove start menu items
609   SetShellVarContext all
610   Delete /REBOOTOK "$SMPROGRAMS\Bacula\*"
611   RMDir "$SMPROGRAMS\Bacula"
612
613   ; remove files and uninstaller (preserving config for now)
614   Delete /REBOOTOK "$INSTDIR\doc\*"
615   Delete /REBOOTOK "$INSTDIR\*"
616   Delete /REBOOTOK "$INSTDIR\help\*"
617
618   ; Check for existing installation
619   MessageBox MB_YESNO|MB_ICONQUESTION \
620   "Would you like to delete the current configuration files and the working state file?" IDNO NoDel
621     Delete /REBOOTOK "$INSTDIR\*"
622     Delete /REBOOTOK "$INSTDIR\bin32\*"
623     Delete /REBOOTOK "$INSTDIR\working\*"
624     Delete /REBOOTOK "$INSTDIR\plugins\*"
625     Delete /REBOOTOK "$PLUGINSDIR\bacula-*.conf"
626     Delete /REBOOTOK "$PLUGINSDIR\*console.conf"
627     Delete /REBOOTOK "$PLUGINSDIR\*conf.in"
628     Delete /REBOOTOK "$PLUGINSDIR\openssl.exe"
629     Delete /REBOOTOK "$PLUGINSDIR\libeay32.dll"
630     Delete /REBOOTOK "$PLUGINSDIR\ssleay32.dll"
631     Delete /REBOOTOK "$PLUGINSDIR\sed.exe"    
632     Delete /REBOOTOK "$PLUGINSDIR\pw.txt"     
633     Delete /REBOOTOK "$PLUGINSDIR\*.sed" 
634     Delete /REBOOTOK "$PLUGINSDIR\*.cmd"    
635     Delete /REBOOTOK "$PLUGINSDIR\*.sql"    
636     RMDir "$INSTDIR\plugins"
637     RMDir "$INSTDIR\working"
638     RMDir "$INSTDIR\bin32"
639     RMDir "$INSTDIR"
640 NoDel:
641
642   ; remove directories used
643   RMDir "$INSTDIR\doc"
644   RMDir "$INSTDIR\help"
645   RMDir "$INSTDIR"
646 SectionEnd
647
648 ;
649 ; $0 - Service Name (ie Bacula-FD)
650 ; $1 - Service Description (ie Bacula File Daemon)
651 ; $2 - Install as Service
652 ; $3 - Start Service now
653 ;
654 Function InstallDaemon
655   Call InstallCommonFiles
656
657   WriteRegDWORD HKLM "Software\Bacula" "Service_$0" $2
658   
659   ${If} $2 = 1
660     nsExec::ExecToLog '"$INSTDIR\$0.exe" /kill'
661     sleep 3000
662     nsExec::ExecToLog '"$INSTDIR\$0.exe" /remove'
663     nsExec::ExecToLog '"$INSTDIR\$0.exe" /install -c "$INSTDIR\$0.conf"'
664
665     ${If} $OsIsNT <> 1
666       File "Start.bat"
667       File "Stop.bat"
668     ${EndIf}
669
670     ; Start the service?
671
672     ${If} $3 = 1  
673       ${If} $OsIsNT = 1
674         nsExec::ExecToLog 'net start $0'
675       ${Else}
676         Exec '"$INSTDIR\$0.exe" /service -c "$INSTDIR\$0.conf"'
677       ${EndIf}
678     ${EndIf}
679   ${Else}
680     CreateShortCut "$SMPROGRAMS\Bacula\Start $1.lnk" "$INSTDIR\$0.exe" '-c "$INSTDIR\$0.conf"' "$INSTDIR\$0.exe" 0
681   ${EndIf}
682 FunctionEnd
683
684 Function GetComputerName
685   Push $R0
686   Push $R1
687   Push $R2
688
689   System::Call "kernel32::GetComputerNameA(t .R0, *i ${NSIS_MAX_STRLEN} R1) i.R2"
690
691   ${StrCase} $R0 $R0 "L"
692
693   Pop $R2
694   Pop $R1
695   Exch $R0
696 FunctionEnd
697
698 !define ComputerNameDnsFullyQualified   3
699
700 Function GetHostName
701   Push $R0
702   Push $R1
703   Push $R2
704
705   ${If} $OsIsNT = 1
706     System::Call "kernel32::GetComputerNameExA(i ${ComputerNameDnsFullyQualified}, t .R0, *i ${NSIS_MAX_STRLEN} R1) i.R2 ?e"
707     ${If} $R2 = 0
708       Pop $R2
709       DetailPrint "GetComputerNameExA failed - LastError = $R2"
710       Call GetComputerName
711       Pop $R0
712     ${Else}
713       Pop $R2
714     ${EndIf}
715   ${Else}
716     Call GetComputerName
717     Pop $R0
718   ${EndIf}
719
720   Pop $R2
721   Pop $R1
722   Exch $R0
723 FunctionEnd
724
725 !define NameUserPrincipal 8
726
727 Function GetUserName
728   Push $R0
729   Push $R1
730   Push $R2
731
732   ${If} $OsIsNT = 1
733     System::Call "secur32::GetUserNameExA(i ${NameUserPrincipal}, t .R0, *i ${NSIS_MAX_STRLEN} R1) i.R2 ?e"
734     ${If} $R2 = 0
735       Pop $R2
736       DetailPrint "GetUserNameExA failed - LastError = $R2"
737       Pop $R0
738       StrCpy $R0 ""
739     ${Else}
740       Pop $R2
741     ${EndIf}
742   ${Else}
743       StrCpy $R0 ""
744   ${EndIf}
745
746   ${If} $R0 == ""
747     System::Call "advapi32::GetUserNameA(t .R0, *i ${NSIS_MAX_STRLEN} R1) i.R2 ?e"
748     ${If} $R2 = 0
749       Pop $R2
750       DetailPrint "GetUserNameA failed - LastError = $R2"
751       StrCpy $R0 ""
752     ${Else}
753       Pop $R2
754     ${EndIf}
755   ${EndIf}
756
757   Pop $R2
758   Pop $R1
759   Exch $R0
760 FunctionEnd
761
762 Function ConfigEditAndCopy
763   Push $R1
764
765   ${If} ${FileExists} "$0\$1"
766     StrCpy $R1 ".new"
767   ${Else}
768     StrCpy $R1 ""
769   ${EndIf}
770
771   nsExec::ExecToLog '$PLUGINSDIR\sed.exe -f "$PLUGINSDIR\config.sed" -i.bak "$PLUGINSDIR\$1"'
772   CopyFiles "$PLUGINSDIR\$1" "$0\$1$R1"
773
774   Pop $R1
775 FunctionEnd
776
777 Function GetSelectedComponents
778   Push $R0
779   StrCpy $R0 0
780   ${If} ${SectionIsSelected} ${SecFileDaemon}
781     IntOp $R0 $R0 | ${ComponentFile}
782   ${EndIf}
783   ${If} ${SectionIsSelected} ${SecConsole}
784     IntOp $R0 $R0 | ${ComponentTextConsole}
785   ${EndIf}
786   ${If} ${SectionIsSelected} ${SecBatConsole}
787     IntOp $R0 $R0 | ${ComponentBatConsole}
788   ${EndIf}
789   Exch $R0
790 FunctionEnd
791
792 Function PageComponentsShow
793
794   Call SelectPreviousComponents
795   Call UpdateComponentUI
796 FunctionEnd
797
798 Function PageDirectoryPre
799   ${If} $AutomaticInstall = 1
800   ${OrIf} $InstallType = ${UpgradeInstall}
801     Abort
802   ${EndIf}
803 FunctionEnd
804
805 Function LeaveInstallPage
806   Push "$INSTDIR\install.log"
807   Call DumpLog
808 FunctionEnd
809
810 Function EnterWriteTemplates
811   Push $R0
812   Push $R1
813
814   Call GetSelectedComponents
815   Pop $R0
816
817   IntOp $R0 $R0 & ${ComponentDirector}
818   IntOp $R1 $NewComponents & ${ComponentsFileAndStorage}
819
820   ${If} $R0 <> 0
821   ${OrIf} $R1 = 0
822     Pop $R1
823     Pop $R0
824     Abort
825   ${EndIf}
826
827   IntOp $R0 $NewComponents & ${ComponentFile}
828   ${If} $R0 = 0
829     WriteINIStr "$PLUGINSDIR\WriteTemplates.ini" "Field 2" State 0
830     WriteINIStr "$PLUGINSDIR\WriteTemplates.ini" "Field 2" Flags DISABLED
831     DeleteINIStr "$PLUGINSDIR\WriteTemplates.ini" "Field 3" State
832     WriteINIStr "$PLUGINSDIR\WriteTemplates.ini" "Field 3" Flags REQ_SAVE|FILE_EXPLORER|WARN_IF_EXIST|DISABLED
833   ${Else}
834     WriteINIStr "$PLUGINSDIR\WriteTemplates.ini" "Field 2" State 1
835     DeleteINIStr "$PLUGINSDIR\WriteTemplates.ini" "Field 2" Flags
836     WriteINIStr "$PLUGINSDIR\WriteTemplates.ini" "Field 3" State "C:\$ConfigClientName.conf"
837   ${EndIf}
838
839
840   !InsertMacro MUI_HEADER_TEXT "$(TITLE_WriteTemplates)" "$(SUBTITLE_WriteTemplates)"
841   !InsertMacro MUI_INSTALLOPTIONS_DISPLAY "WriteTemplates.ini"
842
843   !InsertMacro MUI_INSTALLOPTIONS_READ $R0 "WriteTemplates.ini" "Field 2" State
844   ${If} $R0 <> 0
845     File "/oname=$PLUGINSDIR\client.conf.in" "client.conf.in"
846
847     nsExec::ExecToLog '$PLUGINSDIR\sed.exe -f "$PLUGINSDIR\config.sed" -i.bak "$PLUGINSDIR\client.conf.in"'
848     !InsertMacro MUI_INSTALLOPTIONS_READ $R0 "WriteTemplates.ini" "Field 3" State
849     ${If} $R0 != ""
850       CopyFiles "$PLUGINSDIR\client.conf.in" "$R0"
851     ${EndIf}
852   ${EndIf}
853
854
855   Pop $R1
856   Pop $R0
857 FunctionEnd
858
859 Function SelectPreviousComponents
860   ${If} $InstallType <> ${NewInstall}
861     IntOp $R1 $PreviousComponents & ${ComponentFile}
862     ${If} $R1 <> 0
863       !InsertMacro SelectSection ${SecFileDaemon}
864       !InsertMacro SetSectionFlag ${SecFileDaemon} ${SF_RO}
865     ${Else}
866       !InsertMacro UnselectSection ${SecFileDaemon}
867       !InsertMacro ClearSectionFlag ${SecFileDaemon} ${SF_RO}
868     ${EndIf}
869     IntOp $R1 $PreviousComponents & ${ComponentTextConsole}
870     ${If} $R1 <> 0
871       !InsertMacro SelectSection ${SecConsole}
872       !InsertMacro SetSectionFlag ${SecConsole} ${SF_RO}
873     ${Else}
874       !InsertMacro UnselectSection ${SecConsole}
875       !InsertMacro ClearSectionFlag ${SecConsole} ${SF_RO}
876     ${EndIf}
877     IntOp $R1 $PreviousComponents & ${ComponentBatConsole}
878     ${If} $R1 <> 0
879       !InsertMacro SelectSection ${SecBatConsole}
880       !InsertMacro SetSectionFlag ${SecBatConsole} ${SF_RO}
881     ${Else}
882       !InsertMacro UnselectSection ${SecBatConsole}
883       !InsertMacro ClearSectionFlag ${SecBatConsole} ${SF_RO}
884     ${EndIf}
885   ${EndIf}
886 FunctionEnd
887
888 Function UpdateComponentUI
889   Push $R0
890   Push $R1
891
892   Call GetSelectedComponents
893   Pop $R0
894
895   IntOp $R1 $R0 ^ $PreviousComponents
896   IntOp $NewComponents $R0 & $R1
897
898   ${If} $InstallType <> ${NewInstall}
899     IntOp $R1 $NewComponents & ${ComponentFile}
900     ${If} $R1 <> 0
901       !InsertMacro SetSectionFlag ${SecFileDaemon} ${SF_BOLD}
902     ${Else}
903       !InsertMacro ClearSectionFlag ${SecFileDaemon} ${SF_BOLD}
904     ${EndIf}
905     IntOp $R1 $NewComponents & ${ComponentTextConsole}
906     ${If} $R1 <> 0
907       !InsertMacro SetSectionFlag ${SecConsole} ${SF_BOLD}
908     ${Else}
909       !InsertMacro ClearSectionFlag ${SecConsole} ${SF_BOLD}
910     ${EndIf}
911     IntOp $R1 $NewComponents & ${ComponentBatConsole}
912     ${If} $R1 <> 0
913       !InsertMacro SetSectionFlag ${SecBatConsole} ${SF_BOLD}
914     ${Else}
915       !InsertMacro ClearSectionFlag ${SecBatConsole} ${SF_BOLD}
916     ${EndIf}
917   ${EndIf}
918
919   GetDlgItem $R0 $HWNDPARENT 1
920
921   IntOp $R1 $NewComponents & ${ComponentsRequiringUserConfig}
922   ${If} $R1 = 0
923     SendMessage $R0 ${WM_SETTEXT} 0 "STR:Install"
924   ${Else}
925     SendMessage $R0 ${WM_SETTEXT} 0 "STR:&Next >"
926   ${EndIf}
927
928   Pop $R1
929   Pop $R0
930 FunctionEnd
931
932 !include "InstallType.nsh"
933 !include "ConfigPage1.nsh"
934 !include "ConfigPage2.nsh"
935 !include "DumpLog.nsh"