#!/bin/ksh
#
# A simple wrapper to teach default versions of OpenSolaris 
# commands to folks used to other commands. Of course, the user
# could set $PATH appropriately, or create symlink farms,
# but in the meantime, perhaps this will do.
#


# to install, add this file to a directory, and create symlinks
# for the commands you want this script to replace, eg.
#
# ln -s command-wrapper.ksh ps
# ln -s command-wrapper.ksh tar
# ln -s command-wrapper.ksh top
# etc.
#
# Then pop this at the top of your path.
#




#
# A master replacement command table that calls functions to
# handle each command varient.
#
function sub_command {

	cmd=$1
	case $cmd in
	tar)
		handle_tar $@
		;;
	ps)	
		handle_ps $@
		;;
	top)
		handle_top $@
		;;
	*)
		echo "no match"
		;;
	esac
		
}



#
# Print a warning message saying the command has different
# syntax on a default OpenSolaris install
#
function print_unsupported {
	echo "The command \"$@\" is unavailable or has different"
	echo "different syntax in OpenSolaris."
	echo "You might want to use the following instead - "

}


#
# A function that handles common tar arguments that aren't
# in the default tar that ships with Solaris.
#
function handle_tar {

	arg=$2
	case $arg in

	gxvf|xgvf)
		print_unsupported $@
		echo "example:  gunzip -c [file.tar.gz] | tar xvf -"
		echo ""
		echo "See the tar(1) man page for more information."
		;;
	gxf|xgf)
		print_unsupported $@
		echo "example: gunzip -c [file.tar.gz] | tar xf -"
		echo ""
		echo "See the tar(1) man page for more information."
		;;	
	gcf|cgf)
		print_unsupported $@
		echo "example: tar cf - [files] | gzip -c > file.tar.gz"
		echo ""
		echo "See the tar(1) man page for more information."
		;;
	gxcf|xgcf|cgvf|cgfv|cvgf)
		print_unsupported $@
		echo "For OpenSolaris, use:"
		echo "Example: tar cvf - [files] | gzip -c > file.tar.gz"
		echo ""
		echo "See the tar(1) man page for more information."
		;;
	*)
		shift
		/usr/bin/tar $*
		exit $?
		;;
	esac
}


#
# A function that handles common ps arguments that aren't in
# the default ps that ships with Solaris.
#
function handle_ps {

	arg=$2
	case $arg in

	aux|xua|axu)
		print_unsupported $@
		echo "Example: ps -ef"
		echo ""
		echo "See the ps(1) or pargs(1) man page for more information."
		;;
	*)
		shift
		/usr/bin/ps $*
		;;
	esac
}

function handle_top {
	print_unsupported $@
	echo "Example: prstat 1"
	echo ""
	echo "see the prstat(1m) man page for more information."
}


COMMAND=$0
sub_command $(basename $COMMAND) $@
