Add/fix copyright notices and adjust to latest GNU FDL.
[platform/upstream/coreutils.git] / tests / chgrp / basic
1 #!/bin/sh
2 # make sure chgrp is reasonable
3
4 # Copyright (C) 2000, 2001, 2003, 2004, 2005, 2006 Free Software
5 # Foundation, Inc.
6
7 # This program is free software; you can redistribute it and/or modify
8 # it under the terms of the GNU General Public License as published by
9 # the Free Software Foundation; either version 2 of the License, or
10 # (at your option) any later version.
11
12 # This program is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 # GNU General Public License for more details.
16
17 # You should have received a copy of the GNU General Public License
18 # along with this program; if not, write to the Free Software
19 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
20 # 02110-1301, USA.
21
22 if test "$VERBOSE" = yes; then
23   set -x
24   chgrp --version
25 fi
26
27 . $srcdir/../envvar-check
28 . $srcdir/../lang-default
29 . $srcdir/../group-names
30
31 pwd=`pwd`
32 tmp=basic.$$
33 trap 'status=$?; cd $pwd; rm -rf $tmp && exit $status' 0
34 trap '(exit $?); exit' 1 2 13 15
35
36 framework_failure=0
37 mkdir $tmp || framework_failure=1
38 cd $tmp || framework_failure=1
39
40 if test $framework_failure = 1; then
41   echo 'failure in testing framework' 1>&2
42   (exit 1); exit 1
43 fi
44
45 fail=0
46
47 set _ $groups; shift
48 g1=$1
49 g2=$2
50 mkdir d
51 touch f f2 d/f3
52 chgrp $g1 f || fail=1
53 chgrp $g2 f || fail=1
54 chgrp $g2 f2 || fail=1
55 chgrp -R $g1 d || fail=1
56
57 # Don't let verbose output interfere.
58 test "$VERBOSE" = yes && set +x
59
60 (
61   chgrp -c $g1 f
62   chgrp -c $g2 f
63   chgrp -c $g2 f
64   chgrp --verbose '' f
65   chgrp --verbose $g1 f
66   chgrp --verbose $g1 f
67   chgrp --verbose --reference=f2 f
68   chgrp -R --verbose $g2 d
69   chgrp -R --verbose $g1 d
70   chgrp -R -c $g2 d
71   chgrp -R -c $g1 d
72   chgrp -c $g2 d
73
74   rm -f f
75   touch f
76   ln -s f symlink
77   chgrp $g1 f
78   chgrp -h $g2 symlink
79
80   # This should not change the group of f.
81   chgrp -h -c $g2 symlink
82   chown --from=:$g1 -c :$g2 f
83
84   # This *should* change the group of f.
85   # Though note that the diagnostic is misleading in that
86   # it says the `group of `symlink'' has been changed.
87   chgrp -c $g1 symlink
88   chown --from=:$g1 -c :$g2 f
89
90   # If -R is specified without -H or L, -h is assumed.
91   chgrp -h $g1 f symlink
92   chgrp -R $g2 symlink
93   chown --from=:$g1 -c :$g2 f
94
95   # Make sure we can change the group of inaccessible files.
96   chmod a-r f
97   chown --from=:$g2 -c :$g1 f
98   chmod 0 f
99   chown --from=:$g1 -c :$g2 f
100
101   # chown() must not be optimized away even when
102   # the file's owner and group already have the desired value.
103   rm -f f g
104   touch f g
105   chgrp $g1 f g
106   chgrp $g2 g
107   sleep 1
108   chgrp $g1 f
109
110   # The following no-change chgrp command is supposed to update f's ctime,
111   # but on OpenBSD, it appears to be a no-op for some file system types
112   # (at least NFS) so g's ctime is more recent.  This is not a big deal;
113   # this test works fine when the files are on a local file system (/tmp).
114   chgrp '' f
115   ls -c -t f g
116
117 ) 2>&1 | sed "
118   s/' to .*[^0-9:].*/' to SOMENAME/
119   s/\([ :]\)$g1$/\1G1/
120   s/\([ :]\)$g2$/\1G2/
121 " > actual
122
123 cat <<\EOF > expected
124 changed group of `f' to G1
125 changed group of `f' to G2
126 ownership of `f' retained
127 changed group of `f' to G1
128 group of `f' retained as G1
129 changed group of `f' to SOMENAME
130 changed group of `d/f3' to G2
131 changed group of `d' to G2
132 changed group of `d/f3' to G1
133 changed group of `d' to G1
134 changed group of `d/f3' to G2
135 changed group of `d' to G2
136 changed group of `d/f3' to G1
137 changed group of `d' to G1
138 changed group of `d' to G2
139 changed ownership of `f' to :G2
140 changed group of `symlink' to G1
141 changed ownership of `f' to :G2
142 changed ownership of `f' to :G2
143 changed ownership of `f' to :G1
144 changed ownership of `f' to :G2
145 f
146 g
147 EOF
148
149 cmp expected actual \
150   || { diff expected actual 1>&2; fail=1; }
151
152 (exit $fail); exit $fail