%define _localstatedir /var
Summary: A free Socks v4/v5 client implementation
Summary(ja): Socks v4/v5 クライアントのフリーな実装
Name: dante
Version: 1.1.14
# define for pre-releases, undefine for normal releases.
%undefine pre
Release: 1%{?_dist_release}
License: BSD-type
Group: Applications/Internet
URL: http://www.inet.no/dante/
%define distname %{name}-%{version}%{?pre:-%{pre}}
Source: ftp://ftp.inet.no/pub/socks/%{distname}.tar.gz
Source1: sockd.conf
Buildroot: %{_tmppath}/%{name}-%{version}-root
BuildPreReq: pam-devel tcp_wrappers
Requires: pam

%description
Dante is a free implementation of the proxy protocols socks version 4,
socks version 5 (rfc1928) and msproxy. It can be used as a firewall
between networks. It is being developed by Inferno Nettverk A/S, a
Norwegian consulting company. Commercial support is available.

This package contains the dynamic libraries required to "socksify"
existing applications to become socks clients.

%description -l ja
dante は proxy プロトコルである socks バージョン4,socks バージョン5
(rfc1928), mxproxy のフリー実装です.ネットワーク間のファイアーウォールと
して使うことが出来ます.開発はノルウェーのコンサルタント会社である
Inferno Netverk A/S で行われています.コマーシャルサポートもあります.

このパッケージには,既存のアプリケーションを socks クライアントに
するのに必要なダイナミックライブラリが収められています.

%package server
Summary: A free Socks v4/v5 server implementation
Summary(ja): Socks v4/v5 サーバのフリーな実装
Group: System Environment/Daemons
Requires: dante = %{version}
PreReq: /sbin/chkconfig

%description server
This package contains the socks proxy daemon and its documentation.
The sockd is the server part of the Dante socks proxy package and
allows socks clients to connect through it to the network.

%description server -l ja
このパッケージには socks プロキシデーモンとそのドキュメントが
収められています.sockd は Dante socks プロキシパッケージの
サーバ部分で,socks クライアントは sockd サーバを介することにより
ネットワークに接続出来ます.

%package devel
Summary: development libraries for socks
Summary(ja): socks 用開発ライブラリ
Group: Development/Libraries
Requires: dante = %{version}

%description devel
Additional libraries required to compile programs that use socks.

%description devel -l ja
socks を使うプログラムをコンパイルするのに必要な追加ライブラリです.

%prep
%setup -q -n %{distname}

# no need to preload libdl.so explicitly.
%{__sed} -e 's/@SOCKSIFY_PRELOAD_LIBS@//' bin/socksify.in >bin/socksify.in.new
%{__mv} bin/socksify.in.new bin/socksify.in

# This file is embedded here instead of being another source in order
# to the prefix directory
cat >sockd.init <<EOF
#!/bin/sh
#
# sockd         This shell script takes care of starting and stopping
#               the Dante server.
#
# chkconfig: 2345 65 35
# description: sockd implements a socks v4/v5 proxy server

# Source function library.
. /etc/rc.d/init.d/functions

# Source networking configuration.
. /etc/sysconfig/network

# Check that networking is up.
[ \${NETWORKING} = "no" ] && exit 0

[ -f %{_sbindir}/sockd ] || exit 0
[ -f %{_sysconfdir}/sockd.conf ] || exit 0

# See how we were called.
case "\$1" in
  start)
	# Start daemons.
	echo -n "Starting sockd: "
	daemon %{_sbindir}/sockd -D
	echo
	touch %{_var}/lock/subsys/sockd
	;;
  stop)
	# Stop daemons.
	echo -n "Shutting down sockd: "
	killproc sockd
	echo
	rm -f %{_var}/lock/subsys/sockd
	;;
  restart)
	\$0 stop
	\$0 start
	;;
  status)
	status sockd
	;;
  *)
	echo "Usage: sockd {start|stop|restart|status}"
	exit 1
esac

exit 0
EOF

%build
%configure
%{__make}

%install
%{__rm} -rf %{buildroot}
%{makeinstall}

#set library as executable - prevent ldd from complaining
%{__chmod} +x %{buildroot}%{_libdir}/*.so.*.*
%{__install}  -d %{buildroot}%{_sysconfdir}/rc.d/init.d %{buildroot}%{_bindir}
%{__install} -m 644 example/socks-simple.conf %{buildroot}%{_sysconfdir}/socks.conf
%{__install} -m 644 %{_sourcedir}/sockd.conf %{buildroot}%{_sysconfdir}
%{__install} -m 755 sockd.init %{buildroot}%{_sysconfdir}/rc.d/init.d/sockd

## remove unuse files
rm -rf $RPM_BUILD_ROOT%{_libdir}/*.la


%clean
%{__rm} -rf %{buildroot}


%post -p /sbin/ldconfig
%postun -p /sbin/ldconfig

%post server
/sbin/chkconfig --add sockd

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

%postun server
if [ "$1" -ge "1" ]; then
	service sockd condrestart > /dev/null 2>&1
fi

%files
%defattr(-,root,root)
%doc BUGS CREDITS INSTALL LICENSE NEWS README SUPPORT TODO
%doc doc/README* doc/rfc* doc/SOCKS4.protocol doc/faq.tex
%doc example/{socks.conf,socks-simple-withoutnameserver.conf,sockd.conf,socks-simple.conf}
%{_libdir}/libsocks.so.0.1.0
%{_libdir}/libsocks.so.0
%{_libdir}/libdsocks.so.0.1.0
%{_libdir}/libdsocks.so.0
%{_libdir}/libdsocks.so
%{_bindir}/socksify
%{_mandir}/man5/socks.conf.5*
%config(noreplace) %{_sysconfdir}/socks.conf


%files server
%defattr(-,root,root)
%{_mandir}/man8/sockd.8*
%{_sbindir}/sockd
%{_mandir}/man5/sockd.conf.5*
%config(noreplace) %{_sysconfdir}/sockd.conf
%config %{_sysconfdir}/rc.d/init.d/sockd


%files devel
%defattr(-,root,root)
%{_libdir}/libsocks.so
#%{_libdir}/libsocks.la
%{_libdir}/libsocks.a
#%{_libdir}/libdsocks.la
%{_includedir}/socks.h


%changelog
* Sat Sep 20 2008 Shu KONNO <owa@bg.wakwak.com> 1.1.14-1vl5
- applied new versioning policy, spec in utf-8
- removed *.la

* Mon May 10 2004 NISHIMURA Daisuke <nishi@graco.c.u-tokyo.ac.jp>
- 1.1.14-0vl1: built for VineSeed
- use/change macros for dirs (/etc, /var)
- re-enable chkconfig and add stop/restart on uninstall/upgrade
- include our sockd.conf (Source1) based on example/sockd-basic.conf

* Mon Nov 24 2003 NISHIMURA Daisuke <nishi@graco.c.u-tokyo.ac.jp>
- 1.1.14-0vl0.26.0: new upstream release
- remove preloading libdl.so (in glibc-devel) from socksify

* Mon Dec 02 2002 NISHIMURA Daisuke <nishi@graco.c.u-tokyo.ac.jp>
- 1.1.13-0vl0.26.0: built for Vine Linux 2.5/2.6

* Mon Dec 02 2002 NISHIMURA Daisuke <nishi@graco.c.u-tokyo.ac.jp>
- 1.1.13-0vl0.21.0: built for Vine Linux 2.1.x
- new upstream release:
  dante-config_parse.patch and dante-recvmsg.patch are incorporated.
- set noreplace flag to sock{s,d}.conf
- remove BuildPreReq: flex

* Mon May 13 2002 NISHIMURA Daisuke <nishi@graco.c.u-tokyo.ac.jp>
- 1.1.12-0vl7: built for Vine Linux 2.5

* Mon May 13 2002 NISHIMURA Daisuke <nishi@graco.c.u-tokyo.ac.jp>
- 1.1.12-0vl6: built for Vine Linux 2.1.x
- change dante-recvmsg.patch to fix core dump with libdsocks

* Wed Apr 24 2002 NISHIMURA Daisuke <nishi@graco.c.u-tokyo.ac.jp>
- 1.1.12-0vl5: built for Vine Linux 2.5

* Sat Apr 20 2002 NISHIMURA Daisuke <nishi@graco.c.u-tokyo.ac.jp>
- 1.1.12-0vl4: built for Vine Linux 2.1.x
- replaced source with full-release of 1.1.12.
- replaced dante-recvmsg.patch with one from original author
- added dependencies (pam, tcp_wrappers)

* Sun Mar 31 2002 Jun Nishii <jun@vinelinux.org>
- 1.1.12-0vl3: rebuild for Vine Linux 2.5

* Mon Mar 18 2002 NISHIMURA Daisuke <nishi@graco.c.u-tokyo.ac.jp>
- 1.1.12-0vl2: patch to include/{common,sockd}.h

* Thu Feb 14 2002 NISHIMURA Daisuke <nishi@graco.c.u-tokyo.ac.jp>
- 1.1.12-0vl1: updated to 1.1.12-pre1 and modified spec for pre-releases

* Mon Feb 11 2002 NISHIMURA Daisuke <nishi@graco.c.u-tokyo.ac.jp>
- 1.1.11-0vl2: patch to lib/config_parse.y

* Fri Dec 14 2001 NISHIMURA Daisuke <nishi@graco.c.u-tokyo.ac.jp>
- 1.1.11-0vl1

* Sat Nov 10 2001 akira yamada <akira@vinelinux.org> 1.1.10-0vl2
- moved libsocs.so to dante-devel from dante.
- added defattr for dante-devel.
- added BuildPreReq: flex

* Thu Sep 06 2001 Toru Sagami <sagami@vinelinux.org>
- 1.1.10-0vl1: updated to 1.1.10 with a bit better macros and minor spec fixes
- fixed Group

* Fri May 18 2001 MATSUBAYASHI 'Shaolin' Kohji <shaolin@vinelinux.org>
- 1.1.9-1vl1
- based on 1.1.9-1 generated from original tarball (by rpm -ts)
- rebuilt for Vine Linux
- modified spec file

* Thu Oct 12 2000 Karl-Andre' Skevik <karls@inet.no>
-use of macros for directory locations/paths
-explicitly name documentation files
-run chkconfig --del before files are deleted on uninstall

* Wed Mar 10 1999 Karl-Andre' Skevik <karls@inet.no>
- Integrated into CVS
- socksify patch no longer needed

* Thu Mar 04 1999 Oren Tirosh <oren@hishome.net>
- configurable %{prefix}, fixed daemon init script
- added /lib/libdl.so to socksify

* Wed Mar 03 1999 Oren Tirosh <oren@hishome.net>
- First spec file for Dante