#!/bin/sh
# bin-tc.sh : test case for /bin directory

##########################################################################
# (C) Copyright 1998-2001 The Open Group
#
# All rights reserved.  No part of this source code may be reproduced,
# stored in a retrieval system, or transmitted, in any form or by any
# means, electronic, mechanical, photocopying, recording or otherwise,
# except as stated in the end-user licence agreement, without the prior
# permission of the copyright owners.
#
# X/Open and the 'X' symbol are trademarks of X/Open Company Limited in
# the UK and other countries.
#
#	PROJECT:	LSB-FHS
#	PRODUCT:	LSB.fhs/root/sbin/sbin-tc.sh
#	AUTHOR:		Andrew Josey, The Open Group
#	DATE CREATED:	21 Dec 1998
##########################################################################

# This is $Revision: 1.10 $
#
# $Log: sbin-tc.sh,v $
# Revision 1.10  2004/02/12 14:04:05  ajosey
# update many FIP results to UNSUPPORTED
#
# Revision 1.9  2004/02/12 13:57:19  ajosey
# renumber assertions for LSB2.0/FHS2.3
#
# Revision 1.8  2002/09/23 13:43:05  ajosey
# tps 3,17 and 18 now return UNSUPPORTED rather than FIP
#
# Revision 1.7  2001/08/14 14:35:04  ajosey
# update the assertion numbers for FHS2.2
#
# Revision 1.6  2001/07/27 08:32:00  ajosey
# missing FAIL=N for FIP cases
#
# Revision 1.5  2001/07/20 11:34:14  ajosey
# add in more diagnostics
#
# Revision 1.4  2001/07/20 10:56:43  ajosey
# update UNSUPPORTED to FIP result codes
#
# Revision 1.3  2001/07/18 15:26:00  ajosey
# further alignment of tests for FHS2.2
#
# Revision 1.2  2001/07/17 16:52:25  ajosey
# add header, put back in cvs revision stuff, and mark tp2 as not in use for FHS2.2
#
#
# -- old cvs history below --
#
# This is 1.6
#
# sbin-tc.sh,v
# Revision 1.6  2000/04/18 08:24:33  cyeoh
# Changes tp2 (hwclock) to not test standard output/error as
# behaviour differs across distributions
#
# Revision 1.5  2000/04/17 07:05:45  ajosey
# add tests 17-20
#
# Revision 1.4  2000/04/14 10:19:00  ajosey
# update 3.14-2 for FHS2.1, /sbin/clock->/sbin/hwclock, update 3.14-9, this test no longer applicable in FHS2.1, now gives NOTINUSE result code
#
# Revision 1.3  2000/04/10 04:17:24  cyeoh
# Made tp5 (update) and tp16 (route) more distribution portable
#
# Revision 1.2  2000/04/09 07:15:32  cyeoh
# Added CVS header information
#
#

tet_startup="startup"			# startup function
tet_cleanup="cleanup"			# cleanup function
iclist="ic1 ic2 ic3 ic4 ic5 ic6 ic7 ic8 ic9 ic10 ic11 ic12 ic13 ic14 ic15 ic16 ic17 ic18 ic19 ic20"
ic1="tp1"
ic2="tp2"
ic3="tp3"
ic4="tp4"
ic5="tp5"
ic6="tp6"
ic7="tp7"
ic8="tp8"
ic9="tp9"
ic10="tp10"
ic11="tp11"
ic12="tp12"
ic13="tp13"
ic14="tp14"
ic15="tp15"
ic16="tp16"
ic17="tp17"
ic18="tp18"
ic19="tp19"
ic20="tp20"


tp1()
{
	tpstart "Reference 3.15-1(A)"
	tet_infoline "The /sbin directory exists and is searchable"
	lsb_test_dir_searchable /sbin >out.stdout  2>out.stderr
	check_exit_value $? 0		# should be zero
	check_nostdout			# should be no stdout
	check_nostderr			# should be no stderr
	tpresult			# set result code
}


# 14 Apr 2000
# change clock to hwclock for FHS2.1 alignment
# now removed in FHS2.2
#

tp2() 
{
	tpstart "Reference 3.15-2 (A)"
	tet_infoline "The implementation provides an exec-able version of the hwclock"
	tet_infoline "Note: not in use in FHS 2.2"
	tpresult NOTINUSE

#	tet_infoline "utility in the /sbin directory. "
#	lsb_test_exec /sbin/hwclock >out.stdout 2>out.stderr 
#	check_exit_value $? 0
#	tpresult			# set result code
}


tp3() 
{
	tpstart "Reference 3.15-3 (C)"
	tet_infoline "The implementation may provide an exec-able version of the getty"
	tet_infoline "utility in the /sbin directory. "

	if ! test -x /sbin/getty
	then
		tet_infoline "/sbin/getty not found. "
		FAIL=N
		tpresult UNSUPPORTED
		return
	fi
	tpresult			# set result code
}


tp4() 
{
	tpstart "Reference 3.15-4 (C)"
	tet_infoline "The implementation may provide an exec-able version of the init"
	tet_infoline "utility in the /sbin directory. "

	if ! test -x /sbin/init
	then
		tet_infoline "/sbin/init not found or not executable. "
		FAIL=N
		tpresult UNSUPPORTED
		return
	fi
	tpresult			# set result code
}


tp5() 
{
	tpstart "Reference 3.15-5 (C)"
	tet_infoline "The implementation may provide an exec-able version of the update"
	tet_infoline "utility in the /sbin directory. "

	# when /sbin/update is not called by superuser, its calls
	# flush() and sync()
	# Can't run the program as some versions of update
	# output to standard output with a message concerning
        # running as root as well as returning a non zero exit code
	# so we don't really know if it worked.
	# Instead we just test that its executable
	lsb_test_exec /sbin/update >out.stdout 2>out.stderr 
	if ! test -x /sbin/update
	then
		tet_infoline "/sbin/update not found or not executable. "
		FAIL=N
		tpresult UNSUPPORTED
		return
	fi
	tpresult			# set result code
}


tp6() 
{
	tpstart "Reference 3.15-6 (C)"
	tet_infoline "The implementation may provide an exec-able version of the mkswap"
	tet_infoline "utility in the /sbin directory. "

	if ! test -x /sbin/mkswap
	then
		tet_infoline "/sbin/mkswap not found or not executable. "
		FAIL=N
		tpresult UNSUPPORTED
		return
	fi
	tpresult			# set result code
}


tp7() 
{
	tpstart "Reference 3.15-7 (C)"
	tet_infoline "The implementation may provide an exec-able version of the swapon"
	tet_infoline "utility in the /sbin directory. "
	# call with -V for version
	lsb_test_exec /sbin/swapon -V >out.stdout 2>out.stderr 
	check_exit_value $? 0		
	check_stdout			# should be stdout
	check_nostderr			# should be stderr
	if [ $FAIL = Y ]
	then
		FAIL=N
		tpresult UNSUPPORTED
		return
	fi
	tpresult			# set result code
}


tp8() 
{
	tpstart "Reference 3.15-8 (C)"
	tet_infoline "The implementation may provide an exec-able version of the swapoff"
	tet_infoline "utility in the /sbin directory. "
	if ! test -x /sbin/swapoff
	then
		FAIL=N
		tet_infoline "/sbin/swapoff not found or not executable. "
		tpresult UNSUPPORTED
		return
	fi
	tpresult			# set result code
}


tp9() 
{
	tpstart "Reference 3.15-9 (A)"
	tet_infoline "The implementation provides an exec-able version of the telinit"
	tet_infoline "utility in the /sbin directory. "
	tet_infoline "This requirement is withdrawn in FHS2.1"
# this requirement withdrawn in FHS2.1
#	if ! test -x /sbin/telinit
#	then
#		FAIL=Y
#		tpresult
#		return
#	fi
#	lsb_test_exec /sbin/telinit >out.stdout 2>out.stderr 
#	check_exit_value $? 1
#	check_nostdout			# should be no stdout
#	check_stderr			# should be stderr
	tpresult NOTINUSE		# set result code
}


tp10() 
{
	tpstart "Reference 3.15-10 (A)"
	tet_infoline "The implementation provides an exec-able version of the shutdown"
	tet_infoline "utility in the /sbin directory. "

	if ! test -x /sbin/shutdown
	then
		FAIL=Y
	fi
	tpresult			# set result code
}


tp11() 
{
	tpstart "Reference 3.15-11 (C)"
	tet_infoline "The implementation may provide an exec-able version of the fdisk"
	tet_infoline "utility in the /sbin directory. "
	if ! test -x /sbin/fdisk
	then
		FAIL=N
		tpresult UNSUPPORTED
		return
	fi
	tpresult			# set result code
}


tp12() 
{
	tpstart "Reference 3.15-12 (C)"
	tet_infoline "The implementation may provide an exec-able version of the fsck"
	tet_infoline "utility in the /sbin directory. "
	if ! test -x /sbin/fsck
	then
		FAIL=N
		tpresult UNSUPPORTED
		return
	fi
	tpresult			# set result code
}


tp13() 
{
	tpstart "Reference 3.15-13 (C)"
	tet_infoline "The implementation  may provide an exec-able version of the mkfs"
	tet_infoline "utility in the /sbin directory. "
	if ! test -x /sbin/mkfs
	then
		FAIL=N
		tpresult UNSUPPORTED
		return
	fi
	tpresult			# set result code
}


tp14() 
{
	tpstart "Reference 3.15-14 (C)"
	tet_infoline "The implementation may provide an exec-able version of the mkfs.*"
	tet_infoline "utility in the /sbin directory. "
	tet_infoline "Where * is one or more of ext, ext2, minix, msdos, xia and or others unspecified. "
	for tfile in /sbin/mkfs.*
	do
		tet_infoline "Testing: $tfile"
		if ! test -x $tfile
		then
			FAIL=Y
		fi
	done
	if [ $FAIL = Y ]
	then
		FAIL=N
		tpresult UNSUPPORTED
		return
	fi
	tpresult			# set result code
}


tp15() 
{
	tpstart "Reference 3.15-15 (C)"
	tet_infoline "The implementation may provide an exec-able version of the ifconfig"
	tet_infoline "utility in the /sbin directory. "
	lsb_test_exec /sbin/ifconfig >out.stdout 2>out.stderr 
	check_exit_value $? 0
	check_stdout lo			# should lo in stdout
	check_nostderr			# should be no stderr
	if [ $FAIL = Y ]
	then
		FAIL=N
		tpresult UNSUPPORTED
		return
	fi
	tpresult			# set result code
}


tp16() 
{
	tpstart "Reference 3.15-16 (C)"
	tet_infoline "The implementation may provide an exec-able version of the route"
	tet_infoline "utility in the /sbin directory. "
	lsb_test_exec /sbin/route >out.stdout 2>out.stderr 
	check_exit_value $? 0
	check_nostderr			# should be no stderr
	if [ $FAIL = Y ]
	then
		FAIL=N
		tpresult UNSUPPORTED
		return
	fi
	tpresult			# set result code
}

tp17() 
{
	tpstart "Reference 3.15-17 (C)"
	tet_infoline "The implementation may provide an exec-able version of the fastboot"
	tet_infoline "utility in the /sbin directory. "
# unwise to call fastboot directly
#lsb_test_exec /sbin/fastboot >out.stdout 2>out.stderr 
	if ! test -x /sbin/fastboot
	then
		FAIL=N
		tet_infoline "/sbin/fastboot: file does not exist or is not executable"
		tpresult UNSUPPORTED
		return
	fi
	tpresult			# set result code
}

tp18() 
{
	tpstart "Reference 3.15-18 (C)"
	tet_infoline "The implementation may provide an exec-able version of the fasthalt"
	tet_infoline "utility in the /sbin directory. "
# unwise to call fasthalt directly
#lsb_test_exec /sbin/fasthalt >out.stdout 2>out.stderr 
	if ! test -x /sbin/fasthalt
	then
		FAIL=N
		tet_infoline "/sbin/fasthalt: file does not exist or is not executable"
		tpresult UNSUPPORTED
		return
	fi
	tpresult			# set result code
}

tp19() 
{
	tpstart "Reference 3.15-19 (C)"
	tet_infoline "The implementation may provide an exec-able version of the halt"
	tet_infoline "utility in the /sbin directory. "
# unwise to call halt directly
#lsb_test_exec /sbin/halt >out.stdout 2>out.stderr 
	if ! test -x /sbin/halt
	then
		FAIL=N
		tet_infoline "/sbin/halt: file does not exist or is not executable"
		tpresult UNSUPPORTED
		return
	fi
	tpresult			# set result code
}

tp20() 
{
	tpstart "Reference 3.15-20 (C)"
	tet_infoline "The implementation may provide an exec-able version of the reboot"
	tet_infoline "utility in the /sbin directory. "
# unwise to call reboot directly
#lsb_test_exec /sbin/reboot >out.stdout 2>out.stderr 
	if ! test -x /sbin/reboot
	then
		FAIL=N
		tet_infoline "/sbin/reboot: file does not exist or is not executable"
		tpresult UNSUPPORTED
		return
	fi
	tpresult			# set result code
}

startup() # startup function
{
     rm -f out.stdout out.stderr out.experr >/dev/null 2>&1
}


cleanup() # clean-up function
{
     rm -f out.stdout out.stderr out.experr >/dev/null 2>&1
}

# source common shell functions

. $TET_EXECUTE/LIB/shfuncs.sh
. $TET_EXECUTE/LIB/lsbfuncs.sh

# execute shell test case manager - must be last line
. $TET_ROOT/lib/xpg3sh/tcm.sh
