#!/bin/ash
#
#POSIXness v0.50 20000812
#GPL2 -- Dave 'Kill a Cop' Cinege <dcinege@psychosis.com>
#
#Uses the fullest extent of ash, sed, and custom busybox functions
#to provide many of the linux goodies that will not fit on boot
#floppies. Helps give you that 'real machine' feel...
#
#Some of the sed code is stolen from various FAQ's, etc
#
#Some of these functions are LRP oddites, you probably can't use.

# This script is dedicated to Phil Hands and Paul Russell 
# I hope to amaze and inspire people with the power of the bourne
# shell the same way you guys did for me when I was just a lowly 
# scumbag neophyte begging for a clue. 
# Much thanks for your continuing help with LRP.

# Intial script splitup and many additions by 
# Charles Steinkuehler <cstein@newtek.com>


OIFS=$IFS
TAB='	'
SP=' '
CR='
'
LF='
'

MASTCONF="/etc/POSIXness.conf"

POSIXdir="/lib/POSIXness"
[ -f "$MASTCONF" ] && source $MASTCONF

#POSIXdir="./lib/"	# Dev machine

qt () { "$@" >/dev/null 2>&1 ; }

source () { . $@ ; }

eecho () {	#usr/bin
	echo "$@" >/dev/null >&2
}

singlefilearg () {

	[ "$1" = "" ] && eecho "Usage: $prog file" && exit 1
	[ ! -f "$1" ] && eecho "$1: No such file or directory" && exit 1
}

LSLINKS () {
sed -n '/^.*[ +|	+]().*#/{h; s/\(.*\)[ +|	+]().*/\/\1/; 
x; G; s/.*#\(.*\>\)\n/\1/; p; }' $0 $POSIXdir/POSIXness.*

}

MAKELINKS () {
	for d in $(LSLINKS); do
		ln -s "$0" "/$d"
	done
}


##
#main ()
#{
##

prog=${0##*/}

	[ $prog = "POSIXness" ] && [ $# -gt 0 ] && prog="$1" && shift

case $prog in 

	eecho|LSLINKS|MAKELINKS)
		$prog "$@"  ;;
	help|lrpkg|mount.boot|svi|update-rc.d)
		source $POSIXdir/POSIXness.linuxrouter
		$prog "$@"  ;;
	mail)
		source $POSIXdir/POSIXness.mail
		$prog "$@"  ;;
	expr|finger|free|getservbyname|groupadd|groupdel|groupmod|\
	printenv|uname|useradd|userdel|usermod)
		source $POSIXdir/POSIXness.system
		$prog "$@"  ;;
	basename|cut|dirname|grep|head|\
	necho|nl|sort|tail|uniq|zmore|zgrep)
		source $POSIXdir/POSIXness.text
		$prog "$@"  ;;
	id|last|lsmod|pauseme|reset|uptime|w|who|whoami)
		source $POSIXdir/POSIXness.system
		$prog  ;;
	*)	
		eecho "No function defined for '$prog'"
		exit 1  ;;	
esac
exit $?
	
##
#}
##
