File bweb.spec of Package bacula
# Bweb RPM spec file
# Copyright (C) 2009-2009 Bacula Systems
#
# basic defines for every build
%define _version 3.0.1
%define _release 1
Summary: An advance web interface for Bacula
Name: bweb
Version: %{_version}
Release: %{_release}
License: GPL v2
Group: Applications/Internet
Source: http://www.prdownloads.sourceforge.net/bacula/bweb-%{version}.tar.gz
URL: http://www.bacula.org
Vendor: Bacula Systems SA
Packager: Support <support@baculasystems.com>
BuildArch: noarch
BuildRoot: %{_tmppath}/%{name}-%{version}-%{release}-buildroot
Requires: gd, perl-DBD-Pg, perl-DBD-MySQL, perl-DBI, httpd, bweb-dep, xorg-x11-fonts-truetype
#Requires: perl-Expect, perl-Date-Calc, perl-HTML-Template, perl-IO-Tty, perl-IO-Stty
#Requires: perl-GD, perl-Time-ParseDate, perl-GD-Graph, perl-GD-Text-Util
#Requires: perl-Time-modules, perl-DBD-Pg | perl-DBD-Mysql
%description
Bweb is a web based program that provides a tool to do basic and advanced
operations and get statistics from Bacula.
%prep
%setup
%install
mkdir -p $RPM_BUILD_ROOT/usr/share/bweb/cgi-bin
install -m 755 cgi/*.pl $RPM_BUILD_ROOT/usr/share/bweb/cgi-bin
mkdir -p $RPM_BUILD_ROOT/usr/share/bweb/tpl/en
install -m 644 lang/en/tpl/*.tpl $RPM_BUILD_ROOT/usr/share/bweb/tpl/en
mkdir -p $RPM_BUILD_ROOT/usr/share/bweb/tpl/fr
install -m 644 lang/fr/tpl/*.tpl $RPM_BUILD_ROOT/usr/share/bweb/tpl/fr
mkdir -p $RPM_BUILD_ROOT/usr/share/bweb/tpl/es
install -m 644 lang/es/tpl/*.tpl $RPM_BUILD_ROOT/usr/share/bweb/tpl/es
mkdir -p $RPM_BUILD_ROOT/usr/share/bweb/html
install -m 644 html/*.{js,png,css,gif,ico,html} $RPM_BUILD_ROOT/usr/share/bweb/html
mkdir -p $RPM_BUILD_ROOT/usr/lib/perl5/vendor_perl
install -m 644 lib/*.pm $RPM_BUILD_ROOT/usr/lib/perl5/vendor_perl
mkdir -m 700 -p $RPM_BUILD_ROOT/var/www/bweb
mkdir -m 755 -p $RPM_BUILD_ROOT/usr/share/bweb
install -m 644 script/bweb-postgresql.sql $RPM_BUILD_ROOT/usr/share/bweb
install -m 644 script/bweb-mysql.sql $RPM_BUILD_ROOT/usr/share/bweb
mkdir -p $RPM_BUILD_ROOT/etc/httpd/conf.d
cat > $RPM_BUILD_ROOT/etc/httpd/conf.d/bweb.conf <<EOF
ScriptAlias /cgi-bin/bweb "/usr/share/bweb/cgi-bin/"
<Directory "/usr/share/bweb/cgi-bin">
AllowOverride None
Options None
Order allow,deny
Allow from all
# Uncomment to get restricted access
#
# AuthType Basic
# AuthName MyPrivateFile
# AuthUserFile /etc/bacula/htpasswd.bweb
# AllowOverride None
# Require valid-user
</Directory>
Alias /bweb/fv/ /var/www/bweb/
<Directory "/var/www/bweb/">
Options None
AllowOverride AuthConfig
Order allow,deny
Allow from all
</Directory>
<Directory "/usr/share/bweb/html">
AllowOverride All
</Directory>
Alias /bweb /usr/share/bweb/html
EOF
mkdir -p -m 755 $RPM_BUILD_ROOT/etc/bacula
%post
if [ ! -f /etc/bacula/bweb.conf -a -x /opt/bacula/bin/dbcheck ]; then
out="/opt/bacula/bin/dbcheck -B -c /opt/bacula/etc/bacula-dir.conf"
if [ $? = 0 ]; then
p=$($out | awk -F= '/db_password/ { print $2 }')
type=$($out | awk '/db_type=PostgreSQL/ { print "Pg" } /db_type=MySQL/ { print "mysql" }')
d=$($out | awk -F= '/db_name/ { print $2 }')
h=$($out | awk -F= '/db_host/ { print ";host=" $2 }')
p=$($out | awk -F= '/db_password/ { print $2 }')
u=$($out | awk -F= '/db_user/ { print $2 }')
cat > $RPM_BUILD_ROOT/etc/bacula/bweb.conf <<EOF
\$VAR1 = bless( {
'lang' => 'en',
'name' => undef,
'config_file' => '/etc/bacula/bweb.conf',
'bconsole' => '/opt/bacula/bin/bconsole -n -c /opt/bacula/etc/bconsole-bweb.conf',
'template_dir' => '/usr/share/bweb/tpl',
'password' => '$p',
'dbi' => 'DBI:${type}:database=${d}${h}',
'user' => '$u',
'fv_write_path' => '/var/www/bweb',
'graph_font' => '/usr/share/X11/fonts/TTF/luximr.ttf',
}, 'Bweb::Config' );
EOF
case $type in
mysql)
mysql bacula -e 'SHOW TABLES;' 2>/dev/null|grep bweb_user > /dev/null
if [ $? != 0 ]; then
mysql bacula < /usr/share/bweb/bweb-mysql.sql
fi
;;
Pg)
echo '\d' | su - postgres -c 'psql bacula' 2>/dev/null | grep bweb_user > /dev/null
if [ $? != 0 ]; then
su - postgres -c 'createlang plpgsql bacula'
su - postgres -c 'psql bacula' < /usr/share/bweb/bweb-postgresql.sql
echo 'GRANT ALL ON DATABASE bacula to bacula;' | su - postgres -c 'psql bacula'
fi
;;
esac
fi
chown root:apache /etc/bacula/bweb.conf
chmod 660 /etc/bacula/bweb.conf
cp /opt/bacula/etc/bconsole.conf /opt/bacula/etc/bconsole-bweb.conf
chmod 640 /opt/bacula/etc/bconsole-bweb.conf
chown root:apache /opt/bacula/etc/bconsole-bweb.conf
chmod a+rx /opt/bacula/bin/bconsole
else
if [ ! -f /etc/bacula/bweb.conf ]; then
cat > $RPM_BUILD_ROOT/etc/bacula/bweb.conf <<EOF
\$VAR1 = bless( {
'lang' => 'en',
'name' => undef,
'config_file' => '/etc/bacula/bweb.conf',
'bconsole' => '/opt/bacula/bin/bconsole -n -c /opt/bacula/etc/bconsole-bweb.conf',
'template_dir' => '/usr/share/bweb/tpl',
'fv_write_path' => '/var/www/bweb',
'graph_font' => '/usr/share/X11/fonts/TTF/luximr.ttf',
'password' => '',
# 'dbi' => 'DBI:Pg:database=bacula',
'user' => 'bacula',
}, 'Bweb::Config' );
EOF
fi
fi
/etc/init.d/httpd reload
%files
%defattr(-,root,root)
%doc INSTALL
/etc/bacula
/usr/share/bweb
/usr/lib/perl5/vendor_perl
/etc/httpd/conf.d/bweb.conf
%attr(-, apache, apache) /var/www/bweb