#!/bin/sh

. ${SRCROOT:=`../../../conf/srcroot.sh`}/tests/bin/base

chmodprog="${CHMODPROG-chmod}"
chownprog="${CHOWNPROG-chown}"
chgrpprog="${CHGRPPROG-chgrp}"

chmodcmd="$chmodprog 0755"
chowncmd=""
chgrpcmd=""
#
# Check if we are 'root' to avoid chown as non root user
#
rootflag=FALSE
dstdir=/tmp/xd.$$
dsttmp=${dstdir}/xx.$$
#trap "rm -f ${dsttmp}; rm -rf ${dstdir}" 0
mkdir ${dstdir}
${chmodcmd} ${dstdir}
echo > ${dsttmp}
${chownprog} root ${dsttmp} 2> /dev/null && ${chmodcmd} ${dsttmp} 2> /dev/null && rootflag=TRUE
#
# Win95 has no user 'root' and chown succeeds always.
# Unfortunately, there is also no user 'bin' and chown complains about
# user 'bin' being non-existant.
# Check if the file is now really owned by 'root' to avoid the Win95 probems
#
if [ $rootflag = TRUE ]; then
	ls -l ${dsttmp} 2> /dev/null | grep root > /dev/null || rootflag=FALSE
fi
rm -f ${dsttmp}
rm -rf ${dstdir}

if test $rootflag = TRUE
then
	if [ ."${FORCE_ROOT}" = .true ]; then
		:
	else
		xfail "Please do not run the suite as root"
	fi
fi
