Tizen 2.0 Release
[external/tizen-coreutils.git] / tests / install / basic-1
1 #! /bin/sh
2 # Basic tests for "install".
3
4 # Copyright (C) 1998, 2000-2002, 2004-2007 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   ginstall --version
24 fi
25
26 # Make sure we get English translations.
27 LANGUAGE=C
28 export LANGUAGE
29 LC_ALL=C
30 export LC_ALL
31 LANG=C
32 export LANG
33
34 . $srcdir/../envvar-check
35 PRIV_CHECK_ARG=require-non-root . $srcdir/../priv-check
36
37 dir=dir
38 file=file
39
40 pwd=`pwd`
41 t0=`echo "$0"|sed 's,.*/,,'`.tmp; tmp=$t0/$$
42 trap 'status=$?; cd "$pwd" && chmod -R u+rwx $t0 && rm -rf $t0 && exit $status' 0
43 trap '(exit $?); exit $?' 1 2 13 15
44
45 framework_failure=0
46 mkdir -p $tmp || framework_failure=1
47 cd $tmp || framework_failure=1
48
49 rm -rf $dir $file || framework_failure=1
50 mkdir -p $dir || framework_failure=1
51 echo foo > $file || framework_failure=1
52
53 if test $framework_failure = 1; then
54   echo 'failure in testing framework'
55   exit 1
56 fi
57
58 fail=0
59 ginstall $file $dir || fail=1
60 # Make sure the source file still exists.
61 test -f $file || fail=1
62 # Make sure the dest file has been created.
63 test -f $dir/$file || fail=1
64
65 # Make sure strip works.
66 dd=dd$EXEEXT
67 dd2=dd2$EXEEXT
68
69 just_built_dd=$pwd/../../src/$dd
70
71 test -r "$just_built_dd" || \
72   {
73     cat 1>&2 <<EOF
74 $0: WARNING!!!
75 Your just-built dd binary, $just_built_dd
76 is not readable, so skipping the remaining tests in this file.
77 EOF
78     exit 77
79   }
80
81 cp "$just_built_dd" . || fail=1
82 cp $dd $dd2 || fail=1
83
84 strip $dd2 || \
85   {
86     cat 1>&2 <<EOF
87 $0: WARNING!!!
88 Your strip command doesn't seem to work, so skipping
89 the test of install's --strip option.
90 EOF
91     exit 77
92   }
93
94 # This test would fail with 3.16s when using versions of strip that
95 # don't work on read-only files (the one from binutils works fine).
96 ginstall -s -c -m 555 $dd $dir || fail=1
97 # Make sure the source file is still around.
98 test -f $dd || fail=1
99
100 # Make sure that the destination file has the requested permissions.
101 set X `ls -l $dir/$dd`
102 shift
103 test "$1" = -r-xr-xr-x || fail=1
104
105 # These failed in coreutils CVS from 2004-06-25 to 2004-08-11.
106 ginstall -d . || fail=1
107 ginstall -d newdir || fail=1
108 test -d newdir || fail=1
109 ginstall -d newdir1 newdir2 newdir3 || fail=1
110 test -d newdir1 || fail=1
111 test -d newdir2 || fail=1
112 test -d newdir3 || fail=1
113
114 # This fails because mkdir-p.c's make_dir_parents fails to return to its
115 # initial working directory ($abs) after creating the first argument, and
116 # hence cannot do anything meaningful with the following relative-named dirs.
117 abs=$pwd/$tmp
118 mkdir sub || fail=1
119 (cd sub && chmod 0 . && ginstall -d "$abs/xx/yy" rel/sub1 rel/sub2 2> /dev/null) && fail=1
120 chmod 755 sub
121
122 # Ensure that the first argument-dir has been created.
123 test -d xx/yy || fail=1
124
125 # Make sure that the `rel' directory was not created...
126 test -d sub/rel && fail=1
127 # and make sure it was not created in the wrong place.
128 test -d xx/rel && fail=1
129
130 # Test that we can install from an unreadable directory with an
131 # inaccessible parent.  coreutils 5.97 fails this test.
132 # Perform this test only if "." is on a local file system.
133 # Otherwise, it would fail e.g., on an NFS-mounted file system.
134 if df --local . >/dev/null 2>&1; then
135   mkdir -p sub1/d || fail=1
136   (cd sub1/d && chmod a-r . && chmod a-rx .. &&
137    ginstall -d "$abs/xx/zz" rel/a rel/b) || fail=1
138   chmod 755 sub1 sub1/d || fail=1
139   test -d xx/zz || fail=1
140   test -d sub1/d/rel/a || fail=1
141   test -d sub1/d/rel/b || fail=1
142 fi
143
144 touch file || fail=1
145 ginstall -Dv file sub3/a/b/c/file >out 2>&1 || fail=1
146 diff - out <<\EOF || fail=1
147 ginstall: creating directory `sub3'
148 ginstall: creating directory `sub3/a'
149 ginstall: creating directory `sub3/a/b'
150 ginstall: creating directory `sub3/a/b/c'
151 `file' -> `sub3/a/b/c/file'
152 EOF
153
154 (exit $fail); exit $fail