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