%define _prefix /var/opt/mkcdrec
%define _webmin_root /usr/libexec/webmin
%define _webmin_access_file /etc/webmin/webmin.acl
%define _webmin_cache_cile /etc/webmin/module.infos.cache
%define _boot_arch x86
Summary: mkCDrec (make CD-ROM Recovery) disaster recovery tool-set
Name: mkcdrec
Version: v0.8.7
Release: 1
Source: mkCDrec_%{version}.tar.gz
URL: http://mkcdrec.ota.be/
License: GPL
Group: System/Archiving
Packager: Gratien D'haese
Provides: perl(mkcdrec-lib.pl)

%if %{_boot_arch}==ia64
Prereq: chkconfig fileutils cdrecord mkisofs tar ash mtools rsync
Requires: kernel >= 2.0.0, util-linux >= 2.11, perl >= 5.0, parted >= 1.6
BuildRequires: gcc >= 2.96
%endif
%if %{_boot_arch}==x86_64
Prereq: fileutils cdrecord mkisofs tar ash rsync
Requires: kernel >= 2.0.0, util-linux >= 2.11, perl >= 5.0
BuildRequires: gcc >= 2.96
%endif
%if %{_boot_arch}==x86
Prereq: coreutils fileutils cdrecord mkisofs tar ash mtools syslinux rsync
Requires: kernel >= 2.0.0, util-linux >= 2.11, perl >= 5.0
BuildRequires: syslinux >= 1.60, gcc >= 2.96
%endif

BuildRoot: %{_tmppath}/%{name}-%{version}-root
Prefix: %{_prefix}

%description
mkCDrec (Make CDROM Recovery) makes a bootable (El Torito) disaster recovery
image, including backups of the Linux system to one or more CD-ROM(s)
(multi-volume sets). Otherwise, the backups can be stored on another disk,
NFS disk, or (remote) tape. After a disk crash or system intrusion, the system
can be booted from the CD-ROM and one can restore the complete system as 
it was. It also features disk cloning, which allows one to restore a disk
to another disk (the destination disk does not have to be of the same size,
as it calculates the partition layout itself). Currently, ext2, ext3, minix, 
msdos, fat, vfat, reiserfs, xfs and jfs filesystems are supported.

%changelog
* Wed Jun 23 2004 Guillaume Radde & Gratien D'haese
- add support for IA64
- add webmin module

* Tue Jun 09  2004 Gratien D'haese
- remove sfdisk, tinylogin and udpcp

* Tue Jun 01  2004 Gratien D'haese
- Updated Prereq list

* Sat Jan 24  2004 Gratien D'haese
- remove "cksfv*/src/cksfv" from binaries

* Tue Nov 13 2003 Gratien D'haese
- add contributions directory

* Sun Sep 7 2003 Gratien D'haese
- added doc/style to rpm

* Mon May  5 2003 Michal Jaegermann
- spec edits for sanity

* Sat Feb 22 2003 Gratien D'haese
 - changed the rules for syslinux/isolinux

* Sat Jan 10 2003 Gratien D'haese
 - finishing mkcdrec2.spec for our i386 binary RPM

* Tue Dec 10 2002 Gratien D'haese
 - extending mkcdrec2.spec file

* Sat Feb 09 2002 Gratien D'haese
 - initial draft of mkcdrec2.spec file and modified the original makerpms.sh
   shell script from samba team.

%prep
%setup -n mkcdrec

%build
make -f Makefile.%{_boot_arch} build

%install
mkdir -p $RPM_BUILD_ROOT%{_prefix}/busybox/applets
mkdir -p $RPM_BUILD_ROOT%{_prefix}/bin
mkdir -p $RPM_BUILD_ROOT%{_prefix}/contributions
mkdir -p $RPM_BUILD_ROOT%{_prefix}/modules
mkdir -p $RPM_BUILD_ROOT%{_prefix}/scripts/messages
mkdir -p $RPM_BUILD_ROOT%{_prefix}/doc
mkdir -p $RPM_BUILD_ROOT%{_prefix}/doc/style
mkdir -p $RPM_BUILD_ROOT%{_prefix}/doc/images
mkdir -p $RPM_BUILD_ROOT%{_prefix}/usr
mkdir -p $RPM_BUILD_ROOT%{_prefix}/etc
mkdir -p $RPM_BUILD_ROOT%{_mandir}/man8
for fname in busybox*/busybox  busybox*/busybox.links; do
	install -m 755 $fname $RPM_BUILD_ROOT%{_prefix}/busybox
done

install -m 755 busybox*/applets/install.sh $RPM_BUILD_ROOT%{_prefix}/busybox/applets

for fname in  cutstream*/cutstream \
 pastestream*/pastestream mediacheck/checkisomd5 mediacheck/implantisomd5
do
	install -m 755 $fname $RPM_BUILD_ROOT%{_prefix}/bin
done
for fname in contributions/*.sh; do
	install -m 755 $fname $RPM_BUILD_ROOT%{_prefix}/contributions
done
for fname in scripts/messages/*; do
	install -m 755 $fname $RPM_BUILD_ROOT%{_prefix}/scripts/messages
done
for fname in `find scripts -type f`; do
	install -m 755 $fname $RPM_BUILD_ROOT%{_prefix}/$fname
done
for fname in modules/*; do
	install -m 755 $fname $RPM_BUILD_ROOT%{_prefix}/modules
done
for fname in doc/*.html doc/*.gif doc/*.jpg doc/*.png; do
	install -m 755  $fname $RPM_BUILD_ROOT%{_prefix}/doc
done
for fname in doc/style/*.css; do
	install -m 755  $fname $RPM_BUILD_ROOT%{_prefix}/doc/style
done
for fname in doc/images/*; do
        install -m 755  $fname $RPM_BUILD_ROOT%{_prefix}/doc/images
done

for fname in `find etc -type d`; do
	install -d -m 755  $fname $RPM_BUILD_ROOT%{_prefix}/$fname
done
for fname in `find etc -type f`; do
	install -m 755  $fname $RPM_BUILD_ROOT%{_prefix}/$fname
done
for fname in `find usr -type d`; do
	install -d -m 755  $fname $RPM_BUILD_ROOT%{_prefix}/$fname
done
for fname in `find usr -type f`; do
	install -m 755  $fname $RPM_BUILD_ROOT%{_prefix}/$fname
done

for fname in `find . -type f -maxdepth 1`; do
	install -m 755  $fname $RPM_BUILD_ROOT%{_prefix}/$fname
done

install -m 755 doc/mkcdrec.8 $RPM_BUILD_ROOT%{_mandir}/man8
# gzip $RPM_BUILD_ROOT%{_mandir}/man8/mkcdrec.8
for file in \
    $RPM_BUILD_ROOT%{_prefix}/.cvsignore \
    $RPM_BUILD_ROOT%{_prefix}/COPYING \
    $RPM_BUILD_ROOT%{_prefix}/Changelog \
    $RPM_BUILD_ROOT%{_prefix}/README \
; do rm -f $file ; done
  
# installation of webmin module


[ ! -d $RPM_BUILD_ROOT%{_webmin_root}/mkcdrec ] && install -d -m 755 $RPM_BUILD_ROOT%{_webmin_root}/mkcdrec
# we copy files in webmin directory
#if test -d $RPM_BUILD_ROOT%{_webmin_root}

	for fname in `find webmin -type d`; do
		install -d -m 755 $fname $RPM_BUILD_ROOT%{_webmin_root}/`echo $fname | sed -e 's/webmin/mkcdrec/'`
	done
	for fname in `find webmin -type f`; do
		install -m 755 $fname $RPM_BUILD_ROOT%{_webmin_root}/`echo $fname | sed -e 's/webmin/mkcdrec/'`
	done
#fi
%files
%defattr(-,root,root)
%doc Changelog README COPYING
%doc %{_prefix}/doc
%{_prefix}/VERSION
%{_prefix}/.config.bb
%{_prefix}/busybox
%{_prefix}/bin
%{_prefix}/contributions
%{_prefix}/scripts
%{_prefix}/modules
%{_prefix}/etc
%{_prefix}/usr
%{_prefix}/Config.sh
%{_prefix}/linuxrc
%{_prefix}/linuxrc_find_and_prep_root
%{_prefix}/linuxrc_post
%{_prefix}/linuxrc_pre
%{_prefix}/Makefile
%{_prefix}/Makefile.new-powermac
%{_prefix}/Makefile.x86
%{_prefix}/Makefile.sparc
%{_prefix}/Makefile.ia64
%{_prefix}/Makefile.x86_64
%{_mandir}/man8/*
%{_webmin_root}/mkcdrec/help.cgi
%{_webmin_root}/mkcdrec/images/icon
%{_webmin_root}/mkcdrec/images/icon.gif
%{_webmin_root}/mkcdrec/index.cgi
%{_webmin_root}/mkcdrec/lang/en
%{_webmin_root}/mkcdrec/lang/fr
%{_webmin_root}/mkcdrec/mkcdrec-lib.pl
%{_webmin_root}/mkcdrec/module.info
%{_webmin_root}/mkcdrec/save.cgi

%post
#we add mkcdrec in webmin root's ACL
if [ -f %{_webmin_access_file} ]; then
	cp %{_webmin_access_file} %{_webmin_access_file}.beforemkcdrec.sauv
	ed %{_webmin_access_file} << EOF > /tmp/mkcdrec.log 2>&1
/root:
s/root:/root: mkcdrec/
w
q
EOF
else
	echo "WARNING: it seems that webmin isn't installed on that system.If you install it later, don't forget to add mkcdrec to the list of modules in %{_webmin_access_file} to make mkcdrec's webmin module available."

fi

%postun
# we remove mkcdrec from webmin root's ACL

if [ -f %{_webmin_access_file} ]; then
	ed %{_webmin_access_file} << EOF > /tmp/mkcdrec.log 2>&1
s/mkcdrec//g
w
q
EOF
fi

