#! /bin/sh
# prefix command to run stuff from our programs directory
# Copyright (C) 1998, 1999, 2000, 2001  Henry Spencer.
# 
# This program is free software; you can redistribute it and/or modify it
# under the terms of the GNU General Public License as published by the
# Free Software Foundation; either version 2 of the License, or (at your
# option) any later version.  See <http://www.fsf.org/copyleft/gpl.txt>.
# 
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
# or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
# for more details.
#
# RCSID $Id: ipsec,v 1.1.1.1 2004/04/07 09:06:48 louistsai Exp $

# where the private directory is
IPSEC_DIR=/usr/local/lib/ipsec
export IPSEC_DIR

# standardize PATH, and export it for everything else's benefit
PATH=/usr/local/sbin:/sbin:/usr/sbin:/usr/local/bin:/bin:/usr/bin
export PATH

# things not to be listed in --help command list
DONTMENTION='^(ipsec|_.*|.*\.old)$'

# version numbering (details filled in by build)
# Possibly should call a C program to invoke the version_code() function
# instead, but for performance's sake, we inline it here (and only here).
version="1.93"

# export the version information
IPSEC_VERSION="$version"
export IPSEC_VERSION

# function for the funky user/kernel version stuff
fixversion() {
	if test -f /proc/net/ipsec_version
	then
		kv="`awk '{print $NF}' /proc/net/ipsec_version`"
		if test " $kv" != " $version"
		then
			version="U$version/K$kv"
		fi
	fi
}

case "$1" in
--help|'')
	echo "Usage: ipsec command argument ..."
	echo "where command is one of:"
	ls $IPSEC_DIR | egrep -v -i "$DONTMENTION" | sed 's/^/	/'
	echo
	echo "Most of these have their own manual pages, e.g. ipsec_auto(8)."
	echo "See also <http://www.freeswan.org> or the ipsec(8) manual page."
	exit 0
	;;
--version)
	fixversion
	echo "Linux FreeS/WAN $version"
	echo "See \`ipsec --copyright' for copyright information."
	exit 0
	;;
--versioncode)
	fixversion
	echo "$version"
	exit 0
	;;
--copyright)
	set _copyright
	# and fall through, invoking "ipsec _copyright"
	;;
--directory)
	echo "$IPSEC_DIR"
	exit 0
	;;
--*)
	echo "$0: unknown option \`$1' (perhaps command name was omitted?)" >&2
	exit 1
	;;
esac

cmd="$1"
shift
path="$IPSEC_DIR/$cmd"

if test ! -x "$path"
then
	echo "$0: unknown IPsec command \`$cmd' (\`ipsec --help' for list)" >&2
	exit 1
fi
$path "$@"
