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