Add/fix copyright notices and adjust to latest GNU FDL.
[platform/upstream/coreutils.git] / tests / chgrp / posix-H
1 #!/bin/sh
2 # Test POSIX-mandated -H option.
3
4 # Copyright (C) 2003, 2004, 2005 Free Software Foundation, Inc.
5
6 # This program is free software; you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation; either version 2 of the License, or
9 # (at your option) any later version.
10
11 # This program is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 # GNU General Public License for more details.
15
16 # You should have received a copy of the GNU General Public License
17 # along with this program; if not, write to the Free Software
18 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
19 # 02110-1301, USA.
20
21 if test "$VERBOSE" = yes; then
22   set -x
23   chgrp --version
24 fi
25
26 . $srcdir/../group-names
27 set _ $groups; shift
28 g1=$1
29 g2=$2
30
31 pwd=`pwd`
32 t0=`echo "$0"|sed 's,.*/,,'`.tmp; tmp=$t0/$$
33 trap 'status=$?; cd $pwd; chmod -R u+rwx $t0; rm -rf $t0 && exit $status' 0
34 trap '(exit $?); exit $?' 1 2 13 15
35
36 framework_failure=0
37 mkdir -p $tmp || framework_failure=1
38 cd $tmp || framework_failure=1
39
40 mkdir 1 2 3 || framework_failure=1
41 touch 1/1F 2/2F 3/3F || framework_failure=1
42 ln -s 1 1s || framework_failure=1
43 ln -s ../3 2/2s || framework_failure=1
44 chgrp -R $g1 1 2 3 || framework_failure=1
45
46 if test $framework_failure = 1; then
47   echo "$0: failure in testing framework" 1>&2
48   (exit 1); exit 1
49 fi
50
51 fail=0
52
53 chgrp -H -R $g2 1s 2 || fail=1
54
55 # These must have group $g2.
56 # =========================
57 changed='
58 1
59 1/1F
60 2
61 2/2F
62 3
63 '
64 for i in $changed; do
65   # Filter out symlinks (entries that end in `s'), since it's not
66   # possible to change their group/owner information on some systems.
67   case $i in *s) continue;; esac
68   set _ `ls -dgn $i`; shift
69   group=$3
70   test $group = $g2 || fail=1
71 done
72
73 # These must have group $g1.
74 # =========================
75 not_changed='
76 1s
77 2/2s
78 3/3F
79 '
80 for i in $not_changed; do
81   # Filter out symlinks (entries that end in `s'), since it's not
82   # possible to change their group/owner information on some systems.
83   case $i in *s) continue;; esac
84   set _ `ls -dgn $i`; shift
85   group=$3
86   test $group = $g1 || fail=1
87 done
88
89 (exit $fail); exit $fail