]> Git Repo - binutils.git/blame - install.sh
Latest changes from Andrew
[binutils.git] / install.sh
CommitLineData
bf168768 1#!/bin/sh
bf168768 2#
5d95c474
GI
3# Copyright 1991 by the Massachusetts Institute of Technology
4#
5# Permission to use, copy, modify, distribute, and sell this software and its
6# documentation for any purpose is hereby granted without fee, provided that
7# the above copyright notice appear in all copies and that both that
8# copyright notice and this permission notice appear in supporting
9# documentation, and that the name of M.I.T. not be used in advertising or
10# publicity pertaining to distribution of the software without specific,
11# written prior permission. M.I.T. makes no representations about the
12# suitability of this software for any purpose. It is provided "as is"
13# without express or implied warranty.
14#
bf168768 15# install - install a program, script, or datafile
5d95c474
GI
16# The original version of this script came from X11R5
17# (mit/util/scripts/install.sh); it is not part of GNU.
bf168768
DZ
18#
19# $XConsortium: install.sh,v 1.2 89/12/18 14:47:22 jim Exp $
20#
21# This script is compatible with the BSD install script, but was written
22# from scratch.
23#
5d95c474
GI
24# At Cygnus this script is duplicated as:
25#
26# install.sh
27# apache/install-sh
28# dejagnu/install-sh
29# expect/install-sh
30# inet/install-sh
31#
32# if you change one of these, you will probably want to change them
33# all. Variants of it also appear in:
34#
35# tcl/unix/install-sh
36# tk/unix/install-sh
37#
38# however these versions are the versions of this script from the
39# original Tcl/Tk distribution, and are somewhat different, and so
40# changing these will result in divergences from the Tcl/Tk
41# distribution.
42#
bf168768
DZ
43
44
45# set DOITPROG to echo to test this script
46
47# Don't use :- since 4.3BSD and earlier shells don't like it.
48doit="${DOITPROG-}"
49
50
51# put in absolute paths if you don't have them in your path; or use env. vars.
52
53mvprog="${MVPROG-mv}"
54cpprog="${CPPROG-cp}"
55chmodprog="${CHMODPROG-chmod}"
56chownprog="${CHOWNPROG-chown}"
57chgrpprog="${CHGRPPROG-chgrp}"
58stripprog="${STRIPPROG-strip}"
59rmprog="${RMPROG-rm}"
60mkdirprog="${MKDIRPROG-mkdir}"
61
c0914b6e 62transformbasename=""
bf168768
DZ
63transform_arg=""
64instcmd="$mvprog"
98e67c34 65chmodcmd="$chmodprog 0755"
bf168768
DZ
66chowncmd=""
67chgrpcmd=""
68stripcmd=""
69rmcmd="$rmprog -f"
70mvcmd="$mvprog"
71src=""
72dst=""
24170039 73dir_arg=""
bf168768
DZ
74
75while [ x"$1" != x ]; do
76 case $1 in
77 -c) instcmd="$cpprog"
78 shift
79 continue;;
80
24170039
JM
81 -d) dir_arg=true
82 shift
83 continue;;
84
bf168768
DZ
85 -m) chmodcmd="$chmodprog $2"
86 shift
87 shift
88 continue;;
89
90 -o) chowncmd="$chownprog $2"
91 shift
92 shift
93 continue;;
94
95 -g) chgrpcmd="$chgrpprog $2"
96 shift
97 shift
98 continue;;
99
100 -s) stripcmd="$stripprog"
101 shift
102 continue;;
103
104 -t=*) transformarg=`echo $1 | sed 's/-t=//'`
105 shift
106 continue;;
107
108 -b=*) transformbasename=`echo $1 | sed 's/-b=//'`
109 shift
110 continue;;
111
112 *) if [ x"$src" = x ]
113 then
114 src=$1
115 else
f0d7cc29
DZ
116 # this colon is to work around a 386BSD /bin/sh bug
117 :
bf168768
DZ
118 dst=$1
119 fi
120 shift
121 continue;;
122 esac
123done
124
125if [ x"$src" = x ]
126then
127 echo "install: no input file specified"
128 exit 1
129else
130 true
131fi
132
24170039
JM
133if [ x"$dir_arg" != x ]; then
134 dst=$src
135 src=""
136
137 if [ -d $dst ]; then
138 instcmd=:
139 else
140 instcmd=mkdir
141 fi
142else
143
731b0720
JK
144# Waiting for this to be detected by the "$instcmd $src $dsttmp" command
145# might cause directories to be created, which would be especially bad
146# if $src (and thus $dsttmp) contains '*'.
147
24170039
JM
148 if [ -f $src -o -d $src ]
149 then
150 true
151 else
152 echo "install: $src does not exist"
153 exit 1
154 fi
155
156 if [ x"$dst" = x ]
157 then
158 echo "install: no destination specified"
159 exit 1
160 else
161 true
162 fi
bf168768
DZ
163
164# If destination is a directory, append the input filename; if your system
165# does not like double slashes in filenames, you may need to add some logic
166
24170039
JM
167 if [ -d $dst ]
168 then
169 dst="$dst"/`basename $src`
170 else
171 true
172 fi
bf168768
DZ
173fi
174
af864713
DZ
175## this sed command emulates the dirname command
176dstdir=`echo $dst | sed -e 's,[^/]*$,,;s,/$,,;s,^$,.,'`
bf168768
DZ
177
178# Make sure that the destination directory exists.
179# this part is taken from Noah Friedman's mkinstalldirs script
180
835578f3
DM
181# Skip lots of stat calls in the usual case.
182if [ ! -d "$dstdir" ]; then
bf168768
DZ
183defaultIFS='
184'
185IFS="${IFS-${defaultIFS}}"
186
187oIFS="${IFS}"
188# Some sh's can't handle IFS=/ for some reason.
189IFS='%'
190set - `echo ${dstdir} | sed -e 's@/@%@g' -e 's@^%@/@'`
191IFS="${oIFS}"
192
193pathcomp=''
194
195while [ $# -ne 0 ] ; do
196 pathcomp="${pathcomp}${1}"
197 shift
198
199 if [ ! -d "${pathcomp}" ] ;
200 then
201 $mkdirprog "${pathcomp}"
202 else
203 true
204 fi
205
206 pathcomp="${pathcomp}/"
207done
835578f3 208fi
bf168768 209
24170039 210if [ x"$dir_arg" != x ]
bf168768 211then
24170039
JM
212 $doit $instcmd $dst &&
213
214 if [ x"$chowncmd" != x ]; then $doit $chowncmd $dst; else true ; fi &&
215 if [ x"$chgrpcmd" != x ]; then $doit $chgrpcmd $dst; else true ; fi &&
216 if [ x"$stripcmd" != x ]; then $doit $stripcmd $dst; else true ; fi &&
217 if [ x"$chmodcmd" != x ]; then $doit $chmodcmd $dst; else true ; fi
bf168768 218else
24170039
JM
219
220# If we're going to rename the final executable, determine the name now.
221
222 if [ x"$transformarg" = x ]
223 then
224 dstfile=`basename $dst`
225 else
226 dstfile=`basename $dst $transformbasename |
227 sed $transformarg`$transformbasename
228 fi
bf168768
DZ
229
230# don't allow the sed command to completely eliminate the filename
231
24170039
JM
232 if [ x"$dstfile" = x ]
233 then
234 dstfile=`basename $dst`
235 else
236 true
237 fi
238
239# Make a temp file name in the proper directory.
240
241 dsttmp=$dstdir/#inst.$$#
bf168768
DZ
242
243# Move or copy the file name to the temp name
244
24170039 245 $doit $instcmd $src $dsttmp &&
731b0720 246
24170039 247 trap "rm -f ${dsttmp}" 0 &&
bf168768
DZ
248
249# and set any options; do chmod last to preserve setuid bits
250
731b0720
JK
251# If any of these fail, we abort the whole thing. If we want to
252# ignore errors from any of these, just make sure not to ignore
253# errors from the above "$doit $instcmd $src $dsttmp" command.
254
24170039
JM
255 if [ x"$chowncmd" != x ]; then $doit $chowncmd $dsttmp; else true;fi &&
256 if [ x"$chgrpcmd" != x ]; then $doit $chgrpcmd $dsttmp; else true;fi &&
257 if [ x"$stripcmd" != x ]; then $doit $stripcmd $dsttmp; else true;fi &&
258 if [ x"$chmodcmd" != x ]; then $doit $chmodcmd $dsttmp; else true;fi &&
bf168768
DZ
259
260# Now rename the file to the real destination.
261
24170039
JM
262 $doit $rmcmd -f $dstdir/$dstfile &&
263 $doit $mvcmd $dsttmp $dstdir/$dstfile
264
265fi &&
bf168768
DZ
266
267
268exit 0
This page took 0.273255 seconds and 4 git commands to generate.