#!/bin/sh
# simple shell script wrapper for lsb-test-pam
# Stew Benedict <sbenedict@mandrakesoft.com>
# 12/30/2004 - 1st version 0.1
# 2/16/2005 - move common functions - 0.2

RPMPKG=lsb-test-pam
CONFLICT=lsb-runtime-test

# source common-functions
. /usr/share/lsb/common-functions

install_rpm lsb

remove_conflict $CONFLICT

retrieve_rpm $RPMPKG

# (sb) we have to expose the password of vsx{0,1,2}
# also we can't drive the last 2 bits via script 
# due to su refusing the root passwd from a file
# we get around that by running the runtime-config script
# while we're still root and alias su to /bin/true for vsx0

echo $VSX0_PASS | passwd --stdin vsx0 > /dev/null
echo $VSX1_PASS | passwd --stdin vsx1 > /dev/null
echo $VSX2_PASS | passwd --stdin vsx2 > /dev/null

# (sb) not defined under cron
TMP=$HOME/tmp
HOME=$TET_HOME
rm -f $TET_HOME/.configured
rm -f $TET_HOME/TESTROOT/tetexec.cfg.old
echo "y" | $TET_HOME/scripts/lsb-pam/runtime-config.sh > /dev/null

TMPFILE=`mktemp $TMP/pam.XXXXXX` || exit 1
cat << EOF > $TMPFILE
$TEST_USER
$TEST_ORG
$TEST_SYS
$BLK_DEV
vsx0
$VSX0_PASS
$VSX1_PASS
$VSX2_PASS
y
EOF

chmod 0644 $TMPFILE
mv $TMPFILE $TET_HOME/tmp
TMPFILE=`echo $TMPFILE | sed 's|/root|/home/tet/test_sets|'`

cat << EOF > $TET_HOME/../bin/su
#!/bin/sh
/bin/true
EOF
chmod +x $TET_HOME/../bin/su

JOURNAL=`su - vsx0 run_tests < $TMPFILE | grep 'journal file is' | awk '{print $5}'`

clean_file $TET_HOME/../bin/su
clean_file $TMPFILE

report_results $JOURNAL

