#%bcond_with kde4

Name:            backintime
Version:         1.0.8
Release:         2%{?_dist_release}
Summary:         Simple backup system
Summary(ja):     シンプルなバックアップシステム

Group:           Applications/Archiving
License:         GPLv2+
URL:             http://backintime.le-web.org/
Source0:         http://backintime.le-web.org/download/%{name}/%{name}-%{version}_src.tar.gz
#Source1:         backintime-ja.po

#Patch0:          %{name}-0.9.26_snapshots.patch
#Patch1:          fix_ja.patch

BuildArch:       noarch
BuildRoot:	%{_tmppath}/%{name}-%{version}-root

BuildRequires:   desktop-file-utils
BuildRequires:   gettext libnotify-devel
BuildRequires:   gnome-session
BuildRequires:   kdelibs


%description
Back In Time is a simple backup system for Linux inspired from 
“flyback project” and “TimeVault”. The backup is done by taking 
snapshots of a specified set of directories.

%description -l ja
Back In Time は“flyback project”と“TimeVault”に触発された
Linux のためのシンプルなバックアップシステムです。
指定されたセットのディレクトリのスナップショットを取ることにより、
バックアップが行われます。

%package         common
Summary:         Common files for %{name}
Summary(ja):     %{name} の共通ファイル
Group:           Applications/Archiving
Requires:        python
Requires:        rsync
Requires:        notify-python
Requires:        libnotify
Requires:        crontabs

%description     common
Back In Time is a simple backup system for Linux inspired from 
“flyback project” and “TimeVault”.
This package contains non GUI files used by different GUI fontends.

%description -l ja     common
Back In Time は “flyback project” と “TimeVault” に触発された
Linux のためのシンプルなバックアップシステムです。
このパッケージは異なる GUI フロントエンドにより使用される
GUI を用いないファイルを含んでいます。

%package         gnome
Summary:         Frontend for %{name} on GNOME
Summary(ja):     %{name} の GNOME フロントエンド
Group:           Applications/Archiving
Requires:        %{name}-common = %{version}-%{release}
Requires:        pygtk2-libglade
Requires:        gnome-python
Requires:        usermode-gtk
Requires:        meld

%description     gnome
This package is the GNOME GUI frontend for backintime-common.
Back In Time is a simple backup system for Linux inspired from 
“flyback project” and “TimeVault”.

%description -l ja     gnome
Back In Timeは “flyback project” と “TimeVault” に触発された
Linux のためのシンプルなバックアップシステムです。
このパッケージは backintime-common の GNOME GUI フロントエンドです。

%package         kde
Summary:         Frontend for %{name} on KDE
Summary(ja):     %{name} の KDE フロントエンド
Group:           Applications/Archiving
Requires:        %{name}-common = %{version}-%{release}
Requires:        xorg-x11-utils
Requires:        PyKDE4
Requires:        usermode-gtk
Requires:        kdesdk


%description     kde
This is the KDE4 GUI frontend for backintime-common.
Back In Time is a simple backup system for Linux inspired from 
“flyback project” and “TimeVault”.

%description -l ja  kde
Back In Time は “flyback project” と “TimeVault” に触発された
Linux のためのシンプルなバックアップシステムです。
このパッケージは backintime-common の KDE4 GUI フロントエンドです。

%prep
%setup -q
#%patch0 -p1
#%patch1 -p1

#%__cp -f %{SOURCE1} common/po/ja.po

sed -i 's|Exec=gksu backintime-gnome|Exec=backintime-gnome-root|g' \
       gnome/%{name}-gnome-root.desktop
sed -i 's|Categories=GNOME;GTK;System;|Categories=GNOME;GTK;System;\nNotShowIn=KDE;|g' \
       gnome/%{name}-gnome.desktop

pushd .
cd ./kde4
cp -pr %{name}-kde4.desktop %{name}-kde4-root.desktop
popd

sed -i 's|Name=Back In Time|Name=Back In Time (root)|g' \
	kde4/%{name}-kde4-root.desktop
sed -i 's|Exec=backintime-kde4|Exec=%{_bindir}/kdesu -c backintime-kde4|g' \
	kde4/%{name}-kde4-root.desktop
sed -i 's|Categories=Qt;KDE;System;|Categories=Qt;KDE;System;\nNotShowIn=GNOME;XFCE;LXDE;|g' \
	kde4/%{name}-kde4-root.desktop

sed -e 's!share/locale!.*/locale!' /usr/lib/rpm/find-lang.sh > my-find-lang.sh

%build

cd common
%configure
make %{?_smp_mflags}

cd ../gnome
%configure
make %{?_smp_mflags}

cd ../kde4
%configure
make %{?_smp_mflags}

cd ..

%install
rm -rf %{buildroot}

cd common
make install \
     INSTALL="install -p" \
     PREFIX="%{_prefix}" \
     DEST="%{buildroot}/%{_prefix}"

cd ../gnome
make install \
     INSTALL="install -p" \
     PREFIX="%{_prefix}" \
     DEST="%{buildroot}/%{_prefix}"

cd ../kde4
make install \
     INSTALL="install -p" \
     PREFIX="%{_prefix}" \
     DEST="%{buildroot}/%{_prefix}"

cd ..

desktop-file-install \
        --dir=%{buildroot}/%{_datadir}/applications \
        %{buildroot}/%{_datadir}/applications/%{name}-gnome.desktop

desktop-file-install \
        --dir=%{buildroot}/%{_datadir}/applications/ \
        --add-category="Settings;" \
        %{buildroot}/%{_datadir}/applications/%{name}-gnome-root.desktop

desktop-file-install \
        --dir=%{buildroot}/%{_datadir}/applications/kde4 \
        %{buildroot}/%{_datadir}/applications/kde4/%{name}-kde4.desktop

desktop-file-install \
        --dir=%{buildroot}/%{_datadir}/applications/kde4 \
        --add-category="Settings;" \
        %{buildroot}/%{_datadir}/applications/kde4/%{name}-kde4-root.desktop


mkdir -p %{buildroot}%{_sbindir}
cp -p %{buildroot}%{_bindir}/%{name}-gnome \
      %{buildroot}%{_sbindir}/%{name}-gnome-root

cp -p %{buildroot}%{_bindir}/%{name}-kde4 \
      %{buildroot}%{_sbindir}/%{name}-kde4-root


ln -s consolehelper \
      %{buildroot}%{_bindir}/%{name}-gnome-root

ln -s consolehelper \
      %{buildroot}%{_bindir}/%{name}-kde4-root


mkdir -p %{buildroot}%{_sysconfdir}/security/console.apps/

cat << EOF > %{buildroot}%{_sysconfdir}/security/console.apps/%{name}-gnome-root
USER=root
PROGRAM=%{_sbindir}/%{name}-gnome-root
SESSION=true
EOF

cat << EOF > %{buildroot}%{_sysconfdir}/security/console.apps/%{name}-kde4-root
USER=root
PROGRAM=%{_sbindir}/%{name}-kde4-root
SESSION=true
EOF

mkdir -p %{buildroot}%{_sysconfdir}/pam.d

cat << EOF > %{buildroot}%{_sysconfdir}/pam.d/%{name}-gnome-root
#%PAM-1.0
auth            include         config-util
account         include         config-util
session         include         config-util
EOF

cat << EOF > %{buildroot}%{_sysconfdir}/pam.d/%{name}-kde4-root
%PAM-1.0
auth            include         config-util
account         include         config-util
session         include         config-util
EOF

sh my-find-lang.sh %{buildroot} %{name} %{name}.lang
find %{buildroot}/%{_datadir}/locale/ -mindepth 1 \
    \( -name locale -prune \) -o \
    -type d -printf '%%%%dir %{_datadir}/locale/%%P\n' -o \
    ! -name '*.py' -printf '%{_datadir}/locale/%%P\n' -o \
    -printf '%{_datadir}/locale/%%P\n' \
    -printf '%{_datadir}/locale/%%P[co]\n' >> lang.lst

%clean
rm -rf %{buildroot}


%files common -f lang.lst
%defattr(-,root,root,-)
%{_bindir}/%{name}
%dir %{_datadir}/%{name}/
%{_datadir}/%{name}/common/
%{_datadir}/%{name}/plugins/
%{_mandir}/man1/%{name}*
%doc %{_docdir}/%{name}/
%doc %{_docdir}/%{name}-common/


%files gnome
%defattr(-,root,root,-)
%{_bindir}/%{name}-gnome
%{_bindir}/%{name}-gnome-root
%{_sbindir}/%{name}-gnome-root
%{_datadir}/applications/%{name}-gnome.desktop
%{_datadir}/applications/%{name}-gnome-root.desktop
%{_datadir}/%{name}/gnome/
%doc %{_datadir}/gnome/help/%{name}/
%doc %{_docdir}/%{name}-gnome/
%{_datadir}/omf/%{name}/
%config(noreplace) %{_sysconfdir}/pam.d/%{name}-gnome-root
%config %{_sysconfdir}/security/console.apps/%{name}-gnome-root


%files kde
%defattr(-,root,root,-)
%{_bindir}/%{name}-kde4
%{_bindir}/%{name}-kde4-root
%{_sbindir}/%{name}-kde4-root
%{_datadir}/applications/kde4/%{name}-kde4.desktop
%{_datadir}/applications/kde4/%{name}-kde4-root.desktop
%{_datadir}/backintime/kde4/
%doc %{_datadir}/doc/kde4/HTML/en/%{name}/
%doc %{_docdir}/%{name}-kde4/
%config(noreplace) %{_sysconfdir}/pam.d/%{name}-kde4-root
%config %{_sysconfdir}/security/console.apps/%{name}-kde4-root

%changelog
* Fri May 18 2012 Toshiharu Kudoh <toshi.kd2@gmail.com> - 1.0.8-2
- rebuilt with python-2.7
- added BuildRequires: gnome-session, kdelibs

* Fri Oct 14 2011 Toshiharu Kudoh <toshi.kd2@gmail.com> - 1.0.8-1
- new upstream release
- deleted %bcond_with macro

* Mon Jan 3 2011 Toshiharu Kudoh <toshi.kd2@gmail.com> - 1.0.6-1
- new upstream release
- dropt patch1

* Sat Dec 25 2010 Toshiharu Kudoh <toshi.kd2@gmail.com> - 1.0.4-1
- new upstream release
- added Patch1 to fix ja.po a little

* Sat Feb 6 2010 Toshiharu Kudoh <toshi.kd2@gmail.com> - 0.9.26-10
- rebuilt with python-2.6.4

* Sun Jan 17 2010 Toshiharu Kudoh <toshi.kd2@gmail.com> - 0.9.26-9
- used %bcond_with macro to maintain easier on Stable Release and Seed

* Sat Nov 28 2009 Toshiharu Kudoh <toshi.kd2@gmail.com> - 0.9.26-7
- generated GUI frontend for KDE4 package

* Mon Nov 23 2009 Toshiharu Kudoh <toshi.kd2@gmail.com> - 0.9.26-6
- updated Source1

* Sat Sep 26 2009 Toshiharu Kudoh <toshi.kd2@gmail.com> - 0.9.26-5
- updated Source1
- added Patch0 from Fedora to secure backups

* Sun Jun 28 2009 Toshiharu Kudoh <toshi.kd2@gmail.com> - 0.9.26-4vl5
- updated Source1

* Sun Jun 14 2009 Toshiharu Kudoh <toshi.kd2@gmail.com> - 0.9.26-3vl5
- updated Source1
- cleaned up spec
- changed description of common, gnome
- added Japanese summary

* Sat May 23 2009 Toshiharu Kudoh <toshi.kd2@gmail.com> - 0.9.26-2vl5
- fixed changelog typo in May 22
- updated Source1

* Fri May 22 2009 Toshiharu Kudoh <toshi.kd2@gmail.com> - 0.9.26-1vl5
- New upstream release
- dropt Patch1
- changed URL and Source0 tag
- updated description of backintime-gnome
- updated Source1

* Sun May 3 2009 Toshiharu Kudoh <toshi.kd2@gmail.com> - 0.9.22-3vl5
- added Source1 to translate Japanese

* Fri May 1 2009 Toshiharu Kudoh <toshi.kd2@gmail.com> - 0.9.22-2vl5
- deleted PreReq: notify-python
- moved Requires: notify-python, libnotify (to backintime-common)
- fixed changelog typo in Apr 30

* Thu Apr 30 2009 Toshiharu Kudoh <toshi.kd2@gmail.com> - 0.9.22-1vl5
- New upstream release
- added Patch0 (import from fedora)
- added PreReq: notify-python
- added Requires: usermode-gtk (gnome and kde)
- added configure option (enabled:common,gnome disabled:kde4)
- spec in UTF-8

* Mon Apr 6 2009 Toshiharu Kudoh <toshi.kd2@gmail.com> - 0.9.20-1vl5
- New upstream release

* Sat Apr 4 2009 Toshiharu Kudoh <toshi.kd2@gmail.com> - 0.9.18-1vl5
- initial build for VineSeed
- don't provide package for KDE4 frontend (because KDE4 still don't provide..)

* Tue Mar 17 2009 Simon Wesp <cassmodiah@fedoraproject.org> - 0.9.16.1-1
- New upstream release

* Tue Mar 10 2009 Simon Wesp <cassmodiah@fedoraproject.org> - 0.9.14-1
- Initial Package build
