Blob Blame History Raw
%global username bacula

Summary:        Cross platform network backup for Linux, Unix, Mac and Windows
Name:           bacula
Version:        2.4.4
Release:        10%{?dist}
License:        GPL
Group:          System Environment/Daemons
URL:            http://www.%{name}.org
BuildRoot:      %(mktemp -ud %{_tmppath}/%{name}-%{version}-%{release}-XXXXXX)

Source0:        http://download.sourceforge.net/%{name}/%{name}-%{version}.tar.gz
Source3:        %{name}-gconsole.desktop
Source4:        %{name}-wxconsole.desktop
Source5:        %{name}-traymonitor.desktop
Source6:        %{name}.logrotate
Source7:        %{name}-fd.init
Source8:        %{name}-dir.init
Source9:        %{name}-sd.init

Patch0:         %{name}-2.4.4-director-configuration.patch
Patch1:         %{name}-2.4.4-config.patch
Patch2:         %{name}-2.4.4-fix-logwatch.patch
Patch3:         %{name}-2.4.4-pamd.patch
Patch4:         %{name}-2.4.4-make_catalog_backup.patch
Patch5:         %{name}-2.4.4-gtk-labels.patch

BuildRequires:  atk-devel
BuildRequires:  bonobo-activation-devel
BuildRequires:  desktop-file-utils
BuildRequires:  freetype-devel
BuildRequires:  GConf2-devel
BuildRequires:  glibc-devel
BuildRequires:  gtk2-devel
BuildRequires:  libacl-devel
BuildRequires:  libart_lgpl-devel
BuildRequires:  libbonobo-devel
BuildRequires:  libbonoboui-devel
BuildRequires:  libgnomeui-devel
BuildRequires:  libstdc++-devel
BuildRequires:  libtermcap-devel
BuildRequires:  libxml2-devel
BuildRequires:  mysql-devel
BuildRequires:  ncurses-devel
BuildRequires:  openssl-devel
BuildRequires:  ORBit2-devel
BuildRequires:  pango-devel
BuildRequires:  perl
BuildRequires:  pkgconfig
BuildRequires:  postgresql-devel
BuildRequires:  python-devel
BuildRequires:  sed
BuildRequires:  sqlite-devel
BuildRequires:  tcp_wrappers
BuildRequires:  wxGTK-devel
BuildRequires:  zlib-devel

%description
Bacula is a set of programs that allow you to manage the backup, recovery, and
verification of computer data across a network of different computers. It is
based on a client/server architecture and is efficient and relatively easy to
use, while offering many advanced storage management features that make it easy
to find and recover lost or damaged files.


%package        director-mysql
Summary:        Bacula Director with MySQL database support
Group:          System Environment/Daemons
Provides:       %{name}-director = %{version}-%{release}
Requires:       %{name}-director-common = %{version}-%{release}
Requires:       %{name}-common = %{version}-%{release}
Requires:       mysql-server
Conflicts:      director-sqlite, director-postgresql

%description    director-mysql
Bacula is a set of programs that allow you to manage the backup, recovery, and
verification of computer data across a network of different computers. It is
based on a client/server architecture.

This package contains the %{name} director, the server which controls your
backup run. This director has support for the MySQL database.


%package        director-sqlite
Summary:        Bacula Director with SQLite database support
Group:          System Environment/Daemons
Provides:       %{name}-director = %{version}-%{release}
Requires:       %{name}-director-common = %{version}-%{release}
Requires:       %{name}-common = %{version}-%{release}
Conflicts:      director-mysql, director-postgresql

%description director-sqlite
Bacula is a set of programs that allow you to manage the backup, recovery, and
verification of computer data across a network of different computers. It is
based on a client/server architecture.

This package contains the %{name} director, the server which controls your
backup run. This director has support for the SQLite database.


%package        director-postgresql
Summary:        Bacula Director with PostgresSQL database support
Group:          System Environment/Daemons
Provides:       %{name}-director = %{version}-%{release}
Requires:       %{name}-director-common = %{version}-%{release}
Requires:       %{name}-common = %{version}-%{release}
Requires:       postgresql-server
Conflicts:      director-mysql, director-sqlite

%description    director-postgresql
Bacula is a set of programs that allow you to manage the backup, recovery, and
verification of computer data across a network of different computers. It is
based on a client/server architecture.

This package contains the %{name} director, the server which controls your
backup run. This director has support for the PostgresSQL database.


%package        director-common
Summary:        Common Bacula Director files
Group:          System Environment/Daemons
Requires:       %{name}-director = %{version}-%{release}
Requires:       %{name}-common = %{version}-%{release}

%description director-common
Bacula is a set of programs that allow you to manage the backup, recovery, and
verification of computer data across a network of different computers. It is
based on a client/server architecture.

This package contains the common director files, which are shared between all
database backends. You have to select a possible database backend though, which
provides the needed %{name}-director dependency. Please choose from
%{name}-director-mysql, %{name}-director-sqlite or %{name}-director-postgresql.


%package        client
Summary:        Bacula backup client
Group:          System Environment/Daemons
Requires:       %{name}-common = %{version}-%{release}
Requires(post):         /sbin/chkconfig
Requires(preun):        /sbin/chkconfig
Requires(preun):        /sbin/service
Requires(postun):       /sbin/service

%description    client
Bacula is a set of programs that allow you to manage the backup, recovery, and
verification of computer data across a network of different computers. It is
based on a client/server architecture.

This package contains the %{name} client, the daemon running on the system to be
backed up.


%package        storage-common
Summary:        Common Bacula storage daemon files
Group:          System Environment/Daemons
Requires:       %{name}-storage = %{version}-%{release}
Requires:       %{name}-common = %{version}-%{release}

%description    storage-common
Bacula is a set of programs that allow you to manage the backup, recovery, and
verification of computer data across a network of different computers. It is
based on a client/server architecture.

This package contains the storage daemon, the daemon responsible for writing
the data received from the clients onto tape drives or other mass storage
devices. You have to select a possible storage backend though, which
provides the needed %{name}-storage dependency. Please choose from
%{name}-storage-mysql, %{name}-storage-sqlite or %{name}-storage-postgresql.


%package        storage-mysql
Summary:        MySQL Bacula storage daemon files
Group:          System Environment/Daemons
Provides:       %{name}-storage = %{version}-%{release}
Requires:       %{name}-storage-common = %{version}-%{release}
Requires:       %{name}-common = %{version}-%{release}
Requires:       mysql-server
Conflicts:      storage-sqlite, storage-postgresql

%description    storage-mysql
Bacula is a set of programs that allow you to manage the backup, recovery, and
verification of computer data across a network of different computers. It is
based on a client/server architecture.

This package contains the storage daemon, the daemon responsible for writing
the data received from the clients onto tape drives or other mass storage
devices. This storage has support for the MySQL database.


%package        storage-sqlite
Summary:        SQLite Bacula storage daemon files
Group:          System Environment/Daemons
Provides:       %{name}-storage = %{version}-%{release}
Requires:       %{name}-storage-common = %{version}-%{release}
Requires:       %{name}-common = %{version}-%{release}
Conflicts:      storage-mysql, storage-postgresql

%description    storage-sqlite
Bacula is a set of programs that allow you to manage the backup, recovery, and
verification of computer data across a network of different computers. It is
based on a client/server architecture.

This package contains the storage daemon, the daemon responsible for writing
the data received from the clients onto tape drives or other mass storage
devices. This storage has support for the SQLite database.


%package        storage-postgresql
Summary:        PostgresSQL Bacula storage daemon files
Group:          System Environment/Daemons
Provides:       %{name}-storage = %{version}-%{release}
Requires:       %{name}-storage-common = %{version}-%{release}
Requires:       %{name}-common = %{version}-%{release}
Requires:       postgresql-server
Conflicts:      storage-mysql, storage-sqlite

%description    storage-postgresql
Bacula is a set of programs that allow you to manage the backup, recovery, and
verification of computer data across a network of different computers. It is
based on a client/server architecture.

This package contains the storage daemon, the daemon responsible for writing
the data received from the clients onto tape drives or other mass storage
devices. This storage has support for the PostgresSQL database.


%package        common
Summary:        Common Bacula utilities
Group:          System Environment/Daemons
Requires(pre):          shadow-utils
Requires(postun):       shadow-utils

%description    common
Bacula is a set of programs that allow you to manage the backup, recovery, and
verification of computer data across a network of different computers. It is
based on a client/server architecture.


%package        console
Summary:        Bacula management console
Group:          System Environment/Daemons

%description    console
Bacula is a set of programs that allow you to manage the backup, recovery, and
verification of computer data across a network of different computers. It is
based on a client/server architecture.

This package contains the command-line management console for the %{name}
backup system.


%package        console-gnome
Summary:        Bacula console for the Gnome desktop environment
Group:          System Environment/Daemons
Requires:       usermode

%description    console-gnome
Bacula is a set of programs that allow you to manage the backup, recovery, and
verification of computer data across a network of different computers. It is
based on a client/server architecture.

This package contains the gnome version of the %{name} management console.


%package        console-wxwidgets
Summary:        Bacula console using the wx widgets toolkit
Group:          System Environment/Daemons
Requires:       usermode

%description    console-wxwidgets
Bacula is a set of programs that allow you to manage the backup, recovery, and
verification of computer data across a network of different computers. It is
based on a client/server architecture.

This package contains the wxWidgets version of the %{name} management console.


%package        traymonitor
Summary:        Bacula monitor for the Gnome and KDE system tray
Group:          System Environment/Daemons

%description    traymonitor
Bacula is a set of programs that allow you to manage the backup, recovery, and
verification of computer data across a network of different computers. It is
based on a client/server architecture.

This package contains the Gnome and KDE compatible tray monitor to monitor your
%{name} server.


%package        devel
Summary:        Bacula development files
Group:          Development/Libraries

%description    devel
Bacula is a set of programs that allow you to manage the backup, recovery, and
verification of computer data across a network of different computers. It is
based on a client/server architecture.

This development package contains static libraries and header files.


%prep
%setup -q -c -n %{name}-%{version}

# Patching and other source preparation
pushd %{name}-%{version}
%patch0 -p1 -b .director-configuration
%patch1 -p1 -b .config
%patch2 -p1 -b .fix-logwatch
%patch3 -p1 -b .pamd
%patch4 -p1 -b .make_catalog_backup
%patch5 -p1 -b .gtk-labels

# Remove execution permissions from files we're packaging as docs later on
find updatedb -type f | xargs chmod -x
popd

# Remove cvs left-overs
find -name '.cvsignore' | xargs rm -f

# Fix perms of c files to silent rpmlint
find -type f -name '*.c' | xargs chmod -x
find -type f -name '*.h' | xargs chmod -x

# We are building the source several times, each with a different storage backend
mkdir %{name}-mysql %{name}-postgresql %{name}-sqlite


%build
# Shell function to configure and build a Bacula tree
build() {
cp -rl ../%{name}-%{version}/* .
%configure \
        --sysconfdir=%{_sysconfdir}/%{name} \
        --with-dir-user=%{name} \
        --with-dir-group=%{name} \
        --with-sd-user=%{name} \
        --with-sd-group=%{name} \
        --with-fd-user=root \
        --with-fd-group=root \
        --with-dir-password=@@DIR_PASSWORD@@ \
        --with-fd-password=@@FD_PASSWORD@@ \
        --with-sd-password=@@SD_PASSWORD@@ \
        --with-mon-dir-password=@@MON_DIR_PASSWORD@@ \
        --with-mon-fd-password=@@MON_FD_PASSWORD@@ \
        --with-mon-sd-password=@@MON_SD_PASSWORD@@ \
        --with-working-dir=%{_localstatedir}/spool/%{name} \
        --with-scriptdir=%{_libexecdir}/%{name} \
        --with-smtp-host=localhost \
        --with-subsys-dir=%{_localstatedir}/lock/subsys \
        --with-pid-dir=%{_localstatedir}/run \
        --enable-conio \
        --enable-largefile \
        --enable-gnome \
        --enable-bwx-console \
        --enable-tray-monitor \
        --enable-build-dird \
        --enable-build-stored \
        --with-openssl \
        --with-tcp-wrappers \
        --with-python \
        --enable-smartalloc \
        --with-x \
        $*

if test $? != 0; then
  tail -500 config.log
  : configure failed
  exit 1
fi

%{__make} %{?_smp_mflags}

}

# Build sqlite director
pushd %{name}-sqlite
        build --with-sqlite3
popd

# Build MySQL director
pushd %{name}-mysql
        build --with-mysql
popd

# Build PostgreSQL director
pushd %{name}-postgresql
        build --with-postgresql
popd


%install
rm -rf %{buildroot}

pushd %{name}-sqlite
        make install DESTDIR=%{buildroot}
        mv %{buildroot}%{_sbindir}/%{name}-dir  %{buildroot}%{_sbindir}/%{name}-dir.sqlite
        mv %{buildroot}%{_sbindir}/dbcheck  %{buildroot}%{_sbindir}/dbcheck.sqlite
        mv %{buildroot}%{_sbindir}/bcopy  %{buildroot}%{_sbindir}/bcopy.sqlite
        mv %{buildroot}%{_sbindir}/bscan  %{buildroot}%{_sbindir}/bscan.sqlite

        for script in create_%{name}_database drop_%{name}_database drop_%{name}_tables \
                        grant_%{name}_privileges make_%{name}_tables \
                        update_%{name}_tables; do
                mv %{buildroot}%{_libexecdir}/%{name}/${script} %{buildroot}%{_libexecdir}/%{name}/${script}.sqlite
        done
popd

pushd %{name}-mysql
        make install DESTDIR=%{buildroot}
        mv %{buildroot}%{_sbindir}/%{name}-dir  %{buildroot}%{_sbindir}/%{name}-dir.mysql
        mv %{buildroot}%{_sbindir}/dbcheck  %{buildroot}%{_sbindir}/dbcheck.mysql
        mv %{buildroot}%{_sbindir}/bcopy  %{buildroot}%{_sbindir}/bcopy.mysql
        mv %{buildroot}%{_sbindir}/bscan  %{buildroot}%{_sbindir}/bscan.mysql

        for script in create_%{name}_database drop_%{name}_database drop_%{name}_tables \
                        grant_%{name}_privileges make_%{name}_tables \
                        update_%{name}_tables; do
                mv %{buildroot}%{_libexecdir}/%{name}/${script} %{buildroot}%{_libexecdir}/%{name}/${script}.mysql
        done
popd

pushd %{name}-postgresql
        make install DESTDIR=%{buildroot}
        mv %{buildroot}%{_sbindir}/%{name}-dir  %{buildroot}%{_sbindir}/%{name}-dir.postgresql
        mv %{buildroot}%{_sbindir}/dbcheck  %{buildroot}%{_sbindir}/dbcheck.postgresql
        mv %{buildroot}%{_sbindir}/bcopy  %{buildroot}%{_sbindir}/bcopy.postgresql
        mv %{buildroot}%{_sbindir}/bscan  %{buildroot}%{_sbindir}/bscan.postgresql

        for script in create_%{name}_database drop_%{name}_database drop_%{name}_tables \
                        grant_%{name}_privileges make_%{name}_tables \
                        update_%{name}_tables; do
                mv %{buildroot}%{_libexecdir}/%{name}/${script} %{buildroot}%{_libexecdir}/%{name}/${script}.postgresql
        done
popd

rm %{buildroot}%{_mandir}/man1/bat.1.gz

# Fix some wrapper braindeadness
rm -f %{buildroot}%{_libexecdir}/%{name}/bconsole
rm -f %{buildroot}%{_libexecdir}/%{name}/gconsole
mv %{buildroot}%{_sbindir}/bwx-console %{buildroot}%{_sbindir}/bwxconsole
mv %{buildroot}%{_sysconfdir}/%{name}/bwx-console.conf %{buildroot}%{_sysconfdir}/%{name}/bwxconsole.conf

# Desktop Integration for the console apps and the traymonitor
mkdir -p %{buildroot}%{_bindir}
install -m 644 -D %{name}-sqlite/scripts/%{name}.png %{buildroot}%{_datadir}/pixmaps/%{name}.png
install -m 644 -D %{name}-sqlite/scripts/bgnome-console.pamd %{buildroot}%{_sysconfdir}/pam.d/bgnome-console
install -m 644 -D %{name}-sqlite/scripts/bgnome-console.console_apps %{buildroot}%{_sysconfdir}/security/console.apps/bgnome-console
install -m 644 -D %{name}-sqlite/src/wx-console/wxwin16x16.xpm %{buildroot}%{_datadir}/pixmaps/wxwin16x16.xpm
install -m 644 -D %{name}-sqlite/scripts/wxconsole.pamd %{buildroot}%{_sysconfdir}/pam.d/wxconsole
install -m 644 -D %{name}-sqlite/scripts/wxconsole.desktop.consolehelper %{buildroot}%{_sysconfdir}/security/console.apps/bwxconsole
install -m 644 -D %{name}-sqlite/src/tray-monitor/generic.xpm %{buildroot}%{_datadir}/pixmaps/%{name}-tray-monitor.xpm

ln -sf consolehelper %{buildroot}%{_bindir}/bgnome-console
ln -sf consolehelper %{buildroot}%{_bindir}/bwxconsole

desktop-file-install --vendor="fedora" --dir=%{buildroot}%{_datadir}/applications %{SOURCE3}
desktop-file-install --vendor="fedora" --dir=%{buildroot}%{_datadir}/applications %{SOURCE4}
desktop-file-install --vendor="fedora" --dir=%{buildroot}%{_datadir}/applications %{SOURCE5}

# logrotate
mkdir -p %{buildroot}%{_localstatedir}/log/%{name}
install -m 644 -D %{SOURCE6} %{buildroot}%{_sysconfdir}/logrotate.d/%{name}

# And logwatch
install -m 755 -D %{name}-sqlite/scripts/logwatch/%{name} %{buildroot}%{_sysconfdir}/logwatch/scripts/services/%{name}
install -m 755 -D %{name}-sqlite/scripts/logwatch/applybaculadate %{buildroot}%{_sysconfdir}/logwatch/scripts/shared/applybaculadate
install -m 644 -D %{name}-sqlite/scripts/logwatch/logfile.%{name}.conf %{buildroot}%{_sysconfdir}/logwatch/conf/logfiles/%{name}.conf
install -m 644 -D %{name}-sqlite/scripts/logwatch/services.%{name}.conf %{buildroot}%{_sysconfdir}/logwatch/conf/services/%{name}.conf

# Initscripts
install -m 755 -D %{SOURCE7}  %{buildroot}%{_initrddir}/%{name}-fd
install -m 755 -D %{SOURCE8}  %{buildroot}%{_initrddir}/%{name}-dir
install -m 755 -D %{SOURCE9}  %{buildroot}%{_initrddir}/%{name}-sd

# Wipe backup files from the multiple make install calls
rm -vf %{buildroot}%{_sysconfdir}/%{name}/*.{new,old}
rm -vf %{buildroot}%{_libexecdir}/%{name}/*.{new,old}

# Create the spooling
mkdir -p %{buildroot}%{_localstatedir}/spool/%{name}

# Move some files around
mv %{buildroot}%{_libexecdir}/%{name}/query.sql %{buildroot}%{_sysconfdir}/%{name}/query.sql

# Nuke the scripts we do not need
rm -vf %{buildroot}%{_libexecdir}/%{name}/{%{name},%{name}-ctl-*,startmysql,stopmysql}

# Fix up some perms so rpmlint does not complain too much
chmod 755 %{buildroot}%{_sbindir}/*
chmod 755 %{buildroot}%{_libexecdir}/%{name}/*
chmod 644 %{buildroot}%{_libexecdir}/%{name}/btraceback.*

# Install headers
mkdir -p %{buildroot}%{_includedir}/bacula
for dir in src src/cats src/console src/dird src/filed src/findlib src/lib src/stored; do
        mkdir -p %{buildroot}%{_includedir}/bacula/$dir
        install -p -m 644 %{name}-%{version}/$dir/*.h %{buildroot}%{_includedir}/bacula/$dir
done


%clean
rm -rf %{buildroot}

%post director-mysql
replace_symlink() {
    alternatives_name=$1
    suffix=$2
    if [ -h $alternatives_name ]; then
        rm -f $alternatives_name
    fi
    cp $alternatives_name.$suffix $alternatives_name
}

replace_symlink /usr/sbin/%{name}-dir mysql
replace_symlink /usr/libexec/%{name}/create_%{name}_database mysql
replace_symlink /usr/libexec/%{name}/drop_%{name}_database mysql
replace_symlink /usr/libexec/%{name}/drop_%{name}_tables mysql
replace_symlink /usr/libexec/%{name}/grant_%{name}_privileges mysql
replace_symlink /usr/libexec/%{name}/make_%{name}_tables mysql
replace_symlink /usr/libexec/%{name}/update_%{name}_tables mysql


%post director-sqlite
replace_symlink() {
    alternatives_name=$1
    suffix=$2
    if [ -h $alternatives_name ]; then
        rm -f $alternatives_name
    fi
    cp $alternatives_name.$suffix $alternatives_name
}

replace_symlink /usr/sbin/%{name}-dir sqlite
replace_symlink /usr/libexec/%{name}/create_%{name}_database sqlite
replace_symlink /usr/libexec/%{name}/drop_%{name}_database sqlite
replace_symlink /usr/libexec/%{name}/drop_%{name}_tables sqlite
replace_symlink /usr/libexec/%{name}/grant_%{name}_privileges sqlite
replace_symlink /usr/libexec/%{name}/make_%{name}_tables sqlite
replace_symlink /usr/libexec/%{name}/update_%{name}_tables sqlite


%post director-postgresql
replace_symlink() {
    alternatives_name=$1
    suffix=$2
    if [ -h $alternatives_name ]; then
        rm -f $alternatives_name
    fi
    cp $alternatives_name.$suffix $alternatives_name
}
replace_symlink /usr/sbin/%{name}-dir postgresql
replace_symlink /usr/libexec/%{name}/create_%{name}_database postgresql
replace_symlink /usr/libexec/%{name}/drop_%{name}_database postgresql
replace_symlink /usr/libexec/%{name}/drop_%{name}_tables postgresql
replace_symlink /usr/libexec/%{name}/grant_%{name}_privileges postgresql
replace_symlink /usr/libexec/%{name}/make_%{name}_tables postgresql
replace_symlink /usr/libexec/%{name}/update_%{name}_tables postgresql


%preun director-mysql
REMAINING_ITEMS=$1
remove_fake_alternative() {
    filename=$1
    suffix=$2
        if [ ! -h $filename ]; then
        if [ $REMAINING_ITEMS -eq 0 ]; then
                rm -f $filename
            fi
        fi
}

remove_all_fake_dir_alternatives() {
    suffix=$1
    remove_fake_alternative /usr/sbin/%{name}-dir $suffix
    remove_fake_alternative /usr/sbin/dbcheck %{name}-dbcheck $suffix
    remove_fake_alternative /usr/libexec/%{name}/create_%{name}_database $suffix
    remove_fake_alternative /usr/libexec/%{name}/drop_%{name}_database $suffix
    remove_fake_alternative /usr/libexec/%{name}/drop_%{name}_tables $suffix
    remove_fake_alternative /usr/libexec/%{name}/grant_%{name}_privileges $suffix
    remove_fake_alternative /usr/libexec/%{name}/make_%{name}_tables $suffix
    remove_fake_alternative /usr/libexec/%{name}/update_%{name}_tables $suffix
}
remove_all_fake_dir_alternatives mysql

# As proposed on epel-devel, we will not re-enable alternatives in EPEL-5
%preun director-sqlite
REMAINING_ITEMS=$1
remove_fake_alternative() {
    filename=$1
    suffix=$2
    if [ ! -h $filename ]; then
        if [ $REMAINING_ITEMS -eq 0 ]; then
            rm -f $filename
        fi
    fi
}

remove_all_fake_dir_alternatives() {
    suffix=$1
    remove_fake_alternative /usr/sbin/%{name}-dir $suffix
    remove_fake_alternative /usr/sbin/dbcheck %{name}-dbcheck $suffix
    remove_fake_alternative /usr/libexec/%{name}/create_%{name}_database $suffix
    remove_fake_alternative /usr/libexec/%{name}/drop_%{name}_database $suffix
    remove_fake_alternative /usr/libexec/%{name}/drop_%{name}_tables $suffix
    remove_fake_alternative /usr/libexec/%{name}/grant_%{name}_privileges $suffix
    remove_fake_alternative /usr/libexec/%{name}/make_%{name}_tables $suffix
    remove_fake_alternative /usr/libexec/%{name}/update_%{name}_tables $suffix
}
remove_all_fake_dir_alternatives sqlite

# As proposed on epel-devel, we will not re-enable alternatives in EPEL-5
%preun director-postgresql
REMAINING_ITEMS=$1
remove_fake_alternative() {
    filename=$1
    suffix=$2
    if [ ! -h $filename ]; then
        if [ $REMAINING_ITEMS -eq 0 ]; then
            rm -f $filename
        fi
    fi
}

remove_all_fake_dir_alternatives() {
    suffix=$1
    remove_fake_alternative /usr/sbin/%{name}-dir $suffix
    remove_fake_alternative /usr/sbin/dbcheck %{name}-dbcheck $suffix
    remove_fake_alternative /usr/libexec/%{name}/create_%{name}_database $suffix
    remove_fake_alternative /usr/libexec/%{name}/drop_%{name}_database $suffix
    remove_fake_alternative /usr/libexec/%{name}/drop_%{name}_tables $suffix
    remove_fake_alternative /usr/libexec/%{name}/grant_%{name}_privileges $suffix
    remove_fake_alternative /usr/libexec/%{name}/make_%{name}_tables $suffix
    remove_fake_alternative /usr/libexec/%{name}/update_%{name}_tables $suffix
}
remove_all_fake_dir_alternatives postgresql

%pre common
getent group %username >/dev/null || groupadd -g %uid -r %username &>/dev/null || :
getent passwd %username >/dev/null || useradd -u %uid -r -s /sbin/nologin \
    -d /var/spool/bacula -M -c 'Bacula Backup System' -g %username %username &>/dev/null || :
exit 0


%postun common
test "$1" != 0 || userdel %username &>/dev/null || :
test "$1" != 0 || groupdel %username &>/dev/null || :
exit 0


%post storage-mysql
replace_symlink() {
    alternatives_name=$1
    suffix=$2
    if [ -h $alternatives_name ]; then
        rm -f $alternatives_name
    fi
    cp $alternatives_name.$suffix $alternatives_name
}
replace_symlink /usr/sbin/bcopy mysql
if [ -h /usr/sbin/dbcheck ]; then
    rm -f /usr/sbin/dbcheck
fi
cp /usr/sbin/bscan.mysql /usr/sbin/dbcheck

%post storage-sqlite
replace_symlink() {
    alternatives_name=$1
    suffix=$2
    if [ -h $alternatives_name ]; then
        rm -f $alternatives_name
    fi
    cp $alternatives_name.$suffix $alternatives_name
}
replace_symlink /usr/sbin/bcopy sqlite
if [ -h /usr/sbin/dbcheck ]; then
    rm -f /usr/sbin/dbcheck
fi
cp /usr/sbin/bscan.sqlite /usr/sbin/dbcheck


%post storage-postgresql
replace_symlink() {
    alternatives_name=$1
    suffix=$2
    if [ -h $alternatives_name ]; then
        rm -f $alternatives_name
    fi
    cp $alternatives_name.$suffix $alternatives_name
}
replace_symlink /usr/sbin/bcopy postgresql
if [ -h /usr/sbin/dbcheck ]; then
    rm -f /usr/sbin/dbcheck
fi
cp /usr/sbin/bscan.postgresql /usr/sbin/dbcheck


%preun storage-mysql
REMAINING_ITEMS=$1
remove_fake_alternative() {
    filename=$1
    suffix=$2
    if [ ! -h $filename ]; then
        if [ $REMAINING_ITEMS -eq 0 ]; then
            rm -f $filename
        fi
    fi
}

remove_fake_alternative /usr/sbin/bcopy mysql
remove_fake_alternative /usr/sbin/dbcheck mysql

# As proposed on epel-devel, we will not re-enable alternatives in EPEL-5
%preun storage-sqlite
REMAINING_ITEMS=$1
remove_fake_alternative() {
    filename=$1
    suffix=$2
    if [ ! -h $filename ]; then
        if [ $REMAINING_ITEMS -eq 0 ]; then
            rm -f $filename
        fi
    fi
}
remove_fake_alternative /usr/sbin/bcopy sqlite
remove_fake_alternative /usr/sbin/dbcheck sqlite

# As proposed on epel-devel, we will not re-enable alternatives in EPEL-5
%preun storage-postgresql
REMAINING_ITEMS=$1
remove_fake_alternative() {
    filename=$1
    suffix=$2
    if [ ! -h $filename ]; then
        if [ $REMAINING_ITEMS -eq 0 ]; then
            rm -f $filename
        fi
    fi
}
remove_fake_alternative /usr/sbin/bcopy postgresql
remove_fake_alternative /usr/sbin/dbcheck postgresql

%post client
/sbin/chkconfig --add %{name}-fd


%preun client
if [ $1 = 0 ]; then
        /sbin/service %{name}-fd stop >/dev/null 2>&1 || :
        /sbin/chkconfig --del %{name}-fd
fi


%postun client
if [ "$1" -ge "1" ]; then
        /sbin/service %{name}-fd condrestart >/dev/null 2>&1 || :
fi


%post director-common
/sbin/chkconfig --add %{name}-dir
# Replace bash script with perl one in config file(rhbz#456612)
# grep -q "make_catalog_backup.pl" /etc/bacula-dir.conf
# if [ ! $? -eq 0 ]; then
#     CATALOG=$(cat /etc/bacula-dir.conf | grep -A1 "^Catalog" | grep Name | awk '{print $3}')
#     sed -i -e "s|/usr/libexec/bacula/make_catalog_backup.*|/usr/libexec/bacula/make_catalog_backup.pl $CATALOG\"|g" \
#          /etc/bacula-dir.conf
# fi


%preun director-common
if [ $1 = 0 ]; then
        /sbin/service %{name}-dir stop >/dev/null 2>&1 || :
        /sbin/chkconfig --del %{name}-dir
fi


%postun director-common
if [ "$1" -ge "1" ]; then
        /sbin/service %{name}-dir condrestart >/dev/null 2>&1 || :
fi


%post storage-common
/sbin/chkconfig --add %{name}-sd


%preun storage-common
if [ $1 = 0 ]; then
        /sbin/service %{name}-sd stop >/dev/null 2>&1 || :
        /sbin/chkconfig --del %{name}-sd
fi


%postun storage-common
if [ "$1" -ge "1" ]; then
        /sbin/service %{name}-sd condrestart >/dev/null 2>&1 || :
fi


%files common
%defattr(-,root,root,-)
%doc %{name}-%{version}/AUTHORS %{name}-%{version}/ChangeLog %{name}-%{version}/COPYING %{name}-%{version}/LICENSE
%doc %{name}-%{version}/README %{name}-%{version}/SUPPORT %{name}-%{version}/VERIFYING
%config(noreplace) %{_sysconfdir}/logrotate.d/%{name}
%dir %{_sysconfdir}/%{name}
%dir %{_libexecdir}/%{name}
%{_sbindir}/bsmtp
%{_sbindir}/btraceback
%{_libexecdir}/%{name}/btraceback.dbx
%{_libexecdir}/%{name}/btraceback.gdb
%{_mandir}/man1/bsmtp.1*
%{_mandir}/man8/%{name}.8*
%{_mandir}/man8/btraceback.8*
%dir %attr(750, %{name}, %{name}) %{_localstatedir}/log/%{name}
%dir %attr(750, %{name}, %{name}) %{_localstatedir}/spool/%{name}

%files client
%defattr(-,root,root,-)
%{_sbindir}/%{name}-fd
%{_initrddir}/%{name}-fd
%config(noreplace) %{_sysconfdir}/%{name}/%{name}-fd.conf
%{_mandir}/man8/%{name}-fd.8*

%files console
%defattr(-,root,root,-)
%{_sbindir}/bconsole
%config(noreplace) %{_sysconfdir}/%{name}/bconsole.conf
%{_mandir}/man8/bconsole.8*

%files console-gnome
%defattr(-,root,root,-)
%config %{_sysconfdir}/security/console.apps/bgnome-console
%config %{_sysconfdir}/pam.d/bgnome-console
%config(noreplace) %{_sysconfdir}/%{name}/bgnome-console.conf
%{_bindir}/bgnome-console
%{_sbindir}/bgnome-console
%{_mandir}/man1/%{name}-bgnome-console.1*
%{_datadir}/applications/fedora-%{name}-gconsole.desktop
%{_datadir}/pixmaps/%{name}.png

%files console-wxwidgets
%defattr(-,root,root,-)
%config %{_sysconfdir}/security/console.apps/bwxconsole
%config %{_sysconfdir}/pam.d/wxconsole
%config(noreplace) %{_sysconfdir}/%{name}/bwxconsole.conf
%{_bindir}/bwxconsole
%{_sbindir}/bwxconsole
%{_mandir}/man1/%{name}-bwxconsole.1*
%{_datadir}/applications/fedora-%{name}-wxconsole.desktop
%{_datadir}/pixmaps/wxwin16x16.xpm

%files director-common
%defattr(-,root,root,-)
%doc %{name}-%{version}/updatedb/
%config(noreplace) %{_sysconfdir}/%{name}/%{name}-dir.conf
%config(noreplace) %{_sysconfdir}/%{name}/query.sql
%config %{_sysconfdir}/logwatch/conf/logfiles/%{name}.conf
%config %{_sysconfdir}/logwatch/conf/services/%{name}.conf
%{_sysconfdir}/logwatch/scripts/services/%{name}
%{_sysconfdir}/logwatch/scripts/shared/applybaculadate
%{_initrddir}/%{name}-dir
%{_sbindir}/bregex
%{_sbindir}/bwild
%{_mandir}/man8/dbcheck.8*
%{_mandir}/man8/%{name}-dir.8*
%{_libexecdir}/%{name}/make_catalog_backup.pl
%{_libexecdir}/%{name}/delete_catalog_backup

%files director-mysql
%defattr(-,root,root,-)
%{_sbindir}/%{name}-dir.mysql
%{_sbindir}/dbcheck.mysql
%{_libexecdir}/%{name}/create_mysql_database
%{_libexecdir}/%{name}/drop_mysql_database
%{_libexecdir}/%{name}/drop_mysql_tables
%{_libexecdir}/%{name}/grant_mysql_privileges
%{_libexecdir}/%{name}/make_mysql_tables
%{_libexecdir}/%{name}/update_mysql_tables
%{_libexecdir}/%{name}/create_%{name}_database.mysql
%{_libexecdir}/%{name}/drop_%{name}_database.mysql
%{_libexecdir}/%{name}/drop_%{name}_tables.mysql
%{_libexecdir}/%{name}/grant_%{name}_privileges.mysql
%{_libexecdir}/%{name}/make_%{name}_tables.mysql
%{_libexecdir}/%{name}/update_%{name}_tables.mysql

%files director-sqlite
%defattr(-,root,root,-)
%{_sbindir}/%{name}-dir.sqlite
%{_sbindir}/dbcheck.sqlite
# DANGER Will Robinson. Bacula has versioned sqlite filenames
%{_libexecdir}/%{name}/create_sqlite3_database
%{_libexecdir}/%{name}/drop_sqlite3_database
%{_libexecdir}/%{name}/drop_sqlite3_tables
%{_libexecdir}/%{name}/grant_sqlite3_privileges
%{_libexecdir}/%{name}/make_sqlite3_tables
%{_libexecdir}/%{name}/update_sqlite3_tables
%{_libexecdir}/%{name}/create_%{name}_database.sqlite
%{_libexecdir}/%{name}/drop_%{name}_database.sqlite
%{_libexecdir}/%{name}/drop_%{name}_tables.sqlite
%{_libexecdir}/%{name}/grant_%{name}_privileges.sqlite
%{_libexecdir}/%{name}/make_%{name}_tables.sqlite
%{_libexecdir}/%{name}/update_%{name}_tables.sqlite

%files director-postgresql
%defattr(-,root,root,-)
%{_sbindir}/%{name}-dir.postgresql
%{_sbindir}/dbcheck.postgresql
%{_libexecdir}/%{name}/create_postgresql_database
%{_libexecdir}/%{name}/drop_postgresql_database
%{_libexecdir}/%{name}/drop_postgresql_tables
%{_libexecdir}/%{name}/grant_postgresql_privileges
%{_libexecdir}/%{name}/make_postgresql_tables
%{_libexecdir}/%{name}/update_postgresql_tables
%{_libexecdir}/%{name}/create_%{name}_database.postgresql
%{_libexecdir}/%{name}/drop_%{name}_database.postgresql
%{_libexecdir}/%{name}/drop_%{name}_tables.postgresql
%{_libexecdir}/%{name}/grant_%{name}_privileges.postgresql
%{_libexecdir}/%{name}/make_%{name}_tables.postgresql
%{_libexecdir}/%{name}/update_%{name}_tables.postgresql

%files storage-common
%defattr(-,root,root,-)
%{_sbindir}/%{name}-sd
%{_sbindir}/bextract
%{_sbindir}/bls
%{_sbindir}/btape
%config(noreplace) %{_sysconfdir}/%{name}/%{name}-sd.conf
%{_initrddir}/%{name}-sd
%{_libexecdir}/%{name}/disk-changer
%{_libexecdir}/%{name}/dvd-handler
%{_libexecdir}/%{name}/mtx-changer
%{_mandir}/man8/bcopy.8*
%{_mandir}/man8/bextract.8*
%{_mandir}/man8/bls.8*
%{_mandir}/man8/bscan.8*
%{_mandir}/man8/btape.8*
%{_mandir}/man8/%{name}-sd.8*

%files storage-mysql
%defattr(-,root,root,-)
%{_sbindir}/bcopy.mysql
%{_sbindir}/bscan.mysql

%files storage-sqlite
%defattr(-,root,root,-)
%{_sbindir}/bcopy.sqlite
%{_sbindir}/bscan.sqlite

%files storage-postgresql
%defattr(-,root,root,-)
%{_sbindir}/bcopy.postgresql
%{_sbindir}/bscan.postgresql

%files traymonitor
%defattr(-,root,root,-)
%{_sbindir}/%{name}-tray-monitor
%config(noreplace) %{_sysconfdir}/%{name}/tray-monitor.conf
%{_mandir}/man1/%{name}-tray-monitor.1*
%{_datadir}/applications/fedora-%{name}-traymonitor.desktop
%{_datadir}/pixmaps/%{name}-tray-monitor.xpm

%files devel
%defattr(-,root,root,-)
%{_includedir}/bacula


%changelog
* Fri Aug 10 2012 Simone Caronni <negativo17@gmail.com> 2.4.4-10
- Removed editing of the config file, leave as comments for reference.
  (https://bugzilla.redhat.com/show_bug.cgi?id=456612#c11)

* Fri Aug 10 2012 Simone Caronni <negativo17@gmail.com> 2.4.4-9
- Fixed changelog.
- Added gtk labels patch for bgnome-console (rhbz#847131).
- Added script to change default backup catalog job to the director
  post section.

* Mon Jul 30 2012 Simone Caronni <negativo17@gmail.com> 2.4.4-8
- Swap make_catalog_backup with perl variant from 5.2.10 (rhbz#456612).

* Thu Jul 26 2012 Robert Scheck <robert@fedoraproject.org> 2.4.4-7
- Really re-added shared script applybaculadate for logwatch

* Thu Jul 19 2012 Simone Caronni <negativo17@gmail.com> 2.4.4-6
- Drop examples (rhbz#475469).

* Thu Jul 19 2012 Simone Caronni <negativo17@gmail.com> 2.4.4-5
- Spool directory owned only by common subpackage (rhbz#718299).
- Backport patch from Bacula 3.0.2 to fix logwatch (rhbz#643932).

* Wed Jul 18 2012 Simone Caronni <negativo17@gmail.com> 2.4.4-4
- Remove fedora-usermgmt entirely, see thread at:
  http://lists.fedoraproject.org/pipermail/packaging/2011-December/008034.html
- Add devel subpackage.
- Remove docs subpackage.
- Rename patches and delete unused ones from git.
- Remove conditionals for sqlite versions as this package will die with RHEL 5.

* Wed Jul 18 2012 Simone Caronni <negativo17@gmail.com> 2.4.4-3
- Removed commented stuff that will never come back.
- Cleaned up init files.
- Get rid of useless defines.
- Spec file formatting.

* Sun Feb 28 2010 Felix Schwarz <felix.schwarz@oss.schwarz.eu> 2.4.4-2
- Implement workaround for broken alternatives in 2.0.3-10

* Wed Jan 14 2009 Jon Ciesla <limb@jcomserv.net> 2.4.4-1
- Update to 2.4.4, fix alternatives.

* Thu Sep 13 2007 Andreas Thienemann <andreas@bawue.net> 2.0.3-10
- Applied restore fix to sd. #288981

* Wed Jul 25 2007 Andreas Thienemann <andreas@bawue.net> 2.0.3-9
- Corrected the %%post alternatives calls. Fixing #249560.

* Wed Jul 19 2007 Andreas Thienemann <andreas@bawue.net> 2.0.3-8
- Moved some files around in the %%files section and refactored
  spec parts a bit
- Fixed up the catalog-backup scripts by including them in the
  alternatives system
- Applied tls patch fixing some tls disconnection issues.

* Thu Jul 18 2007 Andreas Thienemann <andreas@bawue.net> 2.0.3-7
- Minor specchanges, mostly typos in the comments
- Incorporated minor changes from dgilmore's review.

* Fri Jul 13 2007 Andreas Thienemann <andreas@bawue.net> 2.0.3-6
- Fixing %%preun scripts. Thx to Dan for spotting this

* Fri Jul 13 2007 Andreas Thienemann <andreas@bawue.net> 2.0.3-5
- Fixed provides and requires

* Wed Jul 11 2007 Andreas Thienemann <andreas@bawue.net> 2.0.3-4
- Fixed many rpmlint issues

* Thu Apr 26 2007 Andreas Thienemann <andreas@bawue.net> 2.0.3-3
- Final cleanups for fedora
- Removed webgui for now. It will be back in a future release
- Added LANG=C calls to the initscripts

* Thu Apr 26 2007 Andreas Thienemann <andreas@bawue.net> 2.0.3-2
- Added logdir
- Fixed up doc-creation to actually work
- Fixed up web interface
- Included docs sub-package
- Included README et al as docs where appropriate

* Sat Mar 10 2007 Andreas Thienemann <andreas@bawue.net> 2.0.3-1
- Updated to 2.0.3
- Reverted the database-check as we're not sure the db is running on the
  local machine. A later revision might parse the bacula-dir.conf file
  and just connect to the db to see if it's running.

* Sat Feb 28 2007 Andreas Thienemann <andreas@bawue.net> 2.0.2-1
- Further updates on the spec

* Sat Feb 18 2007 Andreas Thienemann <andreas@bawue.net> 2.0.2-1
- Much work on the spec
- Updated to 2.0.2

* Sat Feb 18 2006 Andreas Thienemann <andreas@bawue.net> 1.38.11-1
- Initial spec.