#define python_sitelib %(%{__python} -c 'from distutils import sysconfig; print sysconfig.get_python_lib(1)')

Summary: A wireless and wired network manager
Summary(ja): 無線・有線ネットワークマネージャ
Name: wicd
Version: 1.7.0
Release: 5%{?_dist_release}
Source0: %{name}-%{version}.tar.bz2
# from ATrpms package
Patch0:  wicd-1.7.0-init-script.patch

Patch1:  wicd-desktop.patch
Patch2:  18-dont_run_unexpected_files_in_scripts.patch
Patch3:  27-fix_resolv.conf_perms.patch

License: GPLv2
Group: System Environment/Base
BuildRoot: %{_tmppath}/%{name}-%{version}-root
URL: http://wicd.net

BuildRequires: gettext
BuildRequires: desktop-file-utils
BuildRequires: python >= 2.4 python-devel >= 2.4
BuildRequires: python-setuptools

Requires: python >= 2.4 ethtool net-tools wpa_supplicant pm-utils wireless-tools
Requires: dhclient iproute dbus-python
Requires: pygtk2 >= 2.10
Requires: python-urwid >= 0.9.8.3
Requires: gksu

Requires(post):   chkconfig
Requires(preun):  chkconfig
Requires(preun):  /sbin/service
Requires(postun): /sbin/service

Conflicts: NetworkManager

%description
A complete network connection manager
Wicd supports wired and wireless networks, and capable of
creating and tracking profiles for both.  It has a 
template-based wireless encryption system, which allows the user
to easily add encryption methods used.  It ships with some common
encryption types, such as WPA and WEP. Wicd will automatically
connect at startup to any preferred network within range.


%prep
%setup -q
%patch0 -p1 -b .init
%patch1 -p1
%patch2 -p1
%patch3 -p1

%{__sed} -i 's/\r//' wicd/logfile.py

%build
%{__python} setup.py configure --share=%{_datadir}/%{name} \
       --etc=%{_sysconfdir}/%{name} \
       --bin=%{_bindir} \
       --sbin=%{_sbindir} \
       --mandir=%{_mandir} \
       --varlib=%{_sharedstatedir}/wicd \
       --pmutils=%{_libdir}/pm-utils/sleep.d \
       --resume=%{_sysconfdir}/acpi/resume.d \
       --suspend=%{_sysconfdir}/acpi/suspend.d \
       --docdir=%{_docdir}/%{name}-%{version} \
       --no-install-kde \
       --no-install-docs

python setup.py build

%install
rm -rf %{buildroot}
python setup.py install -O1 --skip-build --root=%{buildroot}
install -D init/redhat/%{name} %{buildroot}%{_initddir}/%{name}

desktop-file-install --vendor "" --dir %{buildroot}%{_datadir}/autostart/ other/wicd-tray.desktop

%find_lang %{name}

%post
touch --no-create %{_datadir}/icons/hicolor &>/dev/null || :
/sbin/service %{name} restart >/dev/null 2>&1
/sbin/chkconfig --add %{name}
/sbin/chkconfig --level 345 %{name} on

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

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

if [ $1 -eq 0 ] ; then
    touch --no-create %{_datadir}/icons/hicolor &>/dev/null
    gtk-update-icon-cache %{_datadir}/icons/hicolor &>/dev/null || :
fi

%posttrans
gtk-update-icon-cache %{_datadir}/icons/hicolor &>/dev/null || :

%clean
[ -d "$RPM_BUILD_ROOT" -a "$RPM_BUILD_ROOT" != "/" ] && rm -rf $RPM_BUILD_ROOT

%files -f %{name}.lang
%defattr(-,root,root)
%doc AUTHORS CHANGES INSTALL LICENSE NEWS README other/WHEREAREMYFILES
%{_bindir}/wicd-*
%{python_sitelib}/wicd
%{python_sitelib}/*.egg-info
%{_datadir}/wicd
%{_datadir}/pixmaps/wicd*
%{_datadir}/icons/hicolor/*/apps/wicd-*.png
%{_datadir}/icons/hicolor/scalable/apps/wicd-gtk.svg
%{_datadir}/applications/wicd.desktop
%{_datadir}/autostart/wicd-tray.desktop
%docdir %{_datadir}/doc/%{name}/
%{_mandir}/nl/man?/%{name}*
%{_mandir}/man?/%{name}*
%{_sysconfdir}/%{name}
%{_sysconfdir}/acpi/resume.d/80-wicd-connect.sh
%{_sysconfdir}/acpi/suspend.d/50-wicd-suspend.sh
%{_sysconfdir}/dbus-1/system.d/wicd.conf
%{_sysconfdir}/rc.d/init.d/wicd
%{_sysconfdir}/xdg/autostart/wicd-tray.desktop
%{_sbindir}/wicd
%{_libdir}/pm-utils/sleep.d/91wicd
%{_localstatedir}/log/wicd/.empty_on_purpose
%{_localstatedir}/lib/wicd

%changelog
* Wed Jun 9 2010 Toshiharu Kudoh <toshi.kd2@gmail.com> - 1.7.0-5
- improved service start process in %%post section
- changed daemon start runlevel

* Mon Jun 07 2010 Shu KONNO <owa@bg.wakwak.com> - 1.7.0-4
- fixed %%python_sitelib

* Sat Jun 5 2010 Toshiharu Kudoh <toshi.kd2@gmail.com> - 1.7.0-3
- added Rerquires: gksu
- added Patch2,3 from Debian
  - to stop running unexpected files in scripts
  - to fix resolv.conf permission

* Fri Jun 4 2010 Toshiharu Kudoh <toshi.kd2@gmail.com> - 1.7.0-2
- added chkconfig in %post
- added Patch1 to add Japanese description for desktop file

* Fri May 28 2010 Toshiharu Kudoh <toshi.kd2@gmail.com> - 1.7.0-1
- initial build for VineSeed
