1#!/bin/sh 2# Basic tests for "install". 3 4# Copyright (C) 1998-2023 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 3 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, see <https://www.gnu.org/licenses/>. 18 19. "${srcdir=.}/tests/init.sh"; path_prepend_ ./src 20print_ver_ ginstall 21skip_if_root_ 22 23dir=dir 24file=file 25 26rm -rf $dir $file || framework_failure_ 27mkdir -p $dir || framework_failure_ 28echo foo > $file || framework_failure_ 29 30ginstall $file $dir || fail=1 31# Make sure the source file still exists. 32test -f $file || fail=1 33# Make sure the dest file has been created. 34test -f $dir/$file || fail=1 35 36# Make sure strip works. 37dd=dd$EXEEXT 38dd2=dd2$EXEEXT 39 40just_built_dd=$abs_top_builddir/src/$dd 41 42test -r "$just_built_dd" \ 43 || warn_ "WARNING!!! Your just-built dd binary, $just_built_dd 44is not readable, so skipping the remaining tests in this file." 45 46cp "$just_built_dd" . || fail=1 47cp $dd $dd2 || fail=1 48 49strip=-s 50if ! strip $dd2; then 51 ! test -e $abs_top_builddir/src/coreutils \ 52 && warn_ "WARNING!!! Your strip command doesn't seem to work, 53so skipping the test of install's --strip option." 54 strip= 55fi 56 57# This test would fail with 3.16s when using versions of strip that 58# don't work on read-only files (the one from binutils works fine). 59ginstall $strip -c -m 555 $dd $dir || fail=1 60# Make sure the source file is still around. 61test -f $dd || fail=1 62 63# Make sure that the destination file has the requested permissions. 64mode=$(ls -l $dir/$dd|cut -b-10) 65test "$mode" = -r-xr-xr-x || fail=1 66 67# These failed in coreutils CVS from 2004-06-25 to 2004-08-11. 68ginstall -d . || fail=1 69ginstall -d newdir || fail=1 70test -d newdir || fail=1 71ginstall -d newdir1 newdir2 newdir3 || fail=1 72test -d newdir1 || fail=1 73test -d newdir2 || fail=1 74test -d newdir3 || fail=1 75 76# This fails because mkdir-p.c's make_dir_parents fails to return to its 77# initial working directory ($iwd) after creating the first argument, and 78# hence cannot do anything meaningful with the following relative-named dirs. 79iwd=$(pwd) 80mkdir sub || fail=1 81(cd sub && 82 chmod 0 . && 83 returns_ 1 ginstall -d "$iwd/xx/yy" rel/sub1 rel/sub2 2> /dev/null 84) || fail=1 85chmod 755 sub 86 87# Ensure that the first argument-dir has been created. 88test -d xx/yy || fail=1 89 90# Make sure that the 'rel' directory was not created... 91test -d sub/rel && fail=1 92# and make sure it was not created in the wrong place. 93test -d xx/rel && fail=1 94 95# Test that we can install from an unreadable directory with an 96# inaccessible parent. coreutils 5.97 fails this test. 97# Perform this test only if "." is on a local file system. 98# Otherwise, it would fail e.g., on an NFS-mounted file system. 99if is_local_dir_ .; then 100 mkdir -p sub1/d || fail=1 101 (cd sub1/d && chmod a-r . && chmod a-rx .. && 102 ginstall -d "$iwd/xx/zz" rel/a rel/b) || fail=1 103 chmod 755 sub1 sub1/d || fail=1 104 test -d xx/zz || fail=1 105 test -d sub1/d/rel/a || fail=1 106 test -d sub1/d/rel/b || fail=1 107fi 108 109touch file || fail=1 110ginstall -Dv file sub3/a/b/c/file >out 2>&1 || fail=1 111compare - out <<\EOF || fail=1 112ginstall: creating directory 'sub3' 113ginstall: creating directory 'sub3/a' 114ginstall: creating directory 'sub3/a/b' 115ginstall: creating directory 'sub3/a/b/c' 116'file' -> 'sub3/a/b/c/file' 117EOF 118 119# Test -D together with -t (available since coreutils >= 8.23). 120# Let ginstall create a completely new destination hierarchy. 121ginstall -t sub4/a/b/c -Dv file >out 2>&1 || fail=1 122compare - out <<\EOF || fail=1 123ginstall: creating directory 'sub4' 124ginstall: creating directory 'sub4/a' 125ginstall: creating directory 'sub4/a/b' 126ginstall: creating directory 'sub4/a/b/c' 127'file' -> 'sub4/a/b/c/file' 128EOF 129 130# Ensure that -D with an already existing file as -t's option argument fails. 131touch sub4/file_exists || framework_failure_ 132ginstall -t sub4/file_exists -Dv file >out 2>&1 && fail=1 133compare - out <<\EOF || fail=1 134ginstall: failed to access 'sub4/file_exists': Not a directory 135EOF 136 137# Ensure that -D with an already existing directory for -t's option argument 138# succeeds. 139mkdir sub4/dir_exists || framework_failure_ 140touch sub4/dir_exists || framework_failure_ 141ginstall -t sub4/dir_exists -Dv file >out 2>&1 || fail=1 142compare - out <<\EOF || fail=1 143'file' -> 'sub4/dir_exists/file' 144EOF 145 146# Ensure omitted directories are diagnosed 147returns_ 1 ginstall . . 2>err || fail=1 148printf '%s\n' "ginstall: omitting directory '.'" >exp || framework_failure_ 149compare exp err || fail=1 150 151Exit $fail 152