#!/bin/bash

export LANG=C

TEMPDIR=`mktemp -d tests.XXXXXX`

touch $TEMPDIR/passwd
touch $TEMPDIR/shadow
./useradd -G "" -P $TEMPDIR chagetest1 -c "Test account"
./chage -P $TEMPDIR -m 7 -M 92 -d 2000-02-29 -E 2004-02-29 -I 7 -W 14 --service files chagetest1 > tst-chage.run 2>&1
./chage -P $TEMPDIR -l chagetest1 > tst-chage.out1
cat << EOT > tst-chage.expect1
Minimum:	7
Maximum:	92
Warning:	14
Inactive:	7
Last Change:		Feb 29, 2000
Password Expires:	May 31, 2000
Password Inactive:	Jun 07, 2000
Account Expires:	Feb 29, 2004
EOT
diff -q -u tst-chage.expect1 tst-chage.out1
./chage -P $TEMPDIR -m 7 -M 92 -d 2000-02-29 -E 2004-02-29 -I 0 -W 14 --service files chagetest1 > tst-chage.out 2>&1
./chage -P $TEMPDIR -l chagetest1 > tst-chage.out2
RET1=$?
cat << EOT > tst-chage.expect2
Minimum:	7
Maximum:	92
Warning:	14
Inactive:	0
Last Change:		Feb 29, 2000
Password Expires:	May 31, 2000
Password Inactive:	Never
Account Expires:	Feb 29, 2004
EOT
diff -q -u tst-chage.expect2 tst-chage.out2
RET2=$?
rm -rf $TEMPDIR
if [ $RET1 != 0 -o $RET2 != 0 ] ; then
  exit 1
else
  exit 0
fi
