/
winbareos.nsi
878 lines (699 loc) · 27.7 KB
/
winbareos.nsi
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
;
; BAREOS?? - Backup Archiving REcovery Open Sourced
;
; Copyright (C) 2012-2013 Bareos GmbH & Co. KG
;
; This program is Free Software; you can redistribute it and/or
; modify it under the terms of version three of the GNU Affero General Public
; License as published by the Free Software Foundation and included
; in the file LICENSE.
;
; This program is distributed in the hope that it will be useful, but
; WITHOUT ANY WARRANTY; without even the implied warranty of
; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
; Affero General Public License for more details.
;
; You should have received a copy of the GNU Affero General Public License
; along with this program; if not, write to the Free Software
; Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
; 02110-1301, USA.
RequestExecutionLevel admin
!addplugindir ../nsisplugins
; HM NIS Edit Wizard helper defines
!define PRODUCT_NAME "Bareos"
#!define PRODUCT_VERSION "1.0"
!define PRODUCT_PUBLISHER "Bareos GmbH & Co.KG"
!define PRODUCT_WEB_SITE "http://www.bareos.com"
!define PRODUCT_DIR_REGKEY "Software\Microsoft\Windows\CurrentVersion\App Paths\bareos-fd.exe"
!define PRODUCT_UNINST_KEY "Software\Microsoft\Windows\CurrentVersion\Uninstall\${PRODUCT_NAME}"
!define PRODUCT_UNINST_ROOT_KEY "HKLM"
SetCompressor lzma
# variable definitions
Var LocalHostAddress
Var HostName
# Config Parameters Dialog
# Needed for Configuring client config file
Var ClientName #XXX_REPLACE_WITH_HOSTNAME_XXX
Var ClientPassword #XXX_REPLACE_WITH_FD_PASSWORD_XXX
Var ClientMonitorPassword #XXX_REPLACE_WITH_FD_MONITOR_PASSWORD_XXX
Var ClientAddress #XXX_REPLACE_WITH_FD_MONITOR_PASSWORD_XXX
# Needed for bconsole and bat:
Var DirectorAddress #XXX_REPLACE_WITH_HOSTNAME_XXX
Var DirectorPassword #XXX_REPLACE_WITH_DIRECTOR_PASSWORD_XXX
Var DirectorName
# Needed for tray monitor:
# can stay like it is if we dont monitor any director -> Default
Var DirectorMonitorPassword #XXX_REPLACE_WITH_DIRECTOR_MONITOR_PASSWORD_XXX
# this is the one we need to make sure it is the same like configured in the fd
#Var ClientMonitorPassword #XXX_REPLACE_WITH_FD_MONITOR_PASSWORD_XXX
# generated configuration snippet for bareos director config (client ressource)
Var ConfigSnippet
Var dialog
Var hwnd
!include "LogicLib.nsh"
!include "FileFunc.nsh"
!include "Sections.nsh"
!include "StrFunc.nsh"
!include "WinMessages.nsh"
!include "nsDialogs.nsh"
!include "x64.nsh"
!include "WinVer.nsh"
# call functions once to have them included
${StrCase}
${StrTrimNewLines}
; MUI 1.67 compatible ------
!include "MUI.nsh"
; MUI Settings
!define MUI_ABORTWARNING
!define MUI_ICON "${NSISDIR}\Contrib\Graphics\Icons\modern-install.ico"
!define MUI_UNICON "${NSISDIR}\Contrib\Graphics\Icons\modern-uninstall.ico"
!insertmacro GetParameters
!insertmacro GetOptions
; Welcome page
!insertmacro MUI_PAGE_WELCOME
; License
!insertmacro MUI_PAGE_LICENSE "LICENSE"
; Directory page
!insertmacro MUI_PAGE_DIRECTORY
; Components page
!insertmacro MUI_PAGE_COMPONENTS
; Custom für Abfragen benötigter Parameter für den Client
Page custom getClientParameters
; Custom für Abfragen benötigter Parameter für den Zugriff auf director
Page custom getDirectorParameters
; Instfiles page
!insertmacro MUI_PAGE_INSTFILES
; Finish page
; Custom page shows director config snippet
Page custom displayDirconfSnippet
#!define MUI_FINISHPAGE_RUN "$INSTDIR\bareos-fd.exe"
!insertmacro MUI_PAGE_FINISH
; Uninstaller pages
!insertmacro MUI_UNPAGE_INSTFILES
; Language files
!insertmacro MUI_LANGUAGE "English"
; Reserve files
!insertmacro MUI_RESERVEFILE_INSTALLOPTIONS
; MUI end ------
#
# move existing conf files to .old
# and install new ones in original place
# also, install a shortcut to edit
# the conf file
#
!macro InstallConfFile fname
# This is important to have $APPDATA variable
# point to ProgramData folder
# instead of current user's Roaming folder
SetShellVarContext all
${If} ${FileExists} "$APPDATA\${PRODUCT_NAME}\${fname}"
MessageBox MB_YESNO|MB_ICONQUESTION \
"Existing config file found: $APPDATA\${PRODUCT_NAME}\${fname}$\r$\nKeep existing config file?" \
/SD IDNO IDYES keep IDNO move
move:
Rename "$APPDATA\${PRODUCT_NAME}\${fname}" "$APPDATA\${PRODUCT_NAME}\${fname}.old"
Rename "$PLUGINSDIR\${fname}" "$APPDATA\${PRODUCT_NAME}\${fname}"
MessageBox MB_OK|MB_ICONINFORMATION \
"Existing config file saved as $APPDATA\${PRODUCT_NAME}\${fname}.old" \
/SD IDOK
GOTO +3
keep:
Rename "$PLUGINSDIR\${fname}" "$APPDATA\${PRODUCT_NAME}\${fname}.new"
MessageBox MB_OK|MB_ICONINFORMATION \
"New config file stored $APPDATA\${PRODUCT_NAME}\${fname}.new" \
/SD IDOK
${Else}
Rename "$PLUGINSDIR\${fname}" "$APPDATA\${PRODUCT_NAME}\${fname}"
${EndIf}
CreateShortCut "$SMPROGRAMS\${PRODUCT_NAME}\Edit ${fname}.lnk" "write.exe" '"$APPDATA\${PRODUCT_NAME}\${fname}"'
!macroend
Name "${PRODUCT_NAME} ${PRODUCT_VERSION}"
OutFile "${PRODUCT_NAME}-${PRODUCT_VERSION}.exe"
InstallDir "$PROGRAMFILES\${PRODUCT_NAME}"
InstallDirRegKey HKLM "${PRODUCT_DIR_REGKEY}" ""
ShowInstDetails show
ShowUnInstDetails show
InstType "Standard"
InstType "Full"
InstType "Minimal"
Section -StopDaemon
# nsExec::ExecToLog "net stop bareos-fd"
# looks like this does not work on win7 sp1
# if the service doesnt exist, it fails and the installation
# cannot start
# so we use the shotgun:
KillProcWMI::KillProc "bareos-fd.exe"
KillProcWMI::KillProc "bareos-tray-monitor.exe"
SectionEnd
Section -SetPasswords
SetShellVarContext all
# Write sed file to replace the preconfigured variables by the configured values
#
# File Daemon and Tray Monitor configs
#
FileOpen $R1 $PLUGINSDIR\config.sed w
#FileOpen $R1 config.sed w
FileWrite $R1 "s#@VERSION@#${PRODUCT_VERSION}#g$\r$\n"
FileWrite $R1 "s#@DATE@#${__DATE__}#g$\r$\n"
FileWrite $R1 "s#@DISTNAME@#Windows#g$\r$\n"
FileWrite $R1 "s#XXX_REPLACE_WITH_DIRECTOR_PASSWORD_XXX#$DirectorPassword#g$\r$\n"
FileWrite $R1 "s#XXX_REPLACE_WITH_CLIENT_PASSWORD_XXX#$ClientPassword#g$\r$\n"
FileWrite $R1 "s#XXX_REPLACE_WITH_CLIENT_MONITOR_PASSWORD_XXX#$ClientMonitorPassword#g$\r$\n"
FileWrite $R1 "s#XXX_REPLACE_WITH_HOSTNAME_XXX#$HostName#g$\r$\n"
FileWrite $R1 "s#XXX_REPLACE_WITH_BASENAME_XXX-fd#$ClientName#g$\r$\n"
FileWrite $R1 "s#XXX_REPLACE_WITH_BASENAME_XXX-dir#$DirectorName#g$\r$\n"
FileWrite $R1 "s#XXX_REPLACE_WITH_BASENAME_XXX-mon#$HostName-mon#g$\r$\n"
FileClose $R1
nsExec::ExecToLog '$PLUGINSDIR\sed.exe -f "$PLUGINSDIR\config.sed" -i-template "$PLUGINSDIR\bareos-fd.conf"'
nsExec::ExecToLog '$PLUGINSDIR\sed.exe -f "$PLUGINSDIR\config.sed" -i-template "$PLUGINSDIR\tray-monitor.conf"'
#Delete config.sed
#
# config files for bconsole and bat to access remote director
#
FileOpen $R1 $PLUGINSDIR\bconsole.sed w
FileWrite $R1 "s#XXX_REPLACE_WITH_BASENAME_XXX-dir#$DirectorName#g$\r$\n"
FileWrite $R1 "s#XXX_REPLACE_WITH_HOSTNAME_XXX#$DirectorAddress#g$\r$\n"
FileWrite $R1 "s#XXX_REPLACE_WITH_DIRECTOR_PASSWORD_XXX#$DirectorPassword#g$\r$\n"
FileClose $R1
nsExec::ExecToLog '$PLUGINSDIR\sed.exe -f "$PLUGINSDIR\bconsole.sed" -i-template "$PLUGINSDIR\bconsole.conf"'
nsExec::ExecToLog '$PLUGINSDIR\sed.exe -f "$PLUGINSDIR\bconsole.sed" -i-template "$PLUGINSDIR\bat.conf"'
#Delete bconsole.sed
#
# write client config snippet for director
#
#
# FileOpen $R1 import_this_file_into_your_director_config.txt w
#
# FileWrite $R1 'Client {$\n'
# FileWrite $R1 ' Name = $ClientName$\n'
# FileWrite $R1 ' Address = $ClientAddress$\n'
# FileWrite $R1 ' Password = "$ClientPassword"$\n'
# FileWrite $R1 ' Catalog = "MyCatalog"$\n'
# FileWrite $R1 '}$\n'
#
# FileClose $R1
#
SectionEnd
Section "Bareos Client (FileDaemon) and base libs" SEC_CLIENT
SectionIn 1 2 3
SetShellVarContext all
# TODO: only do this if the file exists
# nsExec::ExecToLog '"$INSTDIR\bareos-fd.exe" /kill'
# sleep 3000
# nsExec::ExecToLog '"$INSTDIR\bareos-fd.exe" /remove'
SetOutPath "$INSTDIR"
SetOverwrite ifnewer
CreateDirectory "$SMPROGRAMS\${PRODUCT_NAME}"
CreateDirectory "$APPDATA\${PRODUCT_NAME}"
File "bareos-fd.exe"
File "bpipe-fd.dll"
File "libbareos.dll"
File "libbareosfind.dll"
File "libcrypto-8.dll"
File "libgcc_s_sjlj-1.dll"
File "libssl-8.dll"
File "libstdc++-6.dll"
File "pthreadGCE2.dll"
File "zlib1.dll"
File "liblzo2-2.dll"
# for password generation
File "openssl.exe"
File "sed.exe"
# File "bareos-fd.conf"
!insertmacro InstallConfFile bareos-fd.conf
SectionEnd
Section /o "Text Console (bconsole)" SEC_BCONSOLE
SectionIn 2
SetShellVarContext all
CreateShortCut "$SMPROGRAMS\${PRODUCT_NAME}\bconsole.lnk" "$INSTDIR\bconsole.exe" '-c "$APPDATA\${PRODUCT_NAME}\bconsole.conf"'
File "bconsole.exe"
# File "libbareos.dll"
# File "libcrypto-8.dll"
# File "libgcc_s_sjlj-1.dll"
File "libhistory6.dll"
File "libreadline6.dll"
# File "libssl-8.dll"
# File "libstdc++-6.dll"
File "libtermcap-0.dll"
# File "pthreadGCE2.dll"
# File "zlib1.dll"
#
!insertmacro InstallConfFile "bconsole.conf"
# File "bconsole.conf
SectionEnd
#Section /o "Tray-Monitor" SEC_TRAYMON
#SectionIn 1 2
#
#
# SetShellVarContext all
# CreateShortCut "$SMPROGRAMS\${PRODUCT_NAME}\bareos-tray-monitor.lnk" "$INSTDIR\bareos-tray-monitor.exe" '-c "$APPDATA\${PRODUCT_NAME}\tray-monitor.conf"'
#
# File "bareos-tray-monitor.exe"
## File "libbareos.dll"
## File "libcrypto-8.dll"
## File "libgcc_s_sjlj-1.dll"
# File "libpng15-15.dll"
## File "libssl-8.dll"
## File "libstdc++-6.dll"
## File "pthreadGCE2.dll"
# File "QtCore4.dll"
# File "QtGui4.dll"
## File "zlib1.dll"
#
#
# !insertmacro InstallConfFile "tray-monitor.conf"
## File "tray-monitor.conf"
#
#SectionEnd
Section /o "Qt Console (BAT)" SEC_BAT
SectionIn 2
SetShellVarContext all
CreateShortCut "$SMPROGRAMS\${PRODUCT_NAME}\BAT.lnk" "$INSTDIR\bat.exe" '-c "$APPDATA\${PRODUCT_NAME}\bat.conf"'
CreateShortCut "$DESKTOP\BAT.lnk" "$INSTDIR\bat.exe" '-c "$APPDATA\${PRODUCT_NAME}\bat.conf"'
File "bat.exe"
# File "libbareos.dll"
# File "libcrypto-8.dll"
# File "libgcc_s_sjlj-1.dll"
File "libpng15-15.dll"
# File "libssl-8.dll"
# File "libstdc++-6.dll"
# File "pthreadGCE2.dll"
File "QtCore4.dll"
File "QtGui4.dll"
# File "zlib1.dll"
!insertmacro InstallConfFile "bat.conf"
# File "bat.conf"
SectionEnd
Section "Open Firewall for Client" SEC_FIREWALL
SectionIn 1 2 3
SetShellVarContext current
${If} ${AtLeastWin7}
#
# See http://technet.microsoft.com/de-de/library/dd734783%28v=ws.10%29.aspx
#
DetailPrint "Opening Firewall, OS is Win7+"
DetailPrint "netsh advfirewall firewall add rule name=$\"Bareos backup client (bareos-fd) access$\" dir=in action=allow program=$\"$PROGRAMFILES64\${PRODUCT_NAME}\bareos-fd.exe$\" enable=yes protocol=TCP localport=9102 description=$\"Bareos backup client rule$\""
# profile=[private,domain]"
nsExec::Exec "netsh advfirewall firewall add rule name=$\"Bareos backup client (bareos-fd) access$\" dir=in action=allow program=$\"$PROGRAMFILES64\${PRODUCT_NAME}\bareos-fd.exe$\" enable=yes protocol=TCP localport=9102 description=$\"Bareos backup client rule$\""
# profile=[private,domain]"
${Else}
DetailPrint "Opening Firewall, OS is < Win7"
DetailPrint "netsh firewall add portopening protocol=TCP port=9102 name=$\"Bareos backup client (bareos-fd) access$\""
nsExec::Exec "netsh firewall add portopening protocol=TCP port=9102 name=$\"Bareos backup client (bareos-fd) access$\""
${EndIf}
SectionEnd
; Section descriptions
!insertmacro MUI_FUNCTION_DESCRIPTION_BEGIN
!insertmacro MUI_DESCRIPTION_TEXT ${SEC_CLIENT} "Installs the Bareos File Daemon and required Files"
!insertmacro MUI_DESCRIPTION_TEXT ${SEC_BCONSOLE} "Installs the CLI client console (bconsole)"
# !insertmacro MUI_DESCRIPTION_TEXT ${SEC_TRAYMON} "Installs the tray Icon to monitor the Bareos client"
!insertmacro MUI_DESCRIPTION_TEXT ${SEC_BAT} "Installs the Qt Console (BAT)"
!insertmacro MUI_DESCRIPTION_TEXT ${SEC_FIREWALL} "Opens Port 9102/TCP for bareos-fd.exe (Client program) in the Windows Firewall"
!insertmacro MUI_FUNCTION_DESCRIPTION_END
Section -AdditionalIcons
SetShellVarContext all
WriteIniStr "$INSTDIR\${PRODUCT_NAME}.url" "InternetShortcut" "URL" "${PRODUCT_WEB_SITE}"
CreateShortCut "$SMPROGRAMS\${PRODUCT_NAME}\Website.lnk" "$INSTDIR\${PRODUCT_NAME}.url"
CreateShortCut "$SMPROGRAMS\${PRODUCT_NAME}\Uninstall.lnk" "$INSTDIR\uninst.exe"
SectionEnd
Section -Post
SetShellVarContext all
WriteUninstaller "$INSTDIR\uninst.exe"
WriteRegStr HKLM "${PRODUCT_DIR_REGKEY}" "" "$INSTDIR\bareos-fd.exe"
WriteRegStr ${PRODUCT_UNINST_ROOT_KEY} "${PRODUCT_UNINST_KEY}" "DisplayName" "$(^Name)"
WriteRegStr ${PRODUCT_UNINST_ROOT_KEY} "${PRODUCT_UNINST_KEY}" "UninstallString" "$INSTDIR\uninst.exe"
WriteRegStr ${PRODUCT_UNINST_ROOT_KEY} "${PRODUCT_UNINST_KEY}" "DisplayIcon" "$INSTDIR\bareos-fd.exe"
WriteRegStr ${PRODUCT_UNINST_ROOT_KEY} "${PRODUCT_UNINST_KEY}" "DisplayVersion" "${PRODUCT_VERSION}"
WriteRegStr ${PRODUCT_UNINST_ROOT_KEY} "${PRODUCT_UNINST_KEY}" "URLInfoAbout" "${PRODUCT_WEB_SITE}"
WriteRegStr ${PRODUCT_UNINST_ROOT_KEY} "${PRODUCT_UNINST_KEY}" "Publisher" "${PRODUCT_PUBLISHER}"
# install service
nsExec::ExecToLog '"$INSTDIR\bareos-fd.exe" /kill'
sleep 3000
nsExec::ExecToLog '"$INSTDIR\bareos-fd.exe" /remove'
nsExec::ExecToLog '"$INSTDIR\bareos-fd.exe" /install -c "$APPDATA\${PRODUCT_NAME}\bareos-fd.conf"'
SectionEnd
Section -StartDaemon
nsExec::ExecToLog "net start bareos-fd"
SectionEnd
# helper functions to find out computer name
Function GetComputerName
Push $R0
Push $R1
Push $R2
System::Call "kernel32::GetComputerNameA(t .R0, *i ${NSIS_MAX_STRLEN} R1) i.R2"
${StrCase} $R0 $R0 "L"
Pop $R2
Pop $R1
Exch $R0
FunctionEnd
!define ComputerNameDnsFullyQualified 3
Function GetHostName
Push $R0
Push $R1
Push $R2
${If} $OsIsNT = 1
System::Call "kernel32::GetComputerNameExA(i ${ComputerNameDnsFullyQualified}, t .R0, *i ${NSIS_MAX_STRLEN} R1) i.R2 ?e"
${If} $R2 = 0
Pop $R2
DetailPrint "GetComputerNameExA failed - LastError = $R2"
Call GetComputerName
Pop $R0
${Else}
Pop $R2
${EndIf}
${Else}
Call GetComputerName
Pop $R0
${EndIf}
Pop $R2
Pop $R1
Exch $R0
FunctionEnd
Function .onInit
# check if we are installing on 64Bit, then do some settings
${If} ${RunningX64} # 64Bit OS
${If} ${BIT_WIDTH} == '32'
MessageBox MB_OK|MB_ICONSTOP "You are running a 32 Bit installer on a 64 Bit OS.$\r$\nPlease use the 64 Bit installer."
Abort
${EndIf}
StrCpy $INSTDIR "$PROGRAMFILES64\${PRODUCT_NAME}"
SetRegView 64
${EnableX64FSRedirection}
${Else} # 32Bit OS
${If} ${BIT_WIDTH} == '64'
MessageBox MB_OK|MB_ICONSTOP "You are running a 64 Bit installer on a 32 Bit OS.$\r$\nPlease use the 32 Bit installer."
Abort
${EndIf}
${EndIf}
# check if software is already installed
ClearErrors
ReadRegStr $2 ${PRODUCT_UNINST_ROOT_KEY} "${PRODUCT_UNINST_KEY}" "DisplayName"
ReadRegStr $0 ${PRODUCT_UNINST_ROOT_KEY} "${PRODUCT_UNINST_KEY}" "DisplayVersion"
StrCmp $2 "" +3
MessageBox MB_OK|MB_ICONSTOP "${PRODUCT_NAME} version $0 $\r$\nseems to be already installed on your system.$\r$\nPlease uninstall first."
Abort
# Parameters:
# Needed for Client and Tray-Mon:
#
# Client Name
#
# Director Name
# Client Password
# Client Network Address
#
# Client Monitor Password
#
# Needed for Bconsole/Bat:
#
# Director Network Address
# Director Password
#
var /GLOBAL cmdLineParams
# Installer Options
${GetParameters} $cmdLineParams
ClearErrors
# /? param (help)
ClearErrors
${GetOptions} $cmdLineParams '/?' $R0
IfErrors +3 0
MessageBox MB_OK|MB_ICONINFORMATION "[/CLIENTNAME=Name of the client ressource] $\r$\n\
[/CLIENTPASSWORD=Password to access the client] $\r$\n\
[/DIRECTORNAME=Name of Director to access the client and of the Director accessed by bconsole/BAT] $\r$\n\
[/CLIENTADDRESS=Network Address of the client] $\r$\n\
[/CLIENTMONITORPASSWORD=Password for monitor access] $\r$\n\
$\r$\n\
[/DIRECTORADDRESS=Network Address of the Director (for bconsole or BAT)] $\r$\n\
[/DIRECTORPASSWORD=Password to access Director]$\r$\n\
$\r$\n\
[/S (silent install without user interaction)]$\r$\n\
[/D=C:\specify\installation\directory (! HAS TO BE THE LAST OPTION !)$\r$\n\
[/? (this help dialog)"
# [/DIRECTORNAME=Name of the Director to be accessed from bconsole/BAT]"
Abort
${GetOptions} $cmdLineParams "/CLIENTNAME=" $ClientName
ClearErrors
${GetOptions} $cmdLineParams "/CLIENTPASSWORD=" $ClientPassword
ClearErrors
# ${GetOptions} $cmdLineParams "/CLIENTDIRECTORNAME=" $DirectorName
# ClearErrors
${GetOptions} $cmdLineParams "/CLIENTADDRESS=" $ClientAddress
ClearErrors
${GetOptions} $cmdLineParams "/CLIENTMONITORPASSWORD=" $ClientMonitorPassword
ClearErrors
${GetOptions} $cmdLineParams "/DIRECTORADDRESS=" $DirectorAddress
ClearErrors
${GetOptions} $cmdLineParams "/DIRECTORPASSWORD=" $DirectorPassword
ClearErrors
${GetOptions} $cmdLineParams "/DIRECTORNAME=" $DirectorName
ClearErrors
InitPluginsDir
File "/oname=$PLUGINSDIR\clientdialog.ini" "clientdialog.ini"
File "/oname=$PLUGINSDIR\directordialog.ini" "directordialog.ini"
File "/oname=$PLUGINSDIR\openssl.exe" "openssl.exe"
File "/oname=$PLUGINSDIR\sed.exe" "sed.exe"
File "/oname=$PLUGINSDIR\libcrypto-8.dll" "libcrypto-8.dll"
File "/oname=$PLUGINSDIR\libgcc_s_sjlj-1.dll" "libgcc_s_sjlj-1.dll"
# File /nonfatal "/oname=$PLUGINSDIR\libgcc_s_seh-1.dll" "libgcc_s_seh-1.dll"
File "/oname=$PLUGINSDIR\libssl-8.dll" "libssl-8.dll"
File "/oname=$PLUGINSDIR\libstdc++-6.dll" "libstdc++-6.dll"
File "/oname=$PLUGINSDIR\zlib1.dll" "zlib1.dll"
File "/oname=$PLUGINSDIR\bareos-fd.conf" "bareos-fd.conf"
File "/oname=$PLUGINSDIR\bconsole.conf" "bconsole.conf"
File "/oname=$PLUGINSDIR\bat.conf" "bat.conf"
File "/oname=$PLUGINSDIR\tray-monitor.conf" "tray-monitor.conf"
# make first section mandatory
SectionSetFlags ${SEC_CLIENT} 17 # SF_SELECTED & SF_RO
# SectionSetFlags ${SEC_BCONSOLE} ${SF_SELECTED} # SF_SELECTED
#SectionSetFlags ${SEC_TRAYMON} ${SF_SELECTED} # SF_SELECTED
# find out the computer name
Call GetComputerName
Pop $HostName
Call GetHostName
Pop $LocalHostAddress
# MessageBox MB_OK "Hostname: $HostName"
# MessageBox MB_OK "LocalHostAddress: $LocalHostAddress"
SetPluginUnload alwaysoff
# check if password is set by cmdline. If so, skip creation
strcmp $ClientPassword "" genclientpassword skipclientpassword
genclientpassword:
nsExec::Exec '"$PLUGINSDIR\openssl.exe" rand -base64 -out $PLUGINSDIR\pw.txt 33'
pop $R0
${If} $R0 = 0
FileOpen $R1 "$PLUGINSDIR\pw.txt" r
IfErrors +4
FileRead $R1 $R0
${StrTrimNewLines} $ClientPassword $R0
FileClose $R1
${EndIf}
skipclientpassword:
strcmp $ClientMonitorPassword "" genclientmonpassword skipclientmonpassword
genclientmonpassword:
nsExec::Exec '"$PLUGINSDIR\openssl.exe" rand -base64 -out $PLUGINSDIR\pw.txt 33'
pop $R0
${If} $R0 = 0
FileOpen $R1 "$PLUGINSDIR\pw.txt" r
IfErrors +4
FileRead $R1 $R0
${StrTrimNewLines} $ClientMonitorPassword $R0
FileClose $R1
${EndIf}
skipclientmonpassword:
# MessageBox MB_OK "RandomPassword: $ClientPassword"
# MessageBox MB_OK "RandomPassword: $ClientMonitorPassword"
# if the variables are not empty (because of cmdline params),
# dont set them with our own logic but leave them as they are
strcmp $ClientName "" +1 +2
StrCpy $ClientName "$HostName-fd"
strcmp $ClientAddress "" +1 +2
StrCpy $ClientAddress "$HostName"
strcmp $DirectorName "" +1 +2
StrCpy $DirectorName "bareos-dir"
strcmp $DirectorAddress "" +1 +2
StrCpy $DirectorAddress "bareos-dir.example.com"
strcmp $DirectorPassword "" +1 +2
StrCpy $DirectorPassword "DIRECTORPASSWORD"
FunctionEnd
#
# Client Configuration Dialog
#
Function getClientParameters
Push $R0
# prefill the dialog fields with our passwords and other
# information
WriteINIStr "$PLUGINSDIR\clientdialog.ini" "Field 2" "state" $ClientName
WriteINIStr "$PLUGINSDIR\clientdialog.ini" "Field 3" "state" $DirectorName
WriteINIStr "$PLUGINSDIR\clientdialog.ini" "Field 4" "state" $ClientPassword
WriteINIStr "$PLUGINSDIR\clientdialog.ini" "Field 14" "state" $ClientMonitorPassword
WriteINIStr "$PLUGINSDIR\clientdialog.ini" "Field 5" "state" $ClientAddress
# WriteINIStr "$PLUGINSDIR\clientdialog.ini" "Field 7" "state" "Director console password"
${If} ${SectionIsSelected} ${SEC_CLIENT}
InstallOptions::dialog $PLUGINSDIR\clientdialog.ini
Pop $R0
ReadINIStr $ClientName "$PLUGINSDIR\clientdialog.ini" "Field 2" "state"
ReadINIStr $DirectorName "$PLUGINSDIR\clientdialog.ini" "Field 3" "state"
ReadINIStr $ClientPassword "$PLUGINSDIR\clientdialog.ini" "Field 4" "state"
ReadINIStr $ClientMonitorPassword "$PLUGINSDIR\clientdialog.ini" "Field 14" "state"
ReadINIStr $ClientAddress "$PLUGINSDIR\clientdialog.ini" "Field 5" "state"
${EndIf}
# MessageBox MB_OK "$ClientName$\r$\n$ClientPassword$\r$\n$ClientMonitorPassword "
Pop $R0
FunctionEnd
#
# Director Configuration Dialog (for bconsole and bat configuration)
#
Function getDirectorParameters
Push $R0
# prefill the dialog fields
WriteINIStr "$PLUGINSDIR\directordialog.ini" "Field 2" "state" $DirectorAddress
WriteINIStr "$PLUGINSDIR\directordialog.ini" "Field 3" "state" $DirectorPassword
#TODO: also do this if BAT is selected alone
${If} ${SectionIsSelected} ${SEC_BCONSOLE}
InstallOptions::dialog $PLUGINSDIR\directordialog.ini
Pop $R0
ReadINIStr $DirectorAddress "$PLUGINSDIR\directordialog.ini" "Field 2" "state"
ReadINIStr $DirectorPassword "$PLUGINSDIR\directordialog.ini" "Field 3" "state"
# MessageBox MB_OK "$DirectorAddress$\r$\n$DirectorPassword"
${EndIf}
Pop $R0
FunctionEnd
#
# Display auto-created snippet to be added to director config
#
Function displayDirconfSnippet
#
# write client config snippet for director
#
# Multiline text edits cannot be created before but have to be created at runtime.
# see http://nsis.sourceforge.net/NsDialogs_FAQ#How_to_create_a_multi-line_edit_.28text.29_control
StrCpy $ConfigSnippet "Client {$\r$\n \
Name = $ClientName$\r$\n \
Address = $ClientAddress$\r$\n \
Password = $\"$ClientPassword$\"$\r$\n \
# uncomment the following if using bacula $\r$\n \
# Catalog = $\"MyCatalog$\"$\r$\n \
}$\r$\n"
nsDialogs::Create 1018
Pop $dialog
${NSD_CreateGroupBox} 0 0 100% 100% "Add this Client Ressource to your Bareos Director Configuration"
Pop $hwnd
nsDialogs::CreateControl EDIT \
"${__NSD_Text_STYLE}|${WS_VSCROLL}|${ES_MULTILINE}|${ES_WANTRETURN}" \
"${__NSD_Text_EXSTYLE}" \
10 15 95% 90% \
$ConfigSnippet
Pop $hwnd
nsDialogs::Show
FunctionEnd
Function un.onUninstSuccess
HideWindow
MessageBox MB_ICONINFORMATION|MB_OK "$(^Name) was successfully uninstalled." /SD IDYES
FunctionEnd
Function un.onInit
MessageBox MB_ICONQUESTION|MB_YESNO|MB_DEFBUTTON2 "Do you want to uninstall $(^Name) and all its components?" /SD IDYES IDYES +2
Abort
FunctionEnd
Section Uninstall
# on 64Bit Systems, change the INSTDIR and Registry view to remove the right entries
${If} ${RunningX64} # 64Bit OS
StrCpy $INSTDIR "$PROGRAMFILES64\${PRODUCT_NAME}"
SetRegView 64
${EnableX64FSRedirection}
${EndIf}
SetShellVarContext all
# uninstall service
nsExec::ExecToLog '"$INSTDIR\bareos-fd.exe" /kill'
sleep 3000
nsExec::ExecToLog '"$INSTDIR\bareos-fd.exe" /remove'
# ask if existing config files should be kept
IfSilent +2
MessageBox MB_YESNO|MB_ICONQUESTION \
"Do you want to keep the existing configuration files?" /SD IDYES IDYES ConfDeleteSkip
Delete "$APPDATA\${PRODUCT_NAME}\bareos-fd.conf"
Delete "$APPDATA\${PRODUCT_NAME}\tray-monitor.conf"
Delete "$APPDATA\${PRODUCT_NAME}\bconsole.conf"
Delete "$APPDATA\${PRODUCT_NAME}\bat.conf"
ConfDeleteSkip:
Delete "$APPDATA\${PRODUCT_NAME}\bareos-fd.conf.old"
Delete "$APPDATA\${PRODUCT_NAME}\tray-monitor.conf.old"
Delete "$APPDATA\${PRODUCT_NAME}\bconsole.conf.old"
Delete "$APPDATA\${PRODUCT_NAME}\bat.conf.old"
RMDir "$APPDATA\${PRODUCT_NAME}"
Delete "$INSTDIR\${PRODUCT_NAME}.url"
Delete "$INSTDIR\uninst.exe"
Delete "$INSTDIR\bareos-tray-monitor.exe"
Delete "$INSTDIR\bat.exe"
Delete "$INSTDIR\bareos-fd.exe"
Delete "$INSTDIR\bconsole.exe"
Delete "$INSTDIR\bpipe-fd.dll"
Delete "$INSTDIR\libbareos.dll"
Delete "$INSTDIR\libbareosfind.dll"
Delete "$INSTDIR\libcrypto-8.dll"
Delete "$INSTDIR\libgcc_s_sjlj-1.dll"
Delete "$INSTDIR\libhistory6.dll"
Delete "$INSTDIR\libreadline6.dll"
Delete "$INSTDIR\libssl-8.dll"
Delete "$INSTDIR\libstdc++-6.dll"
Delete "$INSTDIR\libtermcap-0.dll"
Delete "$INSTDIR\pthreadGCE2.dll"
Delete "$INSTDIR\zlib1.dll"
Delete "$INSTDIR\QtCore4.dll"
Delete "$INSTDIR\QtGui4.dll"
Delete "$INSTDIR\liblzo2-2.dll"
Delete "$INSTDIR\libpng15-15.dll"
Delete "$INSTDIR\openssl.exe"
Delete "$INSTDIR\sed.exe"
Delete "$INSTDIR\*template"
Delete "$SMPROGRAMS\${PRODUCT_NAME}\Uninstall.lnk"
Delete "$SMPROGRAMS\${PRODUCT_NAME}\Website.lnk"
Delete "$DESKTOP\${PRODUCT_NAME}.lnk"
Delete "$SMPROGRAMS\${PRODUCT_NAME}\${PRODUCT_NAME}.lnk"
# shortcuts
Delete "$SMPROGRAMS\${PRODUCT_NAME}\Edit*.lnk"
Delete "$SMPROGRAMS\${PRODUCT_NAME}\bconsole.lnk"
Delete "$SMPROGRAMS\${PRODUCT_NAME}\BAT.lnk"
Delete "$DESKTOP\BAT.lnk"
Delete "$SMPROGRAMS\${PRODUCT_NAME}\Website.lnk"
Delete "$SMPROGRAMS\${PRODUCT_NAME}\Uninstall.lnk"
RMDir "$SMPROGRAMS\${PRODUCT_NAME}"
RMDir "$INSTDIR"
DeleteRegKey ${PRODUCT_UNINST_ROOT_KEY} "${PRODUCT_UNINST_KEY}"
DeleteRegKey HKLM "${PRODUCT_DIR_REGKEY}"
SetAutoClose true
# close Firewall
${If} ${AtLeastWin7}
DetailPrint "Closing Firewall, OS is Win7+"
DetailPrint "netsh advfirewall firewall delete rule name=$\"Bareos backup client (bareos-fd) access$\""
nsExec::Exec "netsh advfirewall firewall delete rule name=$\"Bareos backup client (bareos-fd) access$\""
${Else}
DetailPrint "Closing Firewall, OS is < Win7"
DetailPrint "netsh firewall delete portopening protocol=TCP port=9102 name=$\"Bareos backup client (bareos-fd) access$\""
nsExec::Exec "netsh firewall delete portopening protocol=TCP port=9102 name=$\"Bareos backup client (bareos-fd) access$\""
${EndIf}
SectionEnd
Function .onSelChange
Push $R0
Push $R1
# Check if BAT was just selected then select SEC_BCONSOLE
SectionGetFlags ${SEC_BAT} $R0
IntOp $R0 $R0 & ${SF_SELECTED}
StrCmp $R0 ${SF_SELECTED} 0 +2
SectionSetFlags ${SEC_BCONSOLE} $R0
Pop $R1
Pop $R0
FunctionEnd
# TODO:
# - access on conf files has to be limited to administrators
# - tray-monitor automatic start at login
# - tray-monitor does not work right now (why?)
# - create snippet for restricted console that is only allowed to access
# this client
#
# DONE:
# - silent installer with configurable parameters that are otherwise in the forms
# - find out if a prior version is already installed and use that install directory or uninstall it first
# - add firewall rule for bareos-fd after installation.
# - put the config files in $APPDATA
# - add section bconsole automatically when section bat is selected
# - add license information to installer
# - kill tray monitor before installing / updateing TODO: testing
# - replace "the network backups solution" by "backup archiving recovery open sourced"