/
winbareos.nsi
2275 lines (1817 loc) · 78.6 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
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
;
; BAREOS - Backup Archiving REcovery Open Sourced
;
; Copyright (C) 2012-2016 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
#SilentInstall silentlog
BrandingText "Bareos Installer"
; 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
var SEC_DIR_POSTGRES_DESCRIPTION
# 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
Var ClientCompatible # is client compatible?
# Needed for configuring the storage config file
Var StorageName # name of the storage in the director config (Device)
Var StorageDaemonName # name of the storage daemon
Var StoragePassword
Var StorageMonitorPassword
Var StorageAddress
# Needed for bconsole and bat:
Var DirectorAddress #XXX_REPLACE_WITH_HOSTNAME_XXX
Var DirectorPassword #XXX_REPLACE_WITH_DIRECTOR_PASSWORD_XXX
Var DirectorName
Var DirectorMonPassword
# Needed for PostgreSQL Database
Var IsPostgresInstalled
Var PostgresPath
Var PostgresBinPath
var PostgresPsqlExeFullPath
Var DbDriver
Var DbPassword
Var DbPort
Var DbUser
Var DbName
Var DbEncoding
Var DbAdminPassword
Var DbAdminUser
# do we need to install Director/Storage (Cmdline setting)
Var InstallDirector
Var InstallStorage
# Install the webui (cmdline setting)
Var InstallWebUI
Var WebUIListenAddress
Var WebUIListenPort
Var WebUILogin
Var WebUIPassword
# Generated configuration snippet for bareos director config (client ressource)
Var ConfigSnippet
Var OsIsNT
Var dialog
Var hwnd
# Keep the configuration files also when running silently?
Var SilentKeepConfig
# Are we doing an upgrade or fresh install?
# If we are doing an upgrade we automatically
# keep the existing config files silently and skip
# the param dialogs and the config snippet dialog
Var Upgrading
# variable if we do write logs or not
#
Var WriteLogs
!include "LogicLib.nsh"
!include "FileFunc.nsh"
!include "Sections.nsh"
!include "StrFunc.nsh"
!include "WinMessages.nsh"
!include "nsDialogs.nsh"
!include "x64.nsh"
!include "WinVer.nsh"
!include "WordFunc.nsh"
# call functions once to have them included
${StrCase}
${StrTrimNewLines}
${StrRep}
; MUI 1.67 compatible ------
!include "MUI.nsh"
; MUI Settings
!define MUI_ABORTWARNING
!define MUI_ICON "bareos.ico"
!define MUI_UNICON "bareos.ico"
#!define MUI_ICON "${NSISDIR}\Contrib\Graphics\Icons\modern-install.ico"
#!define MUI_UNICON "${NSISDIR}\Contrib\Graphics\Icons\modern-uninstall.ico"
!define MUI_COMPONENTSPAGE_SMALLDESC
!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 page to get Client parameter
Page custom getClientParameters
; Custom page to get parameter to access the bareos-director
Page custom getDirectorParameters
; Custom page to get parameter for a local database
Page custom getDatabaseParameters getDatabaseParametersLeave
; Custom page to get parameter to for a local bareos-storage
Page custom getStorageParameters
; Instfiles page
!insertmacro MUI_PAGE_INSTFILES
; Finish page
; Custom page shows director config snippet
Page custom displayDirconfSnippet
Function LaunchLink
StrCmp $InstallWebUI "no" skipLaunchWebui
ExecShell "open" "http://$WebUIListenAddress:$WebUIListenPort"
skipLaunchWebui:
ExecShell "open" "http://www.bareos.com"
FunctionEnd
!define MUI_FINISHPAGE_RUN
#!define MUI_FINISHPAGE_RUN_NOTCHECKED
!define MUI_FINISHPAGE_RUN_TEXT "Open Bareos websites"
!define MUI_FINISHPAGE_RUN_FUNCTION "LaunchLink"
!insertmacro MUI_PAGE_FINISH
; Uninstaller pages
!insertmacro MUI_UNPAGE_INSTFILES
; Language files
!insertmacro MUI_LANGUAGE "English"
; Reserve files
!insertmacro MUI_RESERVEFILE_INSTALLOPTIONS
; MUI end ------
!macro "CreateURLShortCut" "URLFile" "URLSite" "URLDesc"
WriteINIStr "${URLFile}.URL" "InternetShortcut" "URL" "${URLSite}"
!macroend
# check if postgres is installed and set the postgres variables if so
!macro getPostgresVars
SetShellVarContext all
ClearErrors
ReadRegStr $PostgresPath HKLM "SOFTWARE\PostgreSQL Global Development Group\PostgreSQL" "Location"
${If} ${Errors}
StrCpy $IsPostgresInstalled "no"
${Else}
StrCpy $IsPostgresInstalled "yes"
StrCpy $R0 "$PostgresPath"
StrCpy $R1 "\bin"
StrCpy $PostgresBinPath "$R0$R1" # create postgresbinpath
StrCpy $PostgresPsqlExeFullPath "$\"$PostgresBinPath\psql.exe$\""
${EndIf}
!macroend
# check for the connection of the admin user with DbAdminUser/DbAdminPass
# if not successfull, abort
# this will quit the silent installer
# and jump back to the db param dialog in interactive installer
!macro CheckDbAdminConnection
!define UniqueID ${__LINE__} # create a unique Id to be able to use labels in the macro.
# See http://nsis.sourceforge.net/Tutorial:_Using_labels_in_macro%27s
StrCmp $WriteLogs "yes" 0 +2
LogEx::Init false $INSTDIR\sql.log
StrCmp $WriteLogs "yes" 0 +2
LogEx::Write "PostgresPath=$PostgresPath"
# set postgres username and password in environment
System::Call 'kernel32::SetEnvironmentVariable(t "PGUSER", t "$DbAdminUser")i.r0'
System::Call 'kernel32::SetEnvironmentVariable(t "PGPASSWORD", t "$DbAdminPassword")i.r0'
DetailPrint "Now trying to log into the postgres server with the DbAdmin User and Password"
DetailPrint "Running $PostgresPsqlExeFullPath -c \copyright"
StrCmp $WriteLogs "yes" 0 +2
LogEx::Write "Running $PostgresPsqlExeFullPath -c \copyright"
nsExec::Exec /TIMEOUT=10000 "$PostgresPsqlExeFullPath -c \copyright"
Pop $0 # return value/error/timeout
DetailPrint "Return Value is $0"
StrCmp $WriteLogs "yes" 0 +2
LogEx::Write "Return Value is $0"
${select} $0
${case} "1"
DetailPrint "psql.exe was killed"
StrCmp $WriteLogs "yes" 0 +2
LogEx::Write "psql.exe was killed"
${case} "2"
DetailPrint "connection failed, username or password wrong?"
StrCmp $WriteLogs "yes" 0 +2
LogEx::Write "connection failed, username or password wrong?"
${case} "timeout"
DetailPrint "connection timed out, probably password is wrong?"
StrCmp $WriteLogs "yes" 0 +2
LogEx::Write "connection timed out, probably password is wrong?"
${case} "error"
DetailPrint "could not execute $PostgresPsqlExeFullPath"
StrCmp $WriteLogs "yes" 0 +2
LogEx::Write "could not execute $PostgresPsqlExeFullPath"
${case} "0"
DetailPrint "success"
StrCmp $WriteLogs "yes" 0 +2
LogEx::Write "success"
goto afterabort_${UniqueID}
${caseelse}
DetailPrint "Unknown problem executing $PostgresPsqlExeFullPath"
StrCmp $WriteLogs "yes" 0 +2
LogEx::Write "Unknown problem executing $PostgresPsqlExeFullPath"
${endselect}
MessageBox MB_OK|MB_ICONSTOP "Connection to db server with DbAdmin credentials failed.$\r$\nplease check username/password and service$\r$\n($PostgresPsqlExeFullPath -c \copyright)" /SD IDOK
StrCmp $WriteLogs "yes" 0 +2
LogEx::Write "Connection to db server with DbAdmin credentials failed.$\r$\nplease check username/password and service$\r$\n($PostgresPsqlExeFullPath -c \copyright)"
StrCmp $WriteLogs "yes" 0 +2
LogEx::Close
FileOpen $R1 $TEMP\abortreason.txt w
FileWrite $R1 "database connection failed"
FileClose $R1
abort
afterabort_${UniqueID}:
!undef UniqueID
!macroend
#
# 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}"
StrCmp $SilentKeepConfig "yes" keep # in silent install keep configs silently if desired
StrCmp $Upgrading "yes" keep # during upgrade also keep configs silently
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 skipmsgbox
keep:
Rename "$PLUGINSDIR\${fname}" "$APPDATA\${PRODUCT_NAME}\${fname}.new"
StrCmp $Upgrading "yes" skipmsgbox # during upgrade keep existing file without messagebox
MessageBox MB_OK|MB_ICONINFORMATION \
"New config file stored $APPDATA\${PRODUCT_NAME}\${fname}.new" \
/SD IDOK
skipmsgbox:
${Else}
Rename "$PLUGINSDIR\${fname}" "$APPDATA\${PRODUCT_NAME}\${fname}"
${EndIf}
CreateShortCut "$SMPROGRAMS\${PRODUCT_NAME}\Edit ${fname}.lnk" "write.exe" '"$APPDATA\${PRODUCT_NAME}\${fname}"'
# for traymonitor.conf, set access and ownership to users
${If} ${fname} == "tray-monitor.conf"
# Disable file access inheritance
AccessControl::DisableFileInheritance "$APPDATA\${PRODUCT_NAME}\${fname}"
Pop $R0
${If} $R0 == error
Pop $R0
DetailPrint `AccessControl error: $R0`
${EndIf}
# Set file owner to Users
AccessControl::SetFileOwner "$APPDATA\${PRODUCT_NAME}\${fname}" "(S-1-5-32-545)" # user
Pop $R0
${If} $R0 == error
Pop $R0
DetailPrint `AccessControl error: $R0`
${EndIf}
# Set fullaccess for Users (S-1-5-32-545)
AccessControl::SetOnFile "$APPDATA\${PRODUCT_NAME}\${fname}" "(S-1-5-32-545)" "FullAccess"
Pop $R0
${If} $R0 == error
Pop $R0
DetailPrint `AccessControl error: $R0`
${EndIf}
${Else}
# All other config files admin owner and only access
# Disable file access inheritance
AccessControl::DisableFileInheritance "$APPDATA\${PRODUCT_NAME}\${fname}"
Pop $R0
${If} $R0 == error
Pop $R0
DetailPrint `AccessControl error: $R0`
${EndIf}
# Set file owner to administrator
AccessControl::SetFileOwner "$APPDATA\${PRODUCT_NAME}\${fname}" "(S-1-5-32-544)" # administratoren
Pop $R0
${If} $R0 == error
Pop $R0
DetailPrint `AccessControl error: $R0`
${EndIf}
# Set fullaccess only for administrators (S-1-5-32-544)
AccessControl::ClearOnFile "$APPDATA\${PRODUCT_NAME}\${fname}" "(S-1-5-32-544)" "FullAccess"
Pop $R0
${If} $R0 == error
Pop $R0
DetailPrint `AccessControl error: $R0`
${EndIf}
${EndIf}
!macroend
!macro AllowAccessForAll fname
# This is important to have $APPDATA variable
# point to ProgramData folder
# instead of current user's Roaming folder
SetShellVarContext all
# Disable file access inheritance
AccessControl::DisableFileInheritance "${fname}"
Pop $R0
${If} $R0 == error
Pop $R0
DetailPrint `AccessControl error: $R0`
${EndIf}
# Set file owner to Users
AccessControl::SetFileOwner "${fname}" "(S-1-5-32-545)" # user
Pop $R0
${If} $R0 == error
Pop $R0
DetailPrint `AccessControl error: $R0`
${EndIf}
# Set fullaccess for Users (S-1-5-32-545)
AccessControl::SetOnFile "${fname}" "(S-1-5-32-545)" "FullAccess"
Pop $R0
${If} $R0 == error
Pop $R0
DetailPrint `AccessControl error: $R0`
${EndIf}
!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 - FileDaemon + Plugins, Traymonitor"
InstType "Full SQLite - All Daemons, Director with SQLite Backend (no DB Server needed)"
InstType "Full PostgreSQL - All Daemons, Director PostgreSQL Backend (needs local PostgreSQL Server)"
InstType "Minimal - FileDaemon + Plugins, no Traymonitor"
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-sd.exe"
KillProcWMI::KillProc "bareos-dir.exe"
KillProcWMI::KillProc "bareos-tray-monitor.exe"
KillProcWMI::KillProc "bconsole.exe"
KillProcWMI::KillProc "bat.exe"
SectionEnd
Section -SetPasswords
SetShellVarContext all
# TODO: replace by ConfigureConfiguration ?
FileOpen $R1 $PLUGINSDIR\postgres.sed w
FileWrite $R1 "s#@DB_USER@#$DbUser#g$\r$\n"
FileWrite $R1 "s#@DB_PASS@#with password '$DbPassword'#g$\r$\n"
FileClose $R1
#
# config files for bconsole and bat to access remote director
#
FileOpen $R1 $PLUGINSDIR\bconsole.sed w
FileWrite $R1 "s#@basename@-dir#$DirectorName#g$\r$\n"
FileWrite $R1 "s#@dir_port@#9101#g$\r$\n"
FileWrite $R1 "s#@hostname@#$DirectorAddress#g$\r$\n"
FileWrite $R1 "s#@dir_password@#$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"'
# Configure webui
FileOpen $R1 $PLUGINSDIR\webui.sed w
FileWrite $R1 "s#/etc/bareos-webui/directors.ini#C:/ProgramData/Bareos/directors.ini#g$\r$\n"
FileWrite $R1 "s#/etc/bareos-webui/configuration.ini#C:/ProgramData/Bareos/configuration.ini#g$\r$\n"
FileWrite $R1 "s#;include_path = $\".;c.*#include_path = $\".;c:/php/includes;C:/Program Files/Bareos/bareos-webui/vendor/ZendFramework$\"#g$\r$\n"
FileWrite $R1 "s#; extension_dir = $\"ext$\"#extension_dir = $\"ext$\"#g$\r$\n"
FileWrite $R1 "s#;extension=php_gettext.dll#extension=php_gettext.dll#g$\r$\n"
# set username/password to bareos/bareos
FileWrite $R1 "s#user1#bareos#g$\r$\n"
FileWrite $R1 "s#CHANGEME#bareos#g$\r$\n"
# configure webui login
# Name = admin
# Password = "admin"
#
FileWrite $R1 "s#Name = admin#Name = $WebUILogin#g$\r$\n"
FileWrite $R1 "s#Password = $\"admin$\"#Password = $WebUIPassword#g$\r$\n"
FileClose $R1
nsExec::ExecToLog '$PLUGINSDIR\sed.exe -f "$PLUGINSDIR\webui.sed" -i-template "$PLUGINSDIR\php.ini"'
nsExec::ExecToLog '$PLUGINSDIR\sed.exe -f "$PLUGINSDIR\webui.sed" -i-template "$PLUGINSDIR\global.php"'
nsExec::ExecToLog '$PLUGINSDIR\sed.exe -f "$PLUGINSDIR\webui.sed" -i-template "$PLUGINSDIR\admin.conf"'
SectionEnd
#
# Check if database server is installed only in silent mode
# otherwise this is done in the database dialog
#
Section -DataBaseCheck
IfSilent 0 DataBaseCheckEnd # if we are silent, we do the db credentials check, otherwise the db dialog will do it
StrCmp $InstallDirector "no" DataBaseCheckEnd # skip DbConnection if not instaling director
StrCmp $DbDriver "sqlite3" DataBaseCheckEnd # skip DbConnection if not instaling director
${If} ${SectionIsSelected} ${SEC_DIR_POSTGRES}
!insertmacro CheckDbAdminConnection
${EndIF}
DataBaseCheckEnd:
SectionEnd
!If ${WIN_DEBUG} == yes
# install sourcecode if WIN_DEBUG is yes
Section Sourcecode SEC_SOURCE
SectionIn 1 2 3 4
SetShellVarContext all
SetOutPath "C:\"
SetOverwrite ifnewer
File /r "bareos-${VERSION}"
SectionEnd
!Endif
SubSection "File Daemon (Client)" SUBSEC_FD
Section "File Daemon and base libs" SEC_FD
SectionIn 1 2 3 4
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'
SetOverwrite ifnewer
CreateDirectory "$SMPROGRAMS\${PRODUCT_NAME}"
CreateDirectory "$APPDATA\${PRODUCT_NAME}"
SetOutPath "$INSTDIR"
File "bareos-config-deploy.bat"
File "bareos-fd.exe"
File "libbareos.dll"
File "libbareosfind.dll"
File "libbareoslmdb.dll"
File "libcrypto-*.dll"
File "libgcc_s_*-1.dll"
File "libssl-*.dll"
File "libstdc++-6.dll"
File "libwinpthread-1.dll"
File "zlib1.dll"
File "liblzo2-2.dll"
File "libfastlz.dll"
File "libjansson-4.dll"
# for password generation
File "openssl.exe"
File "sed.exe"
# install unittests
File "test_*.exe"
File "/oname=cmocka.dll" "libcmocka.dll"
# install configuration as templates
SetOutPath "$INSTDIR\defaultconfigs\bareos-fd.d"
File /r config\bareos-fd.d\*.*
# install configuration as templates
SetOutPath "$INSTDIR\defaultconfigs\tray-monitor.d\client\"
File config\tray-monitor.d\client\FileDaemon-local.conf
SetOutPath "$APPDATA\${PRODUCT_NAME}"
File "config\fillup.sed"
SectionEnd
Section /o "File Daemon Plugins " SEC_FDPLUGINS
SectionIn 1 2 3 4
SetShellVarContext all
SetOutPath "$INSTDIR\Plugins"
SetOverwrite ifnewer
#File "bpipe-fd.dll"
#File "mssqlvdi-fd.dll"
#File "python-fd.dll"
File "*-fd.dll"
File "Plugins\BareosFd*.py"
File "Plugins\bareos-fd*.py"
File "Plugins\bareos_fd*.py"
SectionEnd
Section "Open Firewall for File Daemon" SEC_FIREWALL_FD
SectionIn 1 2 3 4
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
SubSectionEnd #FileDaemon Subsection
SubSection "Storage Daemon" SUBSEC_SD
Section /o "Storage Daemon" SEC_SD
SectionIn 2 3
SetShellVarContext all
SetOutPath "$INSTDIR"
SetOverwrite ifnewer
File "libbareossd.dll"
File "bareos-sd.exe"
File "btape.exe"
File "bls.exe"
File "bextract.exe"
File "bscan.exe"
CreateDirectory "C:\bareos-storage"
# install configuration as templates
SetOutPath "$INSTDIR\defaultconfigs\bareos-sd.d"
File /r config\bareos-sd.d\*.*
# install configuration as templates
SetOutPath "$INSTDIR\defaultconfigs\tray-monitor.d\storage"
File config\tray-monitor.d\storage\StorageDaemon-local.conf
SectionEnd
Section /o "Storage Daemon Plugins " SEC_SDPLUGINS
SectionIn 2 3
SetShellVarContext all
SetOutPath "$INSTDIR\Plugins"
SetOverwrite ifnewer
File "*-sd.dll"
File "Plugins\BareosSd*.py"
File "Plugins\bareos-sd*.py"
File "Plugins\bareos_sd*.py"
SectionEnd
Section "Open Firewall for Storage Daemon" SEC_FIREWALL_SD
SectionIn 2 3
SetShellVarContext current
${If} ${AtLeastWin7}
DetailPrint "Opening Firewall, OS is Win7+"
DetailPrint "netsh advfirewall firewall add rule name=$\"Bareos storage daemon (bareos-sd) access$\" dir=in action=allow program=$\"$PROGRAMFILES64\${PRODUCT_NAME}\bareos-sd.exe$\" enable=yes protocol=TCP localport=9103 description=$\"Bareos storage daemon rule$\""
# profile=[private,domain]"
nsExec::Exec "netsh advfirewall firewall add rule name=$\"Bareos storage daemon (bareos-sd) access$\" dir=in action=allow program=$\"$PROGRAMFILES64\${PRODUCT_NAME}\bareos-sd.exe$\" enable=yes protocol=TCP localport=9103 description=$\"Bareos storage daemon rule$\""
# profile=[private,domain]"
${Else}
DetailPrint "Opening Firewall, OS is < Win7"
DetailPrint "netsh firewall add portopening protocol=TCP port=9103 name=$\"Bareos storage daemon (bareos-sd) access$\""
nsExec::Exec "netsh firewall add portopening protocol=TCP port=9103 name=$\"Bareos storage daemon (bareos-sd) access$\""
${EndIf}
SectionEnd
SubSectionEnd # Storage Daemon Subsection
SubSection "Director" SUBSEC_DIR
Section /o "Director" SEC_DIR
SectionIn 2 3
SetShellVarContext all
CreateDirectory "$APPDATA\${PRODUCT_NAME}\logs"
CreateDirectory "$APPDATA\${PRODUCT_NAME}\working"
CreateDirectory "$APPDATA\${PRODUCT_NAME}\scripts"
SetOutPath "$INSTDIR"
SetOverwrite ifnewer
File "bareos-dir.exe"
File "bareos-dbcheck.exe"
File "bsmtp.exe"
File "bregex.exe"
File "bwild.exe"
File "libbareoscats.dll"
# install configuration as templates
SetOutPath "$INSTDIR\defaultconfigs\bareos-dir.d"
File /r config\bareos-dir.d\*.*
# install configuration as templates
SetOutPath "$INSTDIR\defaultconfigs\tray-monitor.d\director"
File config\tray-monitor.d\director\Director-local.conf
SectionEnd
Section /o "Director PostgreSQL Backend Support " SEC_DIR_POSTGRES
SectionIn 3
SetShellVarContext all
SetOutPath "$INSTDIR"
File "libbareoscats-postgresql.dll"
# edit sql ddl files
nsExec::ExecToLog '$PLUGINSDIR\sed.exe -f "$PLUGINSDIR\postgres.sed" -i-template "$PLUGINSDIR\postgresql-grant.sql"'
# install edited sql ddl files
Rename "$PLUGINSDIR\postgresql-create.sql" "$APPDATA\${PRODUCT_NAME}\scripts\postgresql-create.sql"
Rename "$PLUGINSDIR\postgresql-grant.sql" "$APPDATA\${PRODUCT_NAME}\scripts\postgresql-grant.sql"
Rename "$PLUGINSDIR\postgresql-drop.sql" "$APPDATA\${PRODUCT_NAME}\scripts\postgresql-drop.sql"
# create db-create script
FileOpen $R1 $PLUGINSDIR\postgresql-createdb.sql w
FileWrite $R1 "CREATE DATABASE $DbName $DbEncoding TEMPLATE template0; $\r$\n"
FileWrite $R1 "ALTER DATABASE $DbName SET datestyle TO 'ISO, YMD'; $\r$\n"
FileClose $R1
# install db-create script
Rename "$PLUGINSDIR\postgresql-createdb.sql" "$APPDATA\${PRODUCT_NAME}\scripts\postgresql-createdb.sql"
# copy postgresql libs to our path
StrCpy $R0 "$PostgresPath"
StrCpy $R1 "\bin"
StrCpy $PostgresBinPath "$R0$R1"
DetailPrint "Copying dlls from $PostgresBinPath ..."
DetailPrint "libpq.dll"
CopyFiles /SILENT "$PostgresBinPath\libpq.dll" "$INSTDIR"
DetailPrint "libintl*.dll"
CopyFiles /SILENT "$PostgresBinPath\libintl*.dll" "$INSTDIR"
DetailPrint "ssleay32.dll"
CopyFiles /SILENT "$PostgresBinPath\ssleay32.dll" "$INSTDIR"
DetailPrint "libeay32.dll"
CopyFiles /SILENT "$PostgresBinPath\libeay32.dll" "$INSTDIR"
# needed since postgresql 9.5
DetailPrint "libiconv-2.dll"
CopyFiles /SILENT "$PostgresBinPath\libiconv-2.dll" "$INSTDIR"
# Since PostgreSQL 9.4 unfortunately setting the PATH Variable is not enough
# to execute psql.exe It always complains about:
# > could not find a "psql.exe" to execute
# > psql.exe: could not find own program executable
# so we use the full path in the batch scripts
#
# write database create batch file
#
FileOpen $R1 "$APPDATA\${PRODUCT_NAME}\scripts\postgres_db_setup.bat" w
FileWrite $R1 'REM call this batch file to create the bareos database in postgresql $\r$\n'
FileWrite $R1 'REM $\r$\n'
FileWrite $R1 'REM $\r$\n'
FileWrite $R1 'REM create postgresql database $\r$\n'
FileWrite $R1 "SET PATH=%PATH%;$\"$PostgresBinPath$\"$\r$\n"
FileWrite $R1 "cd $APPDATA\${PRODUCT_NAME}\scripts\$\r$\n"
FileWrite $R1 "echo creating bareos database$\r$\n"
FileWrite $R1 "$PostgresPsqlExeFullPath -f postgresql-createdb.sql$\r$\n"
FileWrite $R1 "echo creating bareos database tables$\r$\n"
FileWrite $R1 "$PostgresPsqlExeFullPath -f postgresql-create.sql $DbName$\r$\n"
FileWrite $R1 "echo granting bareos database rights$\r$\n"
FileWrite $R1 "$PostgresPsqlExeFullPath -f postgresql-grant.sql $DbName$\r$\n"
FileClose $R1
#
# write database dump file
#
FileOpen $R1 "$APPDATA\${PRODUCT_NAME}\scripts\make_catalog_backup.bat" w
FileWrite $R1 '@echo off$\r$\n'
FileWrite $R1 'REM call this batch file to create a db dump$\r$\n'
FileWrite $R1 'REM create postgresql database dump$\r$\n'
FileWrite $R1 'SET PGUSER=bareos$\r$\n'
FileWrite $R1 'SET PGPASSWORD=bareos$\r$\n'
FileWrite $R1 'SET PGDATABASE=bareos$\r$\n'
FileWrite $R1 "SET PATH=%PATH%;$\"$PostgresBinPath$\"$\r$\n"
FileWrite $R1 'echo dumping bareos database$\r$\n'
FileWrite $R1 "$\"$PostgresBinPath\pg_dump.exe$\" -f $\"$APPDATA\${PRODUCT_NAME}\working\bareos.sql$\" -c$\r$\n"
FileClose $R1
#
# write delete sql dump file
#
FileOpen $R1 "$APPDATA\${PRODUCT_NAME}\scripts\delete_catalog_backup.bat" w
FileWrite $R1 '@echo off $\r$\n'
FileWrite $R1 'REM this script deletes the db dump $\r$\n'
FileWrite $R1 'del $APPDATA\${PRODUCT_NAME}\working\bareos.sql $\r$\n'
FileClose $R1
SectionEnd
Section /o "Director SQLite Backend Support " SEC_DIR_SQLITE
SectionIn 2
SetShellVarContext all
SetOutPath "$INSTDIR"
File "sqlite3.exe"
File "libsqlite3-0.dll"
File "libbareoscats-sqlite3.dll"
Rename "$PLUGINSDIR\sqlite3.sql" "$APPDATA\${PRODUCT_NAME}\scripts\sqlite3.sql"
# write database create batch file sqlite3
#
FileOpen $R1 "$APPDATA\${PRODUCT_NAME}\scripts\sqlite3-createdb.bat" w
FileWrite $R1 'REM call this batch file to create the bareos database in sqlite3 $\r$\n'
FileWrite $R1 'REM $\r$\n'
FileWrite $R1 'REM $\r$\n'
FileWrite $R1 'REM create sqlite3 database $\r$\n'
FileWrite $R1 "cd $APPDATA\${PRODUCT_NAME}\scripts\$\r$\n"
FileWrite $R1 "echo creating bareos database$\r$\n"
FileWrite $R1 "$\"$INSTDIR\sqlite3.exe$\" $\"$APPDATA\${PRODUCT_NAME}\\working\bareos.db$\" < $\"$APPDATA\${PRODUCT_NAME}\scripts\sqlite3.sql$\"$\r$\n"
FileClose $R1
#
# write database dump file
#
FileOpen $R1 "$APPDATA\${PRODUCT_NAME}\scripts\make_catalog_backup.bat" w
FileWrite $R1 '@echo off$\r$\n'
FileWrite $R1 'REM call this batch file to create a db dump$\r$\n'
FileWrite $R1 'REM create sqlite3 database dump$\r$\n'
FileWrite $R1 'echo dumping bareos database$\r$\n'
FileWrite $R1 "echo .dump | $\"$INSTDIR\sqlite3.exe$\" $\"$APPDATA\${PRODUCT_NAME}\\working\bareos.db$\" > $\"$APPDATA\${PRODUCT_NAME}\working\bareos.sql$\"$\r$\n"
FileClose $R1
#
# write delete sql dump file
#
FileOpen $R1 "$APPDATA\${PRODUCT_NAME}\scripts\delete_catalog_backup.bat" w
FileWrite $R1 '@echo off $\r$\n'
FileWrite $R1 'REM this script deletes the db dump $\r$\n'
FileWrite $R1 'del $APPDATA\${PRODUCT_NAME}\working\bareos.sql $\r$\n'
FileClose $R1
SectionEnd
Section /o "Director Plugins" SEC_DIRPLUGINS
SectionIn 2 3
SetShellVarContext all
SetOutPath "$INSTDIR\Plugins"
SetOverwrite ifnewer
#File "python-dir.dll"
File "*-dir.dll"
File "Plugins\BareosDir*.py"
File "Plugins\bareos-dir*.py"
File "Plugins\bareos_dir*.py"
SectionEnd
Section "Open Firewall for Director" SEC_FIREWALL_DIR
SectionIn 2 3
SetShellVarContext current
${If} ${AtLeastWin7}
DetailPrint "Opening Firewall, OS is Win7+"
DetailPrint "netsh advfirewall firewall add rule name=$\"Bareos director (bareos-dir) access$\" dir=in action=allow program=$\"$PROGRAMFILES64\${PRODUCT_NAME}\bareos-dir.exe$\" enable=yes protocol=TCP localport=9101 description=$\"Bareos director rule$\""
# profile=[private,domain]"
nsExec::Exec "netsh advfirewall firewall add rule name=$\"Bareos director (bareos-dir) access$\" dir=in action=allow program=$\"$PROGRAMFILES64\${PRODUCT_NAME}\bareos-dir.exe$\" enable=yes protocol=TCP localport=9101 description=$\"Bareos director rule$\""
# profile=[private,domain]"
${Else}
DetailPrint "Opening Firewall, OS is < Win7"
DetailPrint "netsh firewall add portopening protocol=TCP port=9101 name=$\"Bareos director (bareos-dir) access$\""
nsExec::Exec "netsh firewall add portopening protocol=TCP port=9101 name=$\"Bareos director (bareos-dir) access$\""
${EndIf}
SectionEnd
SubSectionEnd # Director Subsection
SubSection "User Interfaces" SUBSEC_CONSOLES
Section /o "Tray-Monitor" SEC_TRAYMON
SectionIn 1 2 3
SetShellVarContext all
SetOutPath "$INSTDIR"
SetOverwrite ifnewer
CreateShortCut "$SMPROGRAMS\${PRODUCT_NAME}\bareos-tray-monitor.lnk" "$INSTDIR\bareos-tray-monitor.exe"
# autostart
CreateShortCut "$SMSTARTUP\bareos-tray-monitor.lnk" "$INSTDIR\bareos-tray-monitor.exe"
File "bareos-tray-monitor.exe"
File "libpng*.dll"
File "QtCore4.dll"
File "QtGui4.dll"
# install configuration as templates
SetOutPath "$INSTDIR\defaultconfigs\tray-monitor.d\monitor"
File config\tray-monitor.d\monitor\bareos-mon.conf
SectionEnd
Section "Bareos Webui" SEC_WEBUI
SectionIn 2 3
; set to yes, needed for MUI_FINISHPAGE_RUN_FUNCTION
StrCpy $InstallWebUI "yes"
SetShellVarContext all
SetOutPath "$INSTDIR"
SetOverwrite ifnewer
File /r "nssm.exe"
File /r "bareos-webui"
IfSilent skip_vc_redist_check
# check for Visual C++ Redistributable für Visual Studio 2012 x86 (32 Bit)
ReadRegDword $R1 HKLM "SOFTWARE\Wow6432Node\Microsoft\VisualStudio\11.0\VC\Runtimes\x86" "Installed"
check_for_vc_redist:
${If} $R1 == ""
ExecShell "open" "https://www.microsoft.com/en-us/download/details.aspx?id=30679"
MessageBox MB_OK|MB_ICONSTOP "Visual C++ Redistributable for Visual Studio 2012 x86 was not found$\r$\n\
It is needed by the bareos-webui service.$\r$\n\
Please install vcredist_x86.exe from $\r$\n\
https://www.microsoft.com/en-us/download/details.aspx?id=30679$\r$\n\
and click OK when done." /SD IDOK
${EndIf}
ReadRegDword $R1 HKLM "SOFTWARE\Wow6432Node\Microsoft\VisualStudio\11.0\VC\Runtimes\x86" "Installed"
${If} $R1 == ""
goto check_for_vc_redist
${EndIf}
skip_vc_redist_check:
Rename "$INSTDIR\bareos-webui\config\autoload\global.php" "$INSTDIR\bareos-webui\config\autoload\global.php.orig"
Rename "$PLUGINSDIR\global.php" "$INSTDIR\bareos-webui\config\autoload\global.php"
Rename "$PLUGINSDIR\php.ini" "$APPDATA\${PRODUCT_NAME}\php.ini"
Rename "$PLUGINSDIR\directors.ini" "$APPDATA\${PRODUCT_NAME}\directors.ini"
Rename "$PLUGINSDIR\configuration.ini" "$APPDATA\${PRODUCT_NAME}\configuration.ini"
CreateDirectory "$INSTDIR\defaultconfigs\bareos-dir.d\profile"
Rename "$PLUGINSDIR\webui-admin.conf" "$INSTDIR\defaultconfigs\bareos-dir.d\profile\webui-admin.conf"
CreateDirectory "$INSTDIR\defaultconfigs\bareos-dir.d\console"
Rename "$PLUGINSDIR\admin.conf" "$INSTDIR\defaultconfigs\bareos-dir.d\console\admin.conf"
FileClose $R1
ExecWait '$INSTDIR\nssm.exe install bareos-webui $INSTDIR\bareos-webui\php\php.exe'
ExecWait '$INSTDIR\nssm.exe set bareos-webui AppDirectory \"$INSTDIR\bareos-webui\"'
ExecWait '$INSTDIR\nssm.exe set bareos-webui Application $INSTDIR\bareos-webui\php\php.exe'
# nssm.exe wants """ """ around parameters with spaces, the executable itself without quotes
# see https://nssm.cc/usage -> quoting issues
ExecWait '$INSTDIR\nssm.exe set bareos-webui AppParameters \
-S $WebUIListenAddress:$WebUIListenPort \
-c $\"$\"$\"$APPDATA\${PRODUCT_NAME}\php.ini$\"$\"$\" \
-t $\"$\"$\"$INSTDIR\bareos-webui\public$\"$\"$\"'
ExecWait '$INSTDIR\nssm.exe set bareos-webui AppStdout $\"$\"$\"$APPDATA\${PRODUCT_NAME}\logs\bareos-webui.log$\"$\"$\"'
ExecWait '$INSTDIR\nssm.exe set bareos-webui AppStderr $\"$\"$\"$APPDATA\${PRODUCT_NAME}\logs\bareos-webui.log$\"$\"$\"'
WriteRegStr HKLM "SYSTEM\CurrentControlSet\Services\Bareos-webui" \
"Description" "Bareos Webui php service"
nsExec::ExecToLog "net start Bareos-webui"
# Shortcuts
!insertmacro "CreateURLShortCut" "bareos-webui" "http://$WebUIListenAddress:$WebUIListenPort" "Bareos Backup Server Web Interface"
CreateShortCut "$SMPROGRAMS\${PRODUCT_NAME}\bareos-webui.lnk" "http://$WebUIListenAddress:$WebUIListenPort"
# WebUI Firewall
DetailPrint "Opening Firewall for WebUI"
DetailPrint "netsh advfirewall firewall add rule name=$\"Bareos WebUI access$\" dir=in action=allow program=$\"$INSTDIR\bareos-webui\php\php.exe$\" enable=yes protocol=TCP localport=$WEBUILISTENPORT description=$\"Bareos WebUI rule$\""
# profile=[private,domain]"
nsExec::Exec "netsh advfirewall firewall add rule name=$\"Bareos WebUI access$\" dir=in action=allow program=$\"$INSTDIR\bareos-webui\php\php.exe$\" enable=yes protocol=TCP localport=$WEBUILISTENPORT description=$\"Bareos WebUI rule$\""
# profile=[private,domain]"
SectionEnd
Section /o "Text Console (bconsole)" SEC_BCONSOLE
SectionIn 2 3
SetShellVarContext all