]> git.sur5r.net Git - bacula/bacula/blob - bacula/platforms/rpms/redhat/bacula.spec.in
cb2e315b47690e8e0085eedb65e9e2694a7b6d6f
[bacula/bacula] / bacula / platforms / rpms / redhat / bacula.spec.in
1 #
2 # Bacula RPM spec file
3 #
4
5 # Platform Build Configuration
6
7 # basic defines for every build
8 %define _release           @RELEASE@
9 %define _version           @VERSION@
10 %define product            bacula
11 %define _packager Kern Sibbald <kern@sibbald.com>
12 %define depkgs_version @DEPKGS_VERSION@
13
14 # Don't strip binaries
15 %define __os_install_post %{nil}
16 %define __debug_install_post %{nil}
17 %define debug_package %{nil}
18
19 %define postgres_version 8
20 %define pgre84 0
21 %{?build_rhel5:%define pgre84 1}
22 %{?build_el5:%define pgre84 1}
23 %if %{pgre84}
24 %define postgres_package postgresql84
25 %define postgres_server_package postgresql84-server
26 %define postgres_devel_package postgresql84-devel
27 %else
28 %define postgres_package postgresql
29 %define postgres_server_package postgresql-server
30 %define postgres_devel_package postgresql-devel
31 %endif
32
33 %define single_dir 1
34 %{?single_dir_install:%define single_dir 1}
35
36 # Installation Directory locations
37 %define _prefix        /opt/bacula
38 %define _sbindir       /opt/bacula/bin
39 %define _bindir        /opt/bacula/bin
40 %define _subsysdir     /opt/bacula/working
41 %define sqlite_bindir  /opt/bacula/sqlite
42 %define _mandir        /usr/share/man
43 %define docs_dir       /opt/bacula/docs
44 %define archive_dir    /opt/bacula/archive
45 %define sysconf_dir    /opt/bacula/etc
46 %define script_dir     /opt/bacula/scripts
47 %define working_dir    /opt/bacula/working
48 %define pid_dir        /opt/bacula/working
49 %define plugin_dir     /opt/bacula/plugins
50 %define lib_dir        /opt/bacula/lib
51 %define log_dir        /opt/bacula/log
52 %define systemd_dir    /lib/systemd/system
53
54 # Daemon user:group Don't change them unless you know what you are doing
55 %define director_daemon_user    bacula
56 %define storage_daemon_user     bacula
57 %define file_daemon_user        root
58 %define daemon_group            bacula
59 # group that has write access to tape devices, usually disk on Linux
60 %define storage_daemon_group    disk
61
62 %define depkgs ../depkgs
63
64 # problems with mandriva build:
65 # nothing provides libbonobo2_0-devel, nothing provides libbonoboui2_0-devel
66
67 #--------------------------------------------------------------------------
68 # it should not be necessary to change anything below here for a release
69 # except for patch macros in the setup section
70 #--------------------------------------------------------------------------
71
72 %define base_package_name %{product}
73
74 %{?contrib_packager:%define _packager %{contrib_packager}}
75
76 Summary: Bacula - The Network Backup Solution
77 Name: %{base_package_name}
78 Version: %{_version}
79 Release: %{_release}
80 Group: System Environment/Daemons
81 License: AGPLv3
82 BuildRoot: %{_tmppath}/%{name}-root
83 URL: http://www.bacula.org/
84 Vendor: The Bacula Team
85 Packager: %{_packager}
86 Prefix: %{_prefix}
87
88 # opensuse build service changes the release itself
89 # what happens if the release is not 1? DSB
90 Source0: http://www.prdownloads.sourceforge.net/bacula/depkgs-%{depkgs_version}.tar.gz
91 Source1: http://www.prdownloads.sourceforge.net/bacula/%{product}-%{version}.tar.gz
92 Source2: Release_Notes-%{version}-%{release}.tar.gz
93
94 # define the basic package description
95 %define blurb Bacula - The Leading Open Source Backup Solution.
96 %define blurb2 Bacula is a set of computer programs that permit you (or the system
97 %define blurb3 administrator) to manage backup, recovery, and verification of computer
98 %define blurb4 data across a network of computers of different kinds. In technical terms,
99 %define blurb5 it is a network client/server based backup program. Bacula is relatively
100 %define blurb6 easy to use and efficient, while offering many advanced storage management
101 %define blurb7 features that make it easy to find and recover lost or damaged files.
102 %define blurb8 Bacula source code has been released under the AGPL version 3 license.
103
104 %define user_file  /etc/passwd
105 %define group_file /etc/group
106
107 # program locations
108 %define useradd  /usr/sbin/useradd
109 %define groupadd /usr/sbin/groupadd
110 %define usermod  /usr/sbin/usermod
111
112 # platform defines - set one below or define the build_xxx on the command line
113 # RedHat builds
114 %define rh7 0
115 %{?build_rh7:%define rh7 1}
116 %define rh8 0
117 %{?build_rh8:%define rh8 1}
118 %define rh9 0
119 %{?build_rh9:%define rh9 1}
120 # Fedora Core build
121 %define fc16 0
122 %{?build_fc16:%define fc16 1}
123 %define fc17 0
124 %{?build_fc17:%define fc17 1}
125 %define fc18 0
126 %{?build_fc18:%define fc18 1}
127 %define fc22 0
128 %{?build_fc22:%define fc22 1}
129 %define fc25 0
130 %{?build_fc25:%define fc25 1}
131 %define fc26 0
132 %{?build_fc26:%define fc26 1}
133 # RedHat Enterprise builds
134 %define rhel3 0
135 %{?build_rhel3:%define rhel3 1}
136 %define rhel4 0
137 %{?build_rhel4:%define rhel4 1}
138 %{?build_rhel4:%define fc3 1}
139 %{?build_el4:%define rhel4 1}
140 %{?build_el4:%define fc3 1}
141 %define rhel5 0
142 %{?build_rhel5:%define rhel5 1}
143 %{?build_rhel5:%define fc6 1}
144 %{?build_el5:%define rhel5 1}
145 %{?build_el5:%define fc6 1}
146 %define rhel6 0
147 %{?build_rhel6:%define rhel6 1}
148 %{?build_el6:%define rhel6 1}
149 %define rhel7 0
150 %{?build_rhel7:%define rhel7 1}
151 %{?build_el7:%define rhel7 1}
152 # CentOS build
153 %define centos3 0
154 %{?build_centos3:%define centos3 1}
155 %define centos4 0
156 %{?build_centos4:%define centos4 1}
157 %{?build_centos4:%define fc3 1}
158 %define centos5 0
159 %{?build_centos5:%define centos5 1}
160 %{?build_centos5:%define fc6 1}
161 %define centos6 0
162 %{?build_centos6:%define centos6 1}
163 %define centos7 0
164 %{?build_centos7:%define centos7 1}
165 # SL build
166 %define sl3 0
167 %{?build_sl3:%define sl3 1}
168 %define sl4 0
169 %{?build_sl4:%define sl4 1}
170 %{?build_sl4:%define fc3 1}
171 %define sl5 0
172 %{?build_sl5:%define sl5 1}
173 %{?build_sl5:%define fc6 1}
174 # SuSE build
175 %define su9 0
176 %{?build_su9:%define su9 1}
177 %define su10 0
178 %{?build_su10:%define su10 1}
179 %define su102 0
180 %{?build_su102:%define su102 1}
181 %define su103 0
182 %{?build_su103:%define su103 1}
183 %define su110 0
184 %{?build_su110:%define su110 1}
185 %define su111 0
186 %{?build_su111:%define su111 1}
187 %define su112 0
188 %{?build_su112:%define su112 1}
189 %define su113 0
190 %{?build_su113:%define su113 1}
191 %define su120 0
192 %{?build_su120:%define su120 1}
193 %define su131 0
194 %{?build_su131:%define su131 1}
195 # Mandrake builds
196 %define mdk 0
197 %{?build_mdk:%define mdk 1}
198 %define mdv 0
199 %{?build_mdv:%define mdv 1}
200 %{?build_mdv:%define mdk 1}
201
202 # client only build
203 %define client_only 0
204 %{?build_client_only:%define client_only 1}
205
206 # if the platform is using systemd
207 %define usesystemd 0
208
209 %if %{rhel7} || %{fc22}|| %{fc25} || %{fc26} || %{centos7}
210 %define usesystemd 1
211 %endif
212
213 # depending if we use systemd or not, we use chkconfig or systemctl
214 %if %{usesystemd}
215 %define service_enable    systemctl enable
216 %define service_disable   systemctl disable
217 %else
218 %define service_enable    /sbin/chkconfig --add
219 %define service_disable   /sbin/chkconfig --del
220 %endif
221
222 # Setup some short cuts
223 %define rhat 0
224 %if %{rh7} || %{rh8} || %{rh9}
225 %define rhat 1
226 %endif
227 %define fed 0
228 %if %{fc16} || %{fc17} || %{fc18} || %{fc22} || %{fc25} || %{fc26}
229 %define fed 1
230 %endif
231 %define suse 0
232 %if %{su9} || %{su10} || %{su102} || %{su103} || %{su110} || %{su111} || %{su112} || %{su120} || %{su131}
233 %define suse 1
234 %endif
235 %define rhel 0
236 %if %{rhel3} || %{rhel4} || %{rhel5} || %{rhel6} || %{rhel7} || %{centos3} || %{centos4} || %{centos5} || %{centos6} || %{centos7}
237 %define rhel 1
238 %endif
239 %define scil 0
240 %if %{sl3} || %{sl4} || %{sl5}
241 %define scil 1
242 %endif
243
244
245 # test for a platform definition
246 %if !%{rhat} && !%{rhel} && !%{fed} && !%{suse} && !%{mdk} && !%{scil}
247 %{error: You must specify a platform. Please examine the spec file.}
248 exit 1
249 %endif
250
251 # distribution-specific directory for logwatch
252 %if %{rh7} || %{rh8} || %{rh9}
253 %define logwatch_dir /etc/log.d
254 %else
255 %define logwatch_dir /etc/logwatch
256 %endif
257
258 # database defines
259 # set for database support desired or define the build_xxx on the command line
260 %define mysql 0
261 %{?build_mysql:%define mysql 1}
262 %define sqlite 0
263 %{?build_sqlite:%define sqlite 1}
264 %define postgresql 0
265 %{?build_postgresql:%define postgresql 1}
266
267 # test for a database definition
268 %if ! %{mysql} && ! %{sqlite} && ! %{postgresql} && ! %{client_only}
269 %{error: You must specify database support, by passing one of the following to rpmbuild:}
270 %{error:   --define build_postgresql=1}
271 %{error:   --define build_sqlite=1}
272 %{error:   --define build_mysql=1}
273 exit 1
274 %endif
275
276 %if %{mysql}
277 %define db_backend mysql
278 %endif
279 %if %{sqlite}
280 %define db_backend sqlite3
281 %endif
282 %if %{postgresql}
283 %define db_backend postgresql
284 %endif
285
286 # 64 bit support
287 %define x86_64 0
288 %{?build_x86_64:%define x86_64 1}
289
290 # check what distribution we are
291 %if %{fc16} || %{fc17} || %{fc18} || %{fc22} || %{fc25} || %{fc26}
292 %define _dist %(grep Fedora /etc/redhat-release)
293 %endif
294 %if %{centos7} || %{centos6}
295 %define _dist %(grep CentOS /etc/redhat-release)
296 %endif
297 %if %{centos5} || %{centos4} || %{centos3}
298 %define _dist %(grep CentOS /etc/redhat-release)
299 %endif
300 %if %{sl5} ||%{sl4} || %{sl3}
301 %define _dist %(grep 'Scientific Linux' /etc/redhat-release)
302 %endif
303 %if %{suse}
304 %define _dist %(grep -i SuSE /etc/SuSE-release)
305 %endif
306
307 Distribution: %_dist
308
309 # should we enable tcp wrappers support
310 %define tcpwrappers 1
311 %{?build_tcpwrappers:%define tcpwrappers 1}
312
313 # do we need to patch for old postgresql version?
314 %define old_pgsql 0
315 %{?build_old_pgsql:%define old_pgsql 1}
316
317 # Mandriva somehow forces the manpage file extension to bz2 rather than gz
318 %if %{mdk}
319 %define manpage_ext bz2
320 %else
321 %define manpage_ext gz
322 %endif
323
324 # for client only build
325 %if %{client_only}
326 %define mysql 0
327 %define postgresql 0
328 %define sqlite 0
329 %endif
330
331 BuildRequires: gcc, gcc-c++, make, autoconf
332 BuildRequires: glibc, glibc-devel
333 BuildRequires: ncurses-devel, readline-devel
334 BuildRequires: libstdc++-devel, zlib-devel
335 BuildRequires: openssl-devel
336 BuildRequires: libacl-devel
337 BuildRequires: pkgconfig
338 BuildRequires: bzip2-devel
339 %if ! %{rh7}
340 BuildRequires: libxml2-devel
341 %endif
342
343 %if %{rh7}
344 BuildRequires: libxml-devel
345 %endif
346 %if %{mdk}
347 BuildRequires: libstdc++-static-devel
348 BuildRequires: glibc-static-devel
349 %endif
350
351 %if %{mysql} && ! %{suse}
352 BuildRequires: mysql-devel
353 %endif
354
355 %if %{postgresql}
356 BuildRequires: %{postgres_devel_package} >= %{postgres_version}
357 %endif
358
359 %description
360 %{blurb}
361
362 %{blurb2}
363 %{blurb3}
364 %{blurb4}
365 %{blurb5}
366 %{blurb6}
367 %{blurb7}
368 %{blurb8}
369
370 #
371 # ===========================================================
372 # Generate mysql, sqlite, or postgresql rpm
373 # ===========================================================
374 #
375 %if %{mysql}
376 %package mysql
377 Provides: libbaccats-%{version}.so()(64bit)
378 #
379 # The following provides is to work around an 
380 #  auto generated requires from src/scripts/logwatch/applybaculadate
381 #  this is a gross kludge to keep it from being a requirement
382 #
383 Provides: perl(Logwatch)
384 %endif
385 %if %{postgresql}
386 %package postgresql
387 %endif
388
389 Summary: Bacula - The Network Backup Solution
390 Group: System Environment/Daemons
391 Provides: bacula-dir, bacula-sd, bacula-fd, bacula-server
392 Conflicts: bacula-client
393
394 Requires: ncurses, libstdc++, zlib, openssl
395 Requires: glibc, readline, %{name}-libs
396
397 %if %{suse}
398 Conflicts: bacula
399 %endif
400
401 %if %{mysql}
402 Requires: mysql
403 %endif
404
405 %if %{postgresql}
406 Requires: postgresql >= 7
407 %endif
408
409 %if %{mysql}
410 %description mysql
411 %endif
412 %if %{sqlite}
413 %description sqlite
414 %endif
415 %if %{postgresql}
416 %description postgresql
417 %endif
418
419 %{blurb}
420
421 %{blurb2}
422 %{blurb3}
423 %{blurb4}
424 %{blurb5}
425 %{blurb6}
426 %{blurb7}
427 %{blurb8}
428
429 %if %{mysql}
430 This build requires MySQL to be installed separately as the catalog database.
431 %endif
432 %if %{postgresql}
433 This build requires PostgreSQL to be installed separately as the catalog database.
434 %endif
435 %if %{sqlite}
436 This build incorporates sqlite3 as the catalog database, statically compiled.
437 %endif
438 %if %{tcpwrappers}
439 This build includes tcp-wrappers support.
440 %endif
441
442
443
444 #
445 # ===========================================================
446 # Client -- bacula-fd rpm
447 # ===========================================================
448 #
449 %package client
450 Summary: Bacula - The Network Backup Solution
451 Group: System Environment/Daemons
452 Provides: bacula-fd
453 Conflicts: bacula-mysql
454 Conflicts: bacula-sqlite
455 Conflicts: bacula-postgresql
456
457 %if %{suse}
458 Provides: %{product}
459 Provides: %{product}-libs
460 %endif
461
462 Requires: libstdc++, zlib, openssl, bzip2-libs
463 Requires: glibc, readline, %{name}-libs
464
465 %description client
466 %{blurb}
467
468 %{blurb2}
469 %{blurb3}
470 %{blurb4}
471 %{blurb5}
472 %{blurb6}
473 %{blurb7}
474 %{blurb8}
475
476 This is the File daemon (Client) only package. It includes the command line
477 console program.
478 %if %{tcpwrappers}
479 This build includes tcp-wrappers support.
480 %endif
481
482 #
483 # ===========================================================
484 # Generate updatedb rpm
485 # ===========================================================
486 #
487 %if ! %{client_only}
488 %package updatedb
489
490 Summary: Bacula - The Network Backup Solution
491 Group: System Environment/Daemons
492
493 %description updatedb
494 %{blurb}
495
496 %{blurb2}
497 %{blurb3}
498 %{blurb4}
499 %{blurb5}
500 %{blurb6}
501 %{blurb7}
502 %{blurb8}
503
504 This package installs scripts for updating older versions of the bacula
505 database.
506 %endif
507
508 #
509 # ===========================================================
510 # Generate libs rpm
511 # ===========================================================
512 #
513 %package libs
514
515 Summary: Bacula - The Network Backup Solution
516 Group: System Environment/Daemons
517
518 %description libs
519 %{blurb}
520
521 %{blurb2}
522 %{blurb3}
523 %{blurb4}
524 %{blurb5}
525 %{blurb6}
526 %{blurb7}
527 %{blurb8}
528
529 This package installs the shared libraries used by many bacula programs.
530
531 # Must explicitly enable debug pkg on SuSE
532 # but not in opensuse_bs
533 #%if %{suse} && ! 0%{?opensuse_bs}
534 #%debug_package
535 #%endif
536
537 %prep
538 %setup -T    -b 0 -n depkgs
539 %setup -T    -b 1 -n %{product}-%{version}
540 %setup -T -D -b 2 -n %{product}-%{version}
541 # extract depkgs
542
543
544 %build
545
546 %if %{suse}
547 #export LDFLAGS="${LDFLAGS} -L/usr/lib/termcap -L/usr/lib64/termcap"
548 %endif
549
550 # You can use a cache for depkgs
551 # tar xfz depkgs*gz -C ~/
552 # cd ~/depkgs
553 # touch %{depkgs_version}       # depkgs version
554
555 if [ -f $HOME/depkgs/%{depkgs_version} ]; then
556    rm -rf %{depkgs}
557    ln -s $HOME/depkgs %{depkgs}
558 fi
559
560 cwd=${PWD}
561 %if %{sqlite}
562 cd %{depkgs}
563 make sqlite3
564 cd ${cwd}
565 %endif
566
567 cd %{depkgs}
568 make lzo
569 export LDFLAGS="${LDFLAGS} -L${PWD}/lzo/lib"
570 export CPPFLAGS="${CPPFLAGS} -I${PWD}/lzo/include"
571 cd ${cwd}
572
573 # hostname is the build hostname, so use XXX_HOSTNAME_XXX for Address parameter
574 sed -i s/hostname/basename/ src/console/bconsole.conf.in src/dird/bacula-dir.conf.in src/qt-console/bat.conf.in
575
576 %if %{sqlite}
577 # patches for the bundled sqlite scripts
578 sed -i s:.SQLITE_BINDIR.:/opt/bacula/sqlite: src/cats/*_sqlite3_*.in
579
580 # patch the bacula-dir init script to remove sqlite service
581 %if %{suse}
582 sed -i 's/network .DB_TYPE./network/' platforms/suse/bacula-dir.in
583 %endif
584 %endif
585
586 # 64 bit lib location hacks
587 # as of 1.39.18 it should not be necessary to enable x86_64 as configure is
588 # reported to be fixed to properly detect lib locations.
589 %if %{x86_64}
590 export LDFLAGS="${LDFLAGS} -L/usr/lib64"
591 %endif
592 %if %{mysql} && %{x86_64}
593 export LDFLAGS="${LDFLAGS} -L/usr/lib64/mysql"
594 %endif
595
596 export BACULA="Bacula"
597
598 # Main Bacula configuration
599 %configure \
600         --prefix=%{_prefix} \
601         --sbindir=%{_sbindir} \
602         --sysconfdir=%{sysconf_dir} \
603         --mandir=%{_mandir} \
604         --with-scriptdir=%{script_dir} \
605         --with-working-dir=%{working_dir} \
606         --with-plugindir=%{plugin_dir} \
607         --with-logdir=%{log_dir} \
608         --with-pid-dir=%{pid_dir} \
609         --with-subsys-dir=%{_subsysdir} \
610         --enable-smartalloc \
611         --disable-conio \
612         --enable-readline \
613 %if %{mysql}
614         --with-mysql \
615 %endif
616 %if %{postgresql}
617         --with-postgresql \
618 %endif
619         --disable-bat \
620 %if %{client_only}
621         --enable-client-only \
622 %endif
623 %if %{rh7} || %{rh8} || %{rh9}
624         --disable-batch-insert \
625 %endif
626 %if %{usesystemd}
627         --with-systemd=%{systemd_dir} \
628 %endif
629         --with-tcp-wrappers  \
630         --with-dir-user=%{director_daemon_user} \
631         --with-dir-group=%{daemon_group} \
632         --with-sd-user=%{storage_daemon_user} \
633         --with-sd-group=%{storage_daemon_group} \
634         --with-fd-user=%{file_daemon_user} \
635         --with-fd-group=%{daemon_group} \
636         --with-basename="XXX_HOSTNAME_XXX" \
637         --with-hostname="XXX_HOSTNAME_XXX" \
638         --with-dir-password="XXX_REPLACE_WITH_DIRECTOR_PASSWORD_XXX" \
639         --with-fd-password="XXX_REPLACE_WITH_CLIENT_PASSWORD_XXX" \
640         --with-sd-password="XXX_REPLACE_WITH_STORAGE_PASSWORD_XXX" \
641         --with-mon-dir-password="XXX_REPLACE_WITH_DIRECTOR_MONITOR_PASSWORD_XXX" \
642         --with-mon-fd-password="XXX_REPLACE_WITH_CLIENT_MONITOR_PASSWORD_XXX" \
643         --with-mon-sd-password="XXX_REPLACE_WITH_STORAGE_MONITOR_PASSWORD_XXX" \
644         --with-openssl
645
646 make -j3
647
648 %install
649
650 cwd=${PWD}
651 [ "$RPM_BUILD_ROOT" != "/" ] && rm -rf "$RPM_BUILD_ROOT"
652 mkdir -p $RPM_BUILD_ROOT/etc/init.d
653 mkdir -p $RPM_BUILD_ROOT/etc/logrotate.d
654 mkdir -p $RPM_BUILD_ROOT%{logwatch_dir}/conf/logfiles
655 mkdir -p $RPM_BUILD_ROOT%{logwatch_dir}/conf/services
656 mkdir -p $RPM_BUILD_ROOT%{logwatch_dir}/scripts/services
657 mkdir -p $RPM_BUILD_ROOT%{logwatch_dir}/scripts/shared
658 mkdir -p $RPM_BUILD_ROOT%{script_dir}/updatedb
659
660 mkdir -p $RPM_BUILD_ROOT/etc/pam.d
661 mkdir -p $RPM_BUILD_ROOT%{_sbindir}
662
663 %if %{sqlite}
664 mkdir -p $RPM_BUILD_ROOT%{sqlite_bindir}
665 %endif
666
667 make DESTDIR=$RPM_BUILD_ROOT install
668
669 # bsnapshot
670 make DESTDIR=$RPM_BUILD_ROOT -C ../bacula-%{_version}/src/tools/ install-bsnapshot
671
672 %if %{usesystemd}
673 make DESTDIR=$RPM_BUILD_ROOT -C platforms/systemd install-dir install-service
674 %endif
675
676 # Remove docs for programs that are depreciated
677 rm -f $RPM_BUILD_ROOT%{_mandir}/man1/bacula-bgnome-console.1.%{manpage_ext}
678 rm -f $RPM_BUILD_ROOT%{_mandir}/man1/bacula-bwxconsole.1.%{manpage_ext}
679 rm -f $RPM_BUILD_ROOT%{_mandir}/man1/bacula-tray-monitor.1.%{manpage_ext}
680 rm -f $RPM_BUILD_ROOT%{script_dir}/gconsole
681
682 # Remove docs for programs we do not distribute
683 rm -f $RPM_BUILD_ROOT%{_mandir}/man8/bpluginfo.8.%{manpage_ext}
684
685 # Remove storage-ctl packaged in shstore rpm
686 rm -f $RPM_BUILD_ROOT%{script_dir}/storage-ctl
687 rm -f $RPM_BUILD_ROOT%{script_dir}/storage-ctl.conf
688
689 # fixme - make installs the mysql scripts for sqlite build
690 %if %{sqlite}
691 rm -f $RPM_BUILD_ROOT%{script_dir}/startmysql
692 rm -f $RPM_BUILD_ROOT%{script_dir}/stopmysql
693 rm -f $RPM_BUILD_ROOT%{script_dir}/grant_mysql_privileges
694 %endif
695
696 # fixme - make installs the mysql scripts for postgresql build
697 %if %{postgresql}
698 rm -f $RPM_BUILD_ROOT%{script_dir}/startmysql
699 rm -f $RPM_BUILD_ROOT%{script_dir}/stopmysql
700 %endif
701
702 # Remove symlinks
703 #rm -f $RPM_BUILD_ROOT%{_libdir}/libbaccats.so
704 #rm -f $RPM_BUILD_ROOT%{_libdir}/libbaccats-%{version}.so
705 rm -f $RPM_BUILD_ROOT%{_libdir}/libbacsd.la
706
707 # install the init scripts
708 %if !%{usesystemd}
709 %if %{suse}
710 cp -p platforms/suse/bacula-dir $RPM_BUILD_ROOT/etc/init.d/bacula-dir
711 cp -p platforms/suse/bacula-fd $RPM_BUILD_ROOT/etc/init.d/bacula-fd
712 cp -p platforms/suse/bacula-sd $RPM_BUILD_ROOT/etc/init.d/bacula-sd
713 %endif                           # suse
714 %if %{mdk}
715 cp -p platforms/mandrake/bacula-dir $RPM_BUILD_ROOT/etc/init.d/bacula-dir
716 cp -p platforms/mandrake/bacula-fd $RPM_BUILD_ROOT/etc/init.d/bacula-fd
717 cp -p platforms/mandrake/bacula-sd $RPM_BUILD_ROOT/etc/init.d/bacula-sd
718 %endif                           # mdk
719 %if ! %{suse} && ! %{mdk}
720 cp -p platforms/redhat/bacula-dir $RPM_BUILD_ROOT/etc/init.d/bacula-dir
721 cp -p platforms/redhat/bacula-fd $RPM_BUILD_ROOT/etc/init.d/bacula-fd
722 cp -p platforms/redhat/bacula-sd $RPM_BUILD_ROOT/etc/init.d/bacula-sd
723 %endif                           # !suse && !mdk
724 chmod 0754 $RPM_BUILD_ROOT/etc/init.d/*
725 %endif                           # ! usesystemd
726
727 %if %{client_only}
728 rm -f $RPM_BUILD_ROOT/etc/init.d/bacula-dir
729 rm -f $RPM_BUILD_ROOT/etc/init.d/bacula-sd
730 rm -f $RPM_BUILD_ROOT%{script_dir}/breload
731 rm -f $RPM_BUILD_ROOT%{script_dir}/manual_prune.pl
732 rm -f $RPM_BUILD_ROOT%{systemd_dir}/bacula-dir.service
733 rm -f $RPM_BUILD_ROOT%{systemd_dir}/bacula-sd.service
734 %endif
735
736 # install sqlite
737 %if %{sqlite}
738 cp -p %{depkgs}/sqlite3/sqlite3 $RPM_BUILD_ROOT%{sqlite_bindir}/sqlite3
739 cp -p %{depkgs}/sqlite3/sqlite3.h $RPM_BUILD_ROOT%{sqlite_bindir}/sqlite3.h
740 cp -p %{depkgs}/sqlite3/libsqlite3.a $RPM_BUILD_ROOT%{sqlite_bindir}/libsqlite3.a
741 %endif
742
743
744 # install the logrotate file
745 cp -p scripts/logrotate $RPM_BUILD_ROOT/etc/logrotate.d/bacula
746
747 # install the updatedb scripts
748 cp -p updatedb/* $RPM_BUILD_ROOT%{script_dir}/updatedb/
749
750 # install specific scripts
751
752 %if ! %{client_only}
753 # install the sample-query.sql file
754 cp -p examples/sample-query.sql $RPM_BUILD_ROOT%{script_dir}/sample-query.sql
755
756 # install the logwatch scripts
757 cp -p scripts/logwatch/bacula $RPM_BUILD_ROOT%{logwatch_dir}/scripts/services/bacula
758 cp -p scripts/logwatch/applybaculadate $RPM_BUILD_ROOT%{logwatch_dir}/scripts/shared/applybaculadate
759 cp -p scripts/logwatch/logfile.bacula.conf $RPM_BUILD_ROOT%{logwatch_dir}/conf/logfiles/bacula.conf
760 cp -p scripts/logwatch/services.bacula.conf $RPM_BUILD_ROOT%{logwatch_dir}/conf/services/bacula.conf
761 chmod 755 $RPM_BUILD_ROOT%{logwatch_dir}/scripts/services/bacula
762 chmod 755 $RPM_BUILD_ROOT%{logwatch_dir}/scripts/shared/applybaculadate
763 chmod 644 $RPM_BUILD_ROOT%{logwatch_dir}/conf/logfiles/bacula.conf
764 chmod 644 $RPM_BUILD_ROOT%{logwatch_dir}/conf/services/bacula.conf
765 %endif
766
767 # now clean up permissions that are left broken by the install
768 chmod o-rwx $RPM_BUILD_ROOT%{working_dir}
769
770 # fix me - building enable-client-only installs files not included in bacula-client package
771 %if %{client_only}
772 # Program docs not installed on client
773 rm -f $RPM_BUILD_ROOT%{_mandir}/man8/bacula-dir.8.%{manpage_ext}
774 rm -f $RPM_BUILD_ROOT%{_mandir}/man8/bacula-sd.8.%{manpage_ext}
775 rm -f $RPM_BUILD_ROOT%{_mandir}/man8/bcopy.8.%{manpage_ext}
776 rm -f $RPM_BUILD_ROOT%{_mandir}/man8/bextract.8.%{manpage_ext}
777 rm -f $RPM_BUILD_ROOT%{_mandir}/man8/bls.8.%{manpage_ext}
778 rm -f $RPM_BUILD_ROOT%{_mandir}/man8/bscan.8.%{manpage_ext}
779 rm -f $RPM_BUILD_ROOT%{_mandir}/man8/btape.8.%{manpage_ext}
780 rm -f $RPM_BUILD_ROOT%{_mandir}/man8/dbcheck.8.%{manpage_ext}
781 rm -f $RPM_BUILD_ROOT%{_mandir}/man8/bregex.8.%{manpage_ext}
782 rm -f $RPM_BUILD_ROOT%{_mandir}/man8/bwild.8.%{manpage_ext}
783 rm -f $RPM_BUILD_ROOT%{_mandir}/man1/bsmtp.1.%{manpage_ext}
784 rm -f $RPM_BUILD_ROOT%{script_dir}/bacula
785 rm -f $RPM_BUILD_ROOT%{script_dir}/bacula_config
786 rm -f $RPM_BUILD_ROOT%{script_dir}/bacula-ctl-dir
787 rm -f $RPM_BUILD_ROOT%{script_dir}/bacula-ctl-sd
788 rm -f $RPM_BUILD_ROOT%{script_dir}/disk-changer
789 rm -f $RPM_BUILD_ROOT%{script_dir}/dvd-handler
790 rm -f $RPM_BUILD_ROOT%{script_dir}/mtx-changer
791 rm -f $RPM_BUILD_ROOT%{script_dir}/startmysql
792 rm -f $RPM_BUILD_ROOT%{script_dir}/stopmysql
793 rm -rf $RPM_BUILD_ROOT%{script_dir}/updatedb
794 rm -f $RPM_BUILD_ROOT%{script_dir}/bconsole
795 rm -f $RPM_BUILD_ROOT%{script_dir}/mtx-changer.conf
796 rm -f $RPM_BUILD_ROOT%{_sbindir}/bacula
797
798 %endif
799
800 %clean
801 [ "$RPM_BUILD_ROOT" != "/" ] && rm -rf "$RPM_BUILD_ROOT"
802 rm -f $RPM_BUILD_DIR/Release_Notes-%{version}-%{release}.txt
803
804
805 %if %{mysql}
806 # MySQL specific files
807 %files mysql
808 %defattr(-, root, root)
809 %attr(-, root, %{daemon_group}) %{script_dir}/create_mysql_database
810 %attr(-, root, %{daemon_group}) %{script_dir}/drop_mysql_database
811 %attr(-, root, %{daemon_group}) %{script_dir}/make_mysql_tables
812 %attr(-, root, %{daemon_group}) %{script_dir}/drop_mysql_tables
813 %attr(-, root, %{daemon_group}) %{script_dir}/update_mysql_tables
814 %attr(-, root, %{daemon_group}) %{script_dir}/grant_mysql_privileges
815 %{_libdir}/libbaccats*
816 %{_libdir}/libbacsql*
817 %{_libdir}/libbacsd*.so
818 %endif
819
820
821 %if %{postgresql}
822 %files postgresql
823 %defattr(-,root,root)
824 %attr(755, root, %{daemon_group}) %{script_dir}/create_postgresql_database
825 %attr(755, root, %{daemon_group}) %{script_dir}/drop_postgresql_database
826 %attr(755, root, %{daemon_group}) %{script_dir}/make_postgresql_tables
827 %attr(755, root, %{daemon_group}) %{script_dir}/drop_postgresql_tables
828 %attr(755, root, %{daemon_group}) %{script_dir}/update_postgresql_tables
829 %attr(755, root, %{daemon_group}) %{script_dir}/grant_postgresql_privileges
830 %{_libdir}/libbaccats*
831 %{_libdir}/libbacsql*
832 %{_libdir}/libbacsd*.so
833 %endif
834
835 # The rest is DB backend independent
836
837 %if ! %{client_only}
838 %attr(-, root, %{daemon_group}) %dir %{script_dir}
839 %attr(-, root, %{daemon_group}) %dir %{sysconf_dir}
840 %attr(-, root, %{daemon_group}) %{script_dir}/bacula
841 %attr(-, root, %{daemon_group}) %{script_dir}/bacula_config
842 %attr(-, root, %{daemon_group}) %{script_dir}/bconsole
843 %attr(755, root, %{daemon_group}) %{script_dir}/create_bacula_database
844 %attr(755, root, %{daemon_group}) %{script_dir}/drop_bacula_database
845 %attr(755, root, %{daemon_group}) %{script_dir}/grant_bacula_privileges
846 %attr(755, root, %{daemon_group}) %{script_dir}/make_bacula_tables
847 %attr(755, root, %{daemon_group}) %{script_dir}/drop_bacula_tables
848 %attr(755, root, %{daemon_group}) %{script_dir}/update_bacula_tables
849 %attr(-, root, %{daemon_group}) %{script_dir}/make_catalog_backup
850 %attr(-, root, %{daemon_group}) %{script_dir}/make_catalog_backup.pl
851 %attr(-, root, %{daemon_group}) %{script_dir}/delete_catalog_backup
852 %attr(-, root, %{daemon_group}) %{script_dir}/btraceback.dbx
853 %attr(-, root, %{daemon_group}) %{script_dir}/btraceback.gdb
854 %attr(-, root, %{daemon_group}) %{script_dir}/btraceback.mdb
855 %attr(-, root, %{daemon_group}) %{script_dir}/disk-changer
856 %attr(-, root, %{daemon_group}) %{script_dir}/bacula-ctl-dir
857 %attr(-, root, %{daemon_group}) %{script_dir}/bacula-ctl-fd
858 %attr(-, root, %{daemon_group}) %{script_dir}/bacula-ctl-sd
859 %attr(-, root, %{daemon_group}) %{script_dir}/tapealert
860 %attr(-, root, %{daemon_group}) %{script_dir}/baculabackupreport
861
862 %attr(-, root, %{daemon_group}) %{plugin_dir}/bpipe-fd.so
863 %attr(-, root, %{daemon_group}) %{_sbindir}/dbcheck
864 %attr(-, root, %{storage_daemon_group}) %{script_dir}/mtx-changer
865 %attr(-, root, %{storage_daemon_group}) %config(noreplace) %{script_dir}/mtx-changer.conf
866
867 %if %{usesystemd}
868 %attr(-, root, %{daemon_group}) %{systemd_dir}/bacula-dir.service
869 %attr(-, root, %{daemon_group}) %{systemd_dir}/bacula-fd.service
870 %attr(-, root, %{daemon_group}) %{systemd_dir}/bacula-sd.service
871 %else
872 %attr(-, root, %{daemon_group}) /etc/init.d/bacula-dir
873 %attr(-, root, %{daemon_group}) /etc/init.d/bacula-fd
874 %attr(-, root, %{storage_daemon_group}) /etc/init.d/bacula-sd
875 %endif
876
877 /etc/logrotate.d/bacula
878 %{logwatch_dir}/scripts/services/bacula
879 %{logwatch_dir}/scripts/shared/applybaculadate
880 %attr(-, root, %{daemon_group}) %config(noreplace) %{sysconf_dir}/bacula-dir.conf
881 %attr(-, root, %{daemon_group}) %config(noreplace) %{sysconf_dir}/bacula-fd.conf
882 %attr(-, root, %{storage_daemon_group}) %config(noreplace) %{sysconf_dir}/bacula-sd.conf
883 %attr(-, root, %{daemon_group}) %config(noreplace) %{sysconf_dir}/bconsole.conf
884 %attr(-, root, %{daemon_group}) %config(noreplace) %{logwatch_dir}/conf/logfiles/bacula.conf
885 %attr(-, root, %{daemon_group}) %config(noreplace) %{logwatch_dir}/conf/services/bacula.conf
886 %attr(-, root, %{daemon_group}) %{script_dir}/sample-query.sql
887 %attr(-, root, %{daemon_group}) %{script_dir}/query.sql
888
889 %attr(-, %{storage_daemon_user}, %{daemon_group}) %dir %{working_dir}
890
891 %attr(-, root, %{daemon_group}) %{_sbindir}/bacula-dir
892 %attr(-, root, %{daemon_group}) %{_sbindir}/bacula-sd
893 %attr(-, root, %{daemon_group}) %{_sbindir}/btraceback
894 %attr(-, root, %{daemon_group}) %{_sbindir}/bconsole
895 %attr(-, root, %{daemon_group}) %{_sbindir}/bbconsjson
896 %attr(-, root, %{daemon_group}) %{_sbindir}/bsmtp
897 %attr(-, root, %{daemon_group}) %{_sbindir}/bscan
898 %attr(-, root, %{daemon_group}) %{_sbindir}/btape
899 %attr(-, root, %{daemon_group}) %{_sbindir}/bdirjson
900 %attr(-, root, %{daemon_group}) %{_sbindir}/bsdjson
901
902 %attr(755, root, root) %{_sbindir}/bsnapshot
903 %attr(755, root, root) %{_sbindir}/bfdjson
904
905 %{_sbindir}/bacula-fd
906 %{_sbindir}/bacula
907 %{_sbindir}/bcopy
908 %{_sbindir}/bextract
909 %{_sbindir}/bls
910 %{_sbindir}/bregex
911 %{_sbindir}/bwild
912 %{_mandir}/man8/bacula-fd.8.%{manpage_ext}
913 %{_mandir}/man8/bacula-dir.8.%{manpage_ext}
914 %{_mandir}/man8/bacula-sd.8.%{manpage_ext}
915 %{_mandir}/man8/bacula.8.%{manpage_ext}
916 %{_mandir}/man8/bconsole.8.%{manpage_ext}
917 %{_mandir}/man8/bcopy.8.%{manpage_ext}
918 %{_mandir}/man8/bextract.8.%{manpage_ext}
919 %{_mandir}/man8/bls.8.%{manpage_ext}
920 %{_mandir}/man8/bscan.8.%{manpage_ext}
921 %{_mandir}/man8/btape.8.%{manpage_ext}
922 %{_mandir}/man8/btraceback.8.%{manpage_ext}
923 %{_mandir}/man8/dbcheck.8.%{manpage_ext}
924 %{_mandir}/man8/bregex.8.%{manpage_ext}
925 %{_mandir}/man8/bwild.8.%{manpage_ext}
926 %{_mandir}/man1/bsmtp.1.%{manpage_ext}
927 %{_mandir}/man1/bat.1.%{manpage_ext}
928 %_prefix/share/doc/*
929
930 %attr(-, root, %{daemon_group}) %{script_dir}/bacula-tray-monitor.desktop
931
932 %doc ../Release_Notes-%{version}-%{release}.txt
933
934 %endif
935
936 %if %{mysql}
937 %pre mysql
938 # test for bacula database older than version 13
939 # note: this ASSUMES no password has been set for bacula database
940 DB_VER=`mysql 2>/dev/null bacula -e 'select * from Version;'|tail -n 1`
941 %endif
942
943 %if %{sqlite}
944 %pre sqlite
945 # are we upgrading from sqlite to sqlite3?
946 if [ -s %{working_dir}/bacula.db ] && [ -s %{sqlite_bindir}/sqlite ];then
947         echo "This version of bacula-sqlite involves an upgrade to sqlite3."
948         echo "Your catalog database file is not compatible with sqlite3, thus"
949         echo "you will need to dump the data, delete the old file, and re-run"
950         echo "this rpm upgrade."
951         echo ""
952         echo "Backing up your current database..."
953         echo ".dump" | %{sqlite_bindir}/sqlite %{working_dir}/bacula.db > %{working_dir}/bacula_backup.sql
954         mv %{working_dir}/bacula.db %{working_dir}/bacula.db.old
955         echo "Your catalog data has been saved in %{working_dir}/bacula_backup.sql and your"
956         echo "catalog file has been renamed %{working_dir}/bacula.db.old."
957         echo ""
958         echo "Please re-run this rpm package upgrade."
959         echo "After the upgrade is complete, restore your catalog"
960         echo "with the following commands:"
961         echo "%{script_dir}/drop_sqlite3_tables"
962         echo "cd %{working_dir}"
963         echo "%{sqlite_bindir}/sqlite3 $* bacula.db < bacula_backup.sql"
964         echo "chown bacula.bacula bacula.db"
965         exit 1
966 fi
967 # test for bacula database older than version 12 and sqlite3
968 if [ -s %{working_dir}/bacula.db ] && [ -s %{sqlite_bindir}/sqlite3 ];then
969         DB_VER=`echo "select * from Version;" | %{sqlite_bindir}/sqlite3 2>/dev/null %{working_dir}/bacula.db | tail -n 1`
970 %endif
971
972 %if %{postgresql}
973 %pre postgresql
974 DB_VER=`echo 'SELECT * FROM Version LIMIT 1;' | su - postgres -c 'psql bacula' 2>/dev/null | tail -3 | head -1`
975 %endif
976
977 %if ! %{client_only}
978 if [ -n "$DB_VER" ] && [ "$DB_VER" -lt "12" ]; then
979     echo "This bacula upgrade will update a bacula database from version 12 to 1014."
980     echo "You appear to be running database version $DB_VER. You must first update"
981     echo "your database to version 12 and then install this upgrade. The alternative"
982     echo "is to use %{script_dir}/drop_%{db_backend}_tables to delete all your your current"
983     echo "catalog information, then do the upgrade. Information on updating a"
984     echo "database older than version 12 can be found in the release notes."
985     exit 1
986 fi
987 %endif
988
989 %if %{sqlite}
990 fi
991 %endif
992
993 %if ! %{client_only}
994 # check for and copy %{sysconf_dir}/console.conf to bconsole.conf
995 if [ -s %{sysconf_dir}/console.conf ];then
996     cp -p %{sysconf_dir}/console.conf %{sysconf_dir}/bconsole.conf
997 fi
998
999 # create the daemon users and groups
1000 # first create the groups if they don't exist
1001 HAVE_BACULA=`grep %{daemon_group} %{group_file} 2>/dev/null`
1002 if [ -z "$HAVE_BACULA" ]; then
1003         %{groupadd} -r %{daemon_group} > /dev/null 2>&1
1004         echo "The group %{daemon_group} has been added to %{group_file}."
1005         echo "See the manual chapter \"Running Bacula\" for details."
1006 fi
1007 HAVE_BACULA=`grep %{storage_daemon_group} %{group_file} 2>/dev/null`
1008 if [ -z "$HAVE_BACULA" ]; then
1009         %{groupadd} -r %{storage_daemon_group} > /dev/null 2>&1
1010         echo "The group %{storage_daemon_group} has been added to %{group_file}."
1011         echo "See the manual chapter \"Running Bacula\" for details."
1012 fi
1013 # now create the users if they do not exist
1014 # we do not use the -g option allowing the primary group to be set to system default
1015 # this will be a unique group on redhat type systems or the group users on some systems
1016 HAVE_BACULA=`grep %{storage_daemon_user} %{user_file} 2>/dev/null`
1017 if [ -z "$HAVE_BACULA" ]; then
1018         %{useradd} -r -c "Bacula" -d %{working_dir} -g %{storage_daemon_group} -M -s /sbin/nologin %{storage_daemon_user} > /dev/null 2>&1
1019         echo "The user %{storage_daemon_user} has been added to %{user_file}."
1020         echo "See the manual chapter \"Running Bacula\" for details."
1021 fi
1022 HAVE_BACULA=`grep %{director_daemon_user} %{user_file} 2>/dev/null`
1023 if [ -z "$HAVE_BACULA" ]; then
1024         %{useradd} -r -c "Bacula" -d %{working_dir} -g %{daemon_group} -M -s /sbin/nologin %{director_daemon_user} > /dev/null 2>&1
1025         echo "The user %{director_daemon_user} has been added to %{user_file}."
1026         echo "See the manual chapter \"Running Bacula\" for details."
1027 fi
1028 HAVE_BACULA=`grep %{file_daemon_user} %{user_file} 2>/dev/null`
1029 if [ -z "$HAVE_BACULA" ]; then
1030         %{useradd} -r -c "Bacula" -d %{working_dir} -g %{daemon_group} -M -s /sbin/nologin %{file_daemon_user} > /dev/null 2>&1
1031         echo "The user %{file_daemon_user} has been added to %{user_file}."
1032         echo "See the manual chapter \"Running Bacula\" for details."
1033 fi
1034 # now we add the supplementary groups, this is ok to call even if the users already exist
1035 # we only do this if the user is NOT root
1036 IS_ROOT=%{director_daemon_user}
1037 if [ "$IS_ROOT" != "root" ]; then
1038 %{usermod} -G %{daemon_group} %{director_daemon_user}
1039 fi
1040 IS_ROOT=%{storage_daemon_user}
1041 if [ "$IS_ROOT" != "root" ]; then
1042 %{usermod} -G %{daemon_group},%{storage_daemon_group} %{storage_daemon_user}
1043 fi
1044 IS_ROOT=%{file_daemon_user}
1045 if [ "$IS_ROOT" != "root" ]; then
1046 %{usermod} -G %{daemon_group} %{file_daemon_user}
1047 fi
1048 %endif
1049
1050 %if %{mysql}
1051 %post mysql
1052 %endif
1053 %if %{sqlite}
1054 %post sqlite
1055 %endif
1056 %if %{postgresql}
1057 %post postgresql
1058 %endif
1059 %if ! %{client_only}
1060 # add our links
1061 if [ "$1" -ge 1 ] ; then
1062 %if %{suse} && %{mysql}
1063   %{service_enable} mysql
1064 %endif
1065 %if %{suse} && %{postgresql}
1066   %{service_enable} postgresql
1067 %endif
1068   %{service_enable} bacula-dir
1069   %{service_enable} bacula-fd
1070   %{service_enable} bacula-sd
1071 fi
1072 %endif
1073
1074 if [ -d %{sysconf_dir} ]; then
1075    cd %{sysconf_dir}
1076    if [ ! -f .rpm.sed ]; then
1077        (umask 0177
1078         echo "# This file is used to ensure that all passwords will" > .rpm.sed
1079         echo "# match between configuration files"                  >> .rpm.sed
1080        )
1081        for string in XXX_REPLACE_WITH_DIRECTOR_PASSWORD_XXX XXX_REPLACE_WITH_CLIENT_PASSWORD_XXX XXX_REPLACE_WITH_STORAGE_PASSWORD_XXX XXX_REPLACE_WITH_DIRECTOR_MONITOR_PASSWORD_XXX XXX_REPLACE_WITH_CLIENT_MONITOR_PASSWORD_XXX XXX_REPLACE_WITH_STORAGE_MONITOR_PASSWORD_XXX; do
1082            pass=`openssl rand -base64 33`
1083            echo "s@${string}@${pass}@g" >> .rpm.sed
1084        done
1085    fi
1086    host=`hostname -s`
1087    if [ "$host" = "" ]; then
1088        host=localhost
1089    fi
1090    for file in *.conf; do
1091       sed -f .rpm.sed $file > $file.new
1092       sed "s@XXX_HOSTNAME_XXX@${host}@g" $file.new > $file
1093       rm -f $file.new
1094    done
1095 fi
1096
1097
1098 %if %{mysql}
1099
1100 #check, if mysql can be called successfully at all
1101 if mysql 2>/dev/null bacula -e 'select * from Version;' ; then
1102
1103   # test for an existing database
1104   # note: this ASSUMES no password has been set for bacula database
1105   DB_VER=`mysql 2>/dev/null bacula -e 'select * from Version;'|tail -n 1`
1106
1107   # grant privileges and create tables if they do not exist
1108   if [ -z "$DB_VER" ]; then
1109       echo "Hmm, it doesn't look like you have an existing database."
1110       echo "Granting privileges for MySQL user bacula..."
1111       %{script_dir}/grant_mysql_privileges
1112       echo "Creating MySQL bacula database..."
1113       %{script_dir}/create_mysql_database
1114       echo "Creating bacula tables..."
1115       %{script_dir}/make_mysql_tables
1116
1117   elif [ "$DB_VER" -ge "12" -a "$DB_VER" -lt "1015" ]; then
1118       echo "This release requires an upgrade to your bacula database."
1119       echo "Backing up your current database..."
1120       mysqldump -f --opt bacula | bzip2 > %{working_dir}/bacula_backup.sql.bz2
1121       echo "Upgrading bacula database ..."
1122       %{script_dir}/update_mysql_tables
1123       echo "If bacula works correctly you can remove the backup file %{working_dir}/bacula_backup.sql.bz2"
1124
1125   fi
1126 fi
1127 %endif
1128
1129 %if %{sqlite}
1130 # test for an existing database
1131 if [ -s %{working_dir}/bacula.db ]; then
1132         DB_VER=`echo "select * from Version;" | %{sqlite_bindir}/sqlite3 2>/dev/null %{working_dir}/bacula.db | tail -n 1`
1133         # check to see if we need to upgrade a 3.x database
1134         if [ "$DB_VER" -le "13" ] && [ "$DB_VER" -ge "12" ]; then
1135                 echo "This release requires an upgrade to your bacula database."
1136                 echo "Backing up your current database..."
1137                 echo ".dump" | %{sqlite_bindir}/sqlite3 %{working_dir}/bacula.db | bzip2 > %{working_dir}/bacula_backup.sql.bz2
1138                 echo "Upgrading bacula database ..."
1139                 %{script_dir}/update_sqlite3_tables
1140                 echo "If bacula works correctly you can remove the backup file %{working_dir}/bacula_backup.sql.bz2"
1141         fi
1142 else
1143         # create the database and tables
1144         echo "Hmm, doesn't look like you have an existing database."
1145         echo "Creating SQLite database..."
1146         %{script_dir}/create_sqlite3_database
1147         echo "Creating the SQLite tables..."
1148         %{script_dir}/make_sqlite3_tables
1149         chown %{director_daemon_user}.%{daemon_group} %{working_dir}/bacula.db
1150 fi
1151 %endif
1152
1153 %if %{postgresql}
1154 # check if psql can be called successfully at all
1155 if echo 'select * from Version;' | su - postgres -c 'psql bacula' 2>/dev/null; then
1156
1157   # test for an existing database
1158   # note: this ASSUMES no password has been set for bacula database
1159   DB_VER=`echo 'SELECT * FROM Version LIMIT 1;' | su - postgres -c 'psql bacula' 2>/dev/null | tail -3 | head -1`
1160
1161   # grant privileges and create tables if they do not exist
1162   if [ -z "$DB_VER" ]; then
1163       echo "Hmm, doesn't look like you have an existing database."
1164       echo "Creating PostgreSQL bacula database..."
1165       su - postgres -c %{script_dir}/create_postgresql_database
1166       echo "Creating bacula tables..."
1167       su - postgres -c %{script_dir}/make_postgresql_tables
1168       echo "Granting privileges for PostgreSQL user bacula..."
1169       su - postgres -c %{script_dir}/grant_postgresql_privileges
1170
1171   elif [ "$DB_VER" -ge "12" -a "$DB_VER" -lt "1015" ]; then
1172       echo "This release requires an upgrade to your bacula database."
1173       echo "Backing up your current database..."
1174       su - postgres -c 'pg_dump bacula' | bzip2 > %{working_dir}/bacula_backup.sql.bz2
1175       echo "Upgrading bacula database ..."
1176       su - postgres -c %{script_dir}/update_postgresql_tables
1177       echo "If bacula works correctly you can remove the backup file %{working_dir}/bacula_backup.sql.bz2"
1178       echo "Granting privileges for PostgreSQL user bacula..."
1179       su - postgres -c %{script_dir}/grant_postgresql_privileges
1180
1181   fi
1182 fi
1183 %endif
1184
1185 %if ! %{client_only}
1186 if [ -d %{sysconf_dir} ]; then
1187    cd %{sysconf_dir}
1188    if [ ! -f .rpm.sed ]; then
1189        (umask 0177
1190         echo "# This file is used to ensure that all passwords will" > .rpm.sed
1191         echo "# match between configuration files"                  >> .rpm.sed
1192        )
1193        for string in XXX_REPLACE_WITH_DIRECTOR_PASSWORD_XXX XXX_REPLACE_WITH_CLIENT_PASSWORD_XXX XXX_REPLACE_WITH_STORAGE_PASSWORD_XXX XXX_REPLACE_WITH_DIRECTOR_MONITOR_PASSWORD_XXX XXX_REPLACE_WITH_CLIENT_MONITOR_PASSWORD_XXX XXX_REPLACE_WITH_STORAGE_MONITOR_PASSWORD_XXX; do
1194            pass=`openssl rand -base64 33`
1195            echo "s@${string}@${pass}@g" >> .rpm.sed
1196        done
1197    fi
1198    host=`hostname -s`
1199    if [ "$host" = "" ]; then
1200        host=localhost
1201    fi
1202    for file in *.conf; do
1203       sed -f .rpm.sed $file > $file.new
1204       sed "s@XXX_HOSTNAME_XXX@${host}@g" $file.new > $file
1205       rm -f $file.new
1206    done
1207 fi
1208 %endif
1209
1210
1211 %if %{mysql}
1212 %preun mysql
1213 %endif
1214 %if %{sqlite}
1215 %preun sqlite
1216 %endif
1217 %if %{postgresql}
1218 %preun postgresql
1219 %endif
1220
1221 %if ! %{client_only}
1222 # delete our links
1223 if [ $1 = 0 ]; then
1224   %{service_disable} bacula-dir
1225   %{service_disable} bacula-fd
1226   %{service_disable} bacula-sd
1227 fi
1228 %endif
1229
1230 %files client
1231 %defattr(-,root,root)
1232 %attr(-, root, %{daemon_group}) %dir %{script_dir}
1233 %attr(-, root, %{daemon_group}) %dir %{plugin_dir}
1234 %attr(-, root, %{daemon_group}) %dir %{sysconf_dir}
1235
1236 # SD/DIR might write here
1237 %attr(-, %{storage_daemon_user}, %{daemon_group}) %dir %{log_dir}
1238
1239 %if %{usesystemd}
1240 %attr(-, root, %{daemon_group})  %{systemd_dir}/bacula-fd.service
1241 %else
1242 %{script_dir}/bacula-ctl-fd
1243 /etc/init.d/bacula-fd
1244 %endif
1245
1246 /etc/logrotate.d/bacula
1247
1248 %attr(-, root, %{daemon_group}) %config(noreplace) %{sysconf_dir}/bacula-fd.conf
1249 %attr(-, root, %{daemon_group}) %config(noreplace) %{sysconf_dir}/bconsole.conf
1250 %attr(-, root, %{daemon_group}) %dir %{working_dir}
1251
1252 %{_sbindir}/bacula-fd
1253 %{_sbindir}/btraceback
1254 %attr(-, root, %{daemon_group}) %{script_dir}/btraceback.gdb
1255 %attr(-, root, %{daemon_group}) %{script_dir}/btraceback.dbx
1256 %attr(-, root, %{daemon_group}) %{script_dir}/btraceback.mdb
1257 %attr(-, root, %{daemon_group}) %{plugin_dir}/bpipe-fd.so
1258 %{_sbindir}/bconsole
1259 %{_mandir}/man8/bacula-fd.8.%{manpage_ext}
1260 %{_mandir}/man8/bacula.8.%{manpage_ext}
1261 %{_mandir}/man8/bconsole.8.%{manpage_ext}
1262 %{_mandir}/man8/btraceback.8.%{manpage_ext}
1263 %{_mandir}/man1/bat.1.%{manpage_ext}
1264 %_prefix/share/doc/*
1265
1266 %pre client
1267 # create the daemon group and user
1268 HAVE_BACULA=`grep %{daemon_group} %{group_file} 2>/dev/null`
1269 if [ -z "$HAVE_BACULA" ]; then
1270     %{groupadd} -r %{daemon_group} > /dev/null 2>&1
1271     echo "The group %{daemon_group} has been added to %{group_file}."
1272     echo "See the manual chapter \"Running Bacula\" for details."
1273 fi
1274 # we do not use the -g option allowing the primary group to be set to system default
1275 # this will be a unique group on redhat type systems or the group users on some systems
1276 HAVE_BACULA=`grep %{file_daemon_user} %{user_file} 2>/dev/null`
1277 if [ -z "$HAVE_BACULA" ]; then
1278     %{useradd} -r -c "Bacula" -d %{working_dir} -g %{daemon_group} -M -s /sbin/nologin %{file_daemon_user} > /dev/null 2>&1
1279     echo "The user %{file_daemon_user} has been added to %{user_file}."
1280     echo "See the manual chapter \"Running Bacula\" for details."
1281 fi
1282 # now we add the supplementary group, this is ok to call even if the user already exists
1283 # we only do this if the user is NOT root
1284 IS_ROOT=%{file_daemon_user}
1285 if [ "$IS_ROOT" != "root" ]; then
1286 %{usermod} -G %{daemon_group} %{file_daemon_user}
1287 fi
1288
1289 %post client
1290 # add our link
1291 if [ "$1" -ge 1 ] ; then
1292    %{service_enable} bacula-fd
1293 fi
1294
1295 if [ -d %{sysconf_dir} ]; then
1296    cd %{sysconf_dir}
1297    if [ ! -f .rpm.sed ]; then
1298        (umask 0177
1299         echo "# This file is used to ensure that all passwords will" > .rpm.sed
1300         echo "# match between configuration files"                  >> .rpm.sed
1301        )
1302        for string in XXX_REPLACE_WITH_DIRECTOR_PASSWORD_XXX XXX_REPLACE_WITH_CLIENT_PASSWORD_XXX XXX_REPLACE_WITH_STORAGE_PASSWORD_XXX XXX_REPLACE_WITH_DIRECTOR_MONITOR_PASSWORD_XXX XXX_REPLACE_WITH_CLIENT_MONITOR_PASSWORD_XXX XXX_REPLACE_WITH_STORAGE_MONITOR_PASSWORD_XXX; do
1303            pass=`openssl rand -base64 33`
1304            echo "s@${string}@${pass}@g" >> .rpm.sed
1305        done
1306    fi
1307    host=`hostname -s`
1308    if [ "$host" = "" ]; then
1309        host=localhost
1310    fi
1311    for file in *.conf; do
1312       sed -f .rpm.sed $file > $file.new
1313       sed "s@XXX_HOSTNAME_XXX@${host}@g" $file.new > $file
1314       rm -f $file.new
1315    done
1316 fi
1317
1318 %preun client
1319 # delete our link
1320 if [ $1 = 0 ]; then
1321    %{service_disable} bacula-fd
1322 fi
1323
1324 %files libs
1325 %defattr(-,root,root)
1326 %{_libdir}/libbac-*
1327 %{_libdir}/libbac.*
1328 %{_libdir}/libbaccfg*
1329 %{_libdir}/libbacfind*
1330
1331 %post libs
1332 /sbin/ldconfig
1333 exit 0
1334
1335 %postun libs
1336 /sbin/ldconfig
1337 exit 0
1338
1339 %if ! %{client_only}
1340 %files updatedb
1341 %defattr(-,root,%{daemon_group})
1342 %{script_dir}/updatedb/*
1343
1344 %pre updatedb
1345 # create the daemon group
1346 HAVE_BACULA=`grep %{daemon_group} %{group_file} 2>/dev/null`
1347 if [ -z "$HAVE_BACULA" ]; then
1348     %{groupadd} -r %{daemon_group} > /dev/null 2>&1
1349     echo "The group %{daemon_group} has been added to %{group_file}."
1350     echo "See the manual chapter \"Running Bacula\" for details."
1351 fi
1352
1353 %post updatedb
1354 echo "The database update scripts were installed to %{script_dir}/updatedb"
1355 %endif
1356
1357 %changelog