1#!/bin/sh
2# Ensure "install -C" works. (basic tests)
3
4# Copyright (C) 2008-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_setgid_
22skip_if_nondefault_group_
23
24# Note if a group is not specified, install(1) will assume that a file
25# would be installed with the current user's group ID, and thus if the
26# file is the same except that it does have a different group due to
27# its parent directory being g+s for example, then the copy will be
28# done again redundantly in a futile attempt to reset the group ID to
29# that of the current user.
30#
31#  install -d -g wheel -m 2775 test  # Create setgid dir
32#  touch test/a                      # Create source
33#  install -Cv -m664 test/a test/i1  # install source with mode
34#  install -Cv -m664 test/i1 test/i2 # install dest
35#  install -Cv -m664 test/i1 test/i2 # again to see redundant install
36#
37# Similarly if an existing file exists that is the same and has the
38# current users group ID, but when an actual install of the file would
39# reset to a different group ID due to the directory being g+s for example,
40# then the install will not be done when it should.
41#
42#  install -Cv -m664 -g "$(id -nrg)" test/i1 test/i2 # set i2 to uesr's gid
43#  install -Cv -m664 test/i1 test/i2 # this should install but doesn't
44#
45# Therefore we skip the test in the presence of setgid dirs
46# An additional complication on HFS is that it...
47
48mode1=0644
49mode2=0755
50mode3=2755
51
52
53echo test > a || framework_failure_
54echo "'a' -> 'b'" > out_installed_first || framework_failure_
55echo "removed 'b'
56'a' -> 'b'" > out_installed_second || framework_failure_
57> out_empty || framework_failure_
58
59# destination file does not exist
60ginstall -Cv -m$mode1 a b > out || fail=1
61compare out out_installed_first || fail=1
62
63# destination file exists
64ginstall -Cv -m$mode1 a b > out || fail=1
65compare out out_empty || fail=1
66
67# destination file exists (long option)
68ginstall -v --compare -m$mode1 a b > out || fail=1
69compare out out_empty || fail=1
70
71# destination file exists but -C is not given
72ginstall -v -m$mode1 a b > out || fail=1
73compare out out_installed_second || fail=1
74
75# option -C ignored if any non-permission mode should be set
76ginstall -Cv -m$mode3 a b > out || fail=1
77compare out out_installed_second || fail=1
78ginstall -Cv -m$mode3 a b > out || fail=1
79compare out out_installed_second || fail=1
80
81# files are not regular files
82ln -s a c || framework_failure_
83ln -s b d || framework_failure_
84ginstall -Cv -m$mode1 c d > out || fail=1
85echo "removed 'd'
86'c' -> 'd'" > out_installed_second_cd
87compare out out_installed_second_cd || fail=1
88
89# destination file exists but content differs
90echo test1 > a || framework_failure_
91ginstall -Cv -m$mode1 a b > out || fail=1
92compare out out_installed_second || fail=1
93ginstall -Cv -m$mode1 a b > out || fail=1
94compare out out_empty || fail=1
95
96# destination file exists but content differs (same size)
97echo test2 > a || framework_failure_
98ginstall -Cv -m$mode1 a b > out || fail=1
99compare out out_installed_second || fail=1
100ginstall -Cv -m$mode1 a b > out || fail=1
101compare out out_empty || fail=1
102
103# destination file exists but mode differs
104ginstall -Cv -m$mode2 a b > out || fail=1
105compare out out_installed_second || fail=1
106ginstall -Cv -m$mode2 a b > out || fail=1
107compare out out_empty || fail=1
108
109# options -C and --preserve-timestamps are mutually exclusive
110returns_ 1 ginstall -C --preserve-timestamps a b || fail=1
111
112# options -C and --strip are mutually exclusive
113returns_ 1 ginstall -C --strip --strip-program=echo a b || fail=1
114
115Exit $fail
116