tests: add test for locale decimal processing
[coreutils.git] / tests / chmod / setgid.sh
blobab1cdc732a92276b1ac42990eaaa367463b27715
1 #!/bin/sh
2 # Make sure GNU chmod works the same way as those of Solaris, HPUX, AIX
3 # on directories with the setgid bit set. Also, check that the GNU octal
4 # notations work.
6 # Copyright (C) 2001-2019 Free Software Foundation, Inc.
8 # This program is free software: you can redistribute it and/or modify
9 # it under the terms of the GNU General Public License as published by
10 # the Free Software Foundation, either version 3 of the License, or
11 # (at your option) any later version.
13 # This program is distributed in the hope that it will be useful,
14 # but WITHOUT ANY WARRANTY; without even the implied warranty of
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 # GNU General Public License for more details.
18 # You should have received a copy of the GNU General Public License
19 # along with this program. If not, see <https://www.gnu.org/licenses/>.
21 . "${srcdir=.}/tests/init.sh"; path_prepend_ ./src
22 print_ver_ chmod
24 umask 0
25 mkdir -m 755 d || framework_failure_
27 chmod g+s d 2> /dev/null && env -- test -g d ||
29 # This is required because on some systems (at least NetBSD 1.4.2A),
30 # it may happen that when you create a directory, its group isn't one
31 # to which you belong. When that happens, the above chmod fails. So
32 # here, upon failure, we try to set the group, then rerun the chmod command.
34 id_g=$(id -g) &&
35 test -n "$id_g" &&
36 chgrp "$id_g" d &&
37 chmod g+s d || framework_failure_
40 # "chmod g+s d" does nothing on some NFS file systems.
41 env -- test -g d ||
42 skip_ 'cannot create setgid directories'
44 for mode in \
45 + - g-s 00755 000755 =755 -2000 -7022 755 0755 \
46 +2000 -5022 =7777,-5022
48 chmod $mode d || fail=1
50 case $mode in
51 g-s | 00*755 | =755 | -2000 | -7022)
52 expected_mode=drwxr-xr-x ;;
53 *) expected_mode=drwxr-sr-x ;;
54 esac
55 ls_output=$(ls -ld d)
56 case $ls_output in
57 $expected_mode*) ;;
58 *) fail=1 ;;
59 esac
61 chmod =2755 d || fail=1
62 done
64 Exit $fail