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