File tsocks-1.8.spec of Package tsocks

# $Id: tsocks.spec 201 2004-04-03 15:24:49Z dag $

# Authority: dag

%define real_version 1.8beta5

Summary: library to allow transparent SOCKS proxying
Name: tsocks
Version: 1.8
Release: beta5.bmw1
License: GPL
Group: Applications/Internet
URL: http://tsocks.sf.net/
Patch: http://lysithea.members.selfnet.de/code/tsocks-1.8beta5-socks4a.diff
Patch2: libc.patch
BuildRequires: autoconf
BuildRequires: automake

Packager: Bernhard M. Wiedemann <tsocksopensuse20080405@bmw.lsmod.de>

Source: http://dl.sf.net/tsocks/tsocks-%{real_version}.tar.gz
BuildRoot: %{_tmppath}/%{name}-%{version}-%{release}-root


%description
tsocks is a library to allow transparent SOCKS proxying. It supports SOCKS 4, SOCKS 4a and SOCKS 5 (only TCP).

tsocks is designed for use in machines which are firewalled from
the internet. It avoids the need to recompile applications like lynx
or telnet so they can use SOCKS to reach the internet. It behaves
much like the SOCKSified TCP/IP stacks seen on other platforms.

%prep
%setup
%patch -p1
%patch2 -p1
autoreconf

%{__cat} <<'EOF' >tsocks
#!/bin/sh

### A wrapper script for the tsocks(8) transparant socksification library.
### Written by Dag Wieers <dag@wieers.com>.
###
### There are 3 modes of operandi:
###
###  * tsocks <program> <args ...>
###
###    This will socksify the current program only.
###    eg.
###         [user@host ~]# tsocks telnet www.foo.org
###
###  * tsocks [on|off]
###
###    This will socksify the current shell (and childs).
###    eg.
###         [user@host ~]# source /usr/bin/tsocks on
###         (user@host ~)# telnet www.foo.org
###         [user@host ~]# source /usr/bin/tsocks off
###
###  * tsocks
###
###    This will create a new socksified shell.
###    eg.
###         [user@host ~]# tsocks
###         (user@host ~)$ telnet www.foo.org
###         (user@host ~)$ exit
###         [user@host ~]#

PRG="$(basename $0)"
LIB="%{_libdir}/libtsocks.so"

function set_socks {
	if [ -z "$LD_PRELOAD" ]; then
		export LD_PRELOAD="$LIB"
	elif ! echo "$LD_PRELOAD" | grep -q "$LIB"; then
		export LD_PRELOAD="$LIB $LD_PRELOAD"
	fi
}

function unset_socks {
	export LD_PRELOAD="$(echo -n "$LD_PRELOAD" | sed "s|$LIB \?||")"
	if [ -z "$LD_PRELOAD" ]; then
		export -n LD_PRELOAD
	fi
}


case "$1" in
	on)	set_socks;;
	off)	unset_socks;;
	show|sh)
		if echo "$LD_PRELOAD" | grep -q "$LIB"; then
			echo "$PRG: This shell is socksified."
		else
			echo "$PRG: This shell is NOT socksified."
		fi
		;;
	-h|-?)	echo "$PRG: Please see tsocks(1) or read comment at top of $0"
		exit 1
		;;
	'')
		set_socks
#		PS1="$(echo -n "$PS1" | tr \[\] \(\)) " ${SHELL:-/bin/sh};;
		PS1="(\u@\h \W)\$ " ${SHELL:-/bin/sh}
		;;
	*)	set_socks
		exec "$@"
		;;
esac
EOF

# This file is embedded here instead of being another source in order
# to the prefix directory
%{__cat} <<'EOF' >tsocksify.sysv
#!/bin/bash
#
# Startup script to transparantly socksify your system using tsocks.
#
# Written by Dag Wieers <dag@wieers.com>.
#
### BEGIN INIT INFO
# Provides:                     tsocksify
# Required-Start:               $local_fs $remote_fs $network
# Should-Start:                 $syslog $time $named network-remotefs
# Required-Stop:                $local_fs $remote_fs $network
# Should-Stop:                  $syslog $time $named network-remotefs
# Default-Start:                3 5
# Default-Stop:                 0 1 2 6
# Short-Description:            tsocksify
# Description:                  tsocksify
### END INIT INFO
#
# chkconfig: - 89 11
# description: Tsocksify is a means to socksify your system transparantly \
#	(using tsocks) on start-up after the network is up and running.
#
# processname: tsocksify
#
# config: %{_sysconfdir}/tsocks.conf
# config: /etc/ld.so.preload

source %{_initrddir}/functions

[ -r %{_sysconfdir}/tsocks.conf -a -x %{_libdir}/libtsocks.so ] || disable

RETVAL=0
prog="tsocks"

disable() {
	echo "Warning: your installation is faulty."
	stop
	exit 1
}

start() {
	echo -n $"Socksifying system ($prog): "
	grep "%{_libdir}/libtsocks.so" /etc/ld.so.preload &>/dev/null
	ret=$?
	if [ ! -f /etc/ld.so.preload -o $ret -ne 0 ]; then
		echo "%{_libdir}/libtsocks.so" >>/etc/ld.so.preload
		success $"tsocksify startup"
	elif [ $ret -eq 0 ]; then
		passed $"tsocksify startup"
	else
		failure $"tsocksify startup"
	fi
	RETVAL=$?
	echo
	return $RETVAL
}

stop() {
	echo -n "Unsocksifying system ($prog): "
	grep "%{_libdir}/libtsocks.so" /etc/ld.so.preload &>/dev/null
	if [ $? -eq 0 ]; then
		cat /etc/ld.so.preload | grep -v "%{_libdir}/libtsocks.so" >/etc/ld.so.preload.cache
		mv -f /etc/ld.so.preload.cache /etc/ld.so.preload
		success $"tsocksify shutdown"
	else
		failure $"tsocksify shutdown"
	fi
	RETVAL=$?
	if [ ! -s /etc/ld.so.preload ]; then
		rm -f /etc/ld.so.preload
	fi
	echo
	return $RETVAL
}

restart() {
        stop
        start
}

case "$1" in
  start)
	start
	;;
  stop)
	stop
	;;
  restart|reload)
	restart
	;;
  *)
	echo $"Usage: $0 {start|stop|restart}"
	exit $RETVAL
esac

exit $RETVAL
EOF

%build
%configure
%{__make} %{?_smp_mflags}

%install
%{__rm} -rf %{buildroot}
%{__install} -d -m0755 %{buildroot}%{_sysconfdir} \
			%{buildroot}%{_initrddir}
%makeinstall
%{__install} -m0644 tsocks.conf.simple.example %{buildroot}%{_sysconfdir}/tsocks.conf
%{__install} -m0755 tsocksify.sysv %{buildroot}%{_initrddir}/tsocksify
%{__ln_s} -f tsocks %{buildroot}%{_bindir}/tsocksify

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

%post 
#/sbin/ldconfig 2>/dev/null
#/sbin/chkconfig --add tsocksify

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

%postun 
/sbin/ldconfig 2>/dev/null
/sbin/service tsocksify condrestart > /dev/null 2>&1 || :

%files
%defattr(-, root, root, 0755)
%doc ChangeLog COPYING tsocks.conf.simple.example tsocks.conf.complex.example
%doc %{_mandir}/man?/*
%config(noreplace) %{_sysconfdir}/tsocks.conf
%config %{_initrddir}/tsocksify
%{_bindir}/*
%{_libdir}/*

%changelog
* Fri Apr 21 2006 Bernhard M. Wiedemann <tsocksbuild@bmw.lsmod.de> - bmw1
- adapted for openSUSE

* Mon Dec 16 2002 Dag Wieers <dag@wieers.com> - 1.8-6.beta5
- Rewrote tsocks/tsocksify script.
- Don't replace config files.

* Mon Dec 16 2002 Dag Wieers <dag@wieers.com> - 1.8beta5
- Updated tsocksify script and embedded it in SPEC file.

* Fri Jul 12 2002 Dag Wieers <dag@wieers.com> - 1.8beta4
- Added tsocksify SysV script.
- Added pre/post install scripts.
- Omitted INSTALL.

* Tue Jul 09 2002 Dag Wieers <dag@wieers.com> - 1.7
- Initial package.
openSUSE Build Service is sponsored by