Merge commit 'a39d4083cab589d7cd6a13e8a4b8db8875261d75'
[gnulib.git] / tests / test-idpriv-droptemp.sh
1 #!/bin/sh
2
3 # A POSIX compliant 'id' program.
4 if test -f /usr/xpg4/bin/id; then
5   ID=/usr/xpg4/bin/id
6 else
7   ID=id
8 fi
9
10 # The user's original uid and gid.
11 uid=`$ID -u`
12 gid=`$ID -g`
13
14 if test `$ID -u` = 0; then
15   # No need to ask for a password.
16   "${srcdir}/test-idpriv-droptemp.su.sh" "$uid" "$gid"
17 else
18   echo "Need root privileges for the 'test-idpriv-droptemp' test. Deny if you don't trust." > /dev/tty
19   if (type sudo) > /dev/null 2>&1; then
20     # Use the 'sudo' program.
21     sudo "${srcdir}/test-idpriv-droptemp.su.sh" "$uid" "$gid"
22   else
23     # Use the 'su' program.
24     su root -c "${srcdir}/test-idpriv-droptemp.su.sh \"$uid\" \"$gid\""
25   fi
26   result=$?
27   case $result in
28     0)  exit 0;;
29     77) exit 77;;
30     13) exit 1;;
31     *)  echo "Skipping test: root privileges not granted"; exit 77;;
32   esac
33 fi