Skip to content

Commit c62e0ef

Browse files
committed
Update install-sh using version from automake 1.4. Closes patch python#103657
and python#103717.
1 parent ef0a032 commit c62e0ef

1 file changed

Lines changed: 157 additions & 26 deletions

File tree

install-sh

Lines changed: 157 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,27 @@
11
#!/bin/sh
2-
32
#
43
# install - install a program, script, or datafile
5-
# This comes from X11R5; it is not part of GNU.
4+
# This comes from X11R5 (mit/util/scripts/install.sh).
65
#
7-
# $XConsortium: install.sh,v 1.2 89/12/18 14:47:22 jim Exp $
6+
# Copyright 1991 by the Massachusetts Institute of Technology
87
#
9-
# This script is compatible with the BSD install script, but was written
10-
# from scratch.
8+
# Permission to use, copy, modify, distribute, and sell this software and its
9+
# documentation for any purpose is hereby granted without fee, provided that
10+
# the above copyright notice appear in all copies and that both that
11+
# copyright notice and this permission notice appear in supporting
12+
# documentation, and that the name of M.I.T. not be used in advertising or
13+
# publicity pertaining to distribution of the software without specific,
14+
# written prior permission. M.I.T. makes no representations about the
15+
# suitability of this software for any purpose. It is provided "as is"
16+
# without express or implied warranty.
17+
#
18+
# Calling this script install-sh is preferred over install.sh, to prevent
19+
# `make' implicit rules from creating a file called install from it
20+
# when there is no Makefile.
1121
#
22+
# This script is compatible with the BSD install script, but was written
23+
# from scratch. It can only install one file at a time, a restriction
24+
# shared with many OS's install programs.
1225

1326

1427
# set DOITPROG to echo to test this script
@@ -26,23 +39,31 @@ chownprog="${CHOWNPROG-chown}"
2639
chgrpprog="${CHGRPPROG-chgrp}"
2740
stripprog="${STRIPPROG-strip}"
2841
rmprog="${RMPROG-rm}"
42+
mkdirprog="${MKDIRPROG-mkdir}"
2943

44+
transformbasename=""
45+
transform_arg=""
3046
instcmd="$mvprog"
31-
chmodcmd=""
47+
chmodcmd="$chmodprog 0755"
3248
chowncmd=""
3349
chgrpcmd=""
3450
stripcmd=""
3551
rmcmd="$rmprog -f"
3652
mvcmd="$mvprog"
3753
src=""
3854
dst=""
55+
dir_arg=""
3956

4057
while [ x"$1" != x ]; do
4158
case $1 in
4259
-c) instcmd="$cpprog"
4360
shift
4461
continue;;
4562

63+
-d) dir_arg=true
64+
shift
65+
continue;;
66+
4667
-m) chmodcmd="$chmodprog $2"
4768
shift
4869
shift
@@ -62,10 +83,20 @@ while [ x"$1" != x ]; do
6283
shift
6384
continue;;
6485

86+
-t=*) transformarg=`echo $1 | sed 's/-t=//'`
87+
shift
88+
continue;;
89+
90+
-b=*) transformbasename=`echo $1 | sed 's/-b=//'`
91+
shift
92+
continue;;
93+
6594
*) if [ x"$src" = x ]
6695
then
6796
src=$1
6897
else
98+
# this colon is to work around a 386BSD /bin/sh bug
99+
:
69100
dst=$1
70101
fi
71102
shift
@@ -75,46 +106,146 @@ done
75106

76107
if [ x"$src" = x ]
77108
then
78-
echo "install: no input file specified"
79-
exit 1
80-
fi
81-
82-
if [ x"$dst" = x ]
83-
then
84-
echo "install: no destination specified"
109+
echo "install: no input file specified"
85110
exit 1
111+
else
112+
true
86113
fi
87114

115+
if [ x"$dir_arg" != x ]; then
116+
dst=$src
117+
src=""
118+
119+
if [ -d $dst ]; then
120+
instcmd=:
121+
chmodcmd=""
122+
else
123+
instcmd=mkdir
124+
fi
125+
else
126+
127+
# Waiting for this to be detected by the "$instcmd $src $dsttmp" command
128+
# might cause directories to be created, which would be especially bad
129+
# if $src (and thus $dsttmp) contains '*'.
130+
131+
if [ -f $src -o -d $src ]
132+
then
133+
true
134+
else
135+
echo "install: $src does not exist"
136+
exit 1
137+
fi
138+
139+
if [ x"$dst" = x ]
140+
then
141+
echo "install: no destination specified"
142+
exit 1
143+
else
144+
true
145+
fi
88146

89147
# If destination is a directory, append the input filename; if your system
90148
# does not like double slashes in filenames, you may need to add some logic
91149

92-
if [ -d $dst ]
93-
then
94-
dst="$dst"/`basename $src`
150+
if [ -d $dst ]
151+
then
152+
dst="$dst"/`basename $src`
153+
else
154+
true
155+
fi
156+
fi
157+
158+
## this sed command emulates the dirname command
159+
dstdir=`echo $dst | sed -e 's,[^/]*$,,;s,/$,,;s,^$,.,'`
160+
161+
# Make sure that the destination directory exists.
162+
# this part is taken from Noah Friedman's mkinstalldirs script
163+
164+
# Skip lots of stat calls in the usual case.
165+
if [ ! -d "$dstdir" ]; then
166+
defaultIFS='
167+
'
168+
IFS="${IFS-${defaultIFS}}"
169+
170+
oIFS="${IFS}"
171+
# Some sh's can't handle IFS=/ for some reason.
172+
IFS='%'
173+
set - `echo ${dstdir} | sed -e 's@/@%@g' -e 's@^%@/@'`
174+
IFS="${oIFS}"
175+
176+
pathcomp=''
177+
178+
while [ $# -ne 0 ] ; do
179+
pathcomp="${pathcomp}${1}"
180+
shift
181+
182+
if [ ! -d "${pathcomp}" ] ;
183+
then
184+
$mkdirprog "${pathcomp}"
185+
else
186+
true
187+
fi
188+
189+
pathcomp="${pathcomp}/"
190+
done
95191
fi
96192

193+
if [ x"$dir_arg" != x ]
194+
then
195+
$doit $instcmd $dst &&
196+
197+
if [ x"$chowncmd" != x ]; then $doit $chowncmd $dst; else true ; fi &&
198+
if [ x"$chgrpcmd" != x ]; then $doit $chgrpcmd $dst; else true ; fi &&
199+
if [ x"$stripcmd" != x ]; then $doit $stripcmd $dst; else true ; fi &&
200+
if [ x"$chmodcmd" != x ]; then $doit $chmodcmd $dst; else true ; fi
201+
else
202+
203+
# If we're going to rename the final executable, determine the name now.
204+
205+
if [ x"$transformarg" = x ]
206+
then
207+
dstfile=`basename $dst`
208+
else
209+
dstfile=`basename $dst $transformbasename |
210+
sed $transformarg`$transformbasename
211+
fi
212+
213+
# don't allow the sed command to completely eliminate the filename
214+
215+
if [ x"$dstfile" = x ]
216+
then
217+
dstfile=`basename $dst`
218+
else
219+
true
220+
fi
221+
97222
# Make a temp file name in the proper directory.
98223

99-
# Avoid dirname, which doesn't exist everywhere...
100-
dstdir=`echo $dst | sed 's,/[^/]*$,,'`
101-
dsttmp=$dstdir/#inst.$$#
224+
dsttmp=$dstdir/#inst.$$#
102225

103226
# Move or copy the file name to the temp name
104227

105-
$doit $instcmd $src $dsttmp || exit $?
228+
$doit $instcmd $src $dsttmp &&
229+
230+
trap "rm -f ${dsttmp}" 0 &&
106231

107232
# and set any options; do chmod last to preserve setuid bits
108233

109-
if [ x"$chowncmd" != x ]; then $doit $chowncmd $dsttmp; fi
110-
if [ x"$chgrpcmd" != x ]; then $doit $chgrpcmd $dsttmp; fi
111-
if [ x"$stripcmd" != x ]; then $doit $stripcmd $dsttmp; fi
112-
if [ x"$chmodcmd" != x ]; then $doit $chmodcmd $dsttmp; fi
234+
# If any of these fail, we abort the whole thing. If we want to
235+
# ignore errors from any of these, just make sure not to ignore
236+
# errors from the above "$doit $instcmd $src $dsttmp" command.
237+
238+
if [ x"$chowncmd" != x ]; then $doit $chowncmd $dsttmp; else true;fi &&
239+
if [ x"$chgrpcmd" != x ]; then $doit $chgrpcmd $dsttmp; else true;fi &&
240+
if [ x"$stripcmd" != x ]; then $doit $stripcmd $dsttmp; else true;fi &&
241+
if [ x"$chmodcmd" != x ]; then $doit $chmodcmd $dsttmp; else true;fi &&
113242

114243
# Now rename the file to the real destination.
115244

116-
$doit $rmcmd $dst
117-
$doit $mvcmd $dsttmp $dst || exit $?
245+
$doit $rmcmd -f $dstdir/$dstfile &&
246+
$doit $mvcmd $dsttmp $dstdir/$dstfile
247+
248+
fi &&
118249

119250

120251
exit 0

0 commit comments

Comments
 (0)