2002-12-08 H.J. Lu <hjl@gnu.org>
[deliverable/binutils-gdb.git] / readline / support / install.sh
CommitLineData
d60d9f65
SS
1#!/bin/sh
2#
3# install - install a program, script, or datafile
4# This comes from X11R5.
5#
6# $XConsortium: install.sh,v 1.2 89/12/18 14:47:22 jim Exp $
7#
8# This script is compatible with the BSD install script, but was written
9# from scratch.
10#
11
12# set DOITPROG to echo to test this script
13
14# Don't use :- since 4.3BSD and earlier shells don't like it.
15doit="${DOITPROG-}"
16
17
18# put in absolute paths if you don't have them in your path; or use env. vars.
19
20mvprog="${MVPROG-mv}"
21cpprog="${CPPROG-cp}"
22chmodprog="${CHMODPROG-chmod}"
23chownprog="${CHOWNPROG-chown}"
24chgrpprog="${CHGRPPROG-chgrp}"
25stripprog="${STRIPPROG-strip}"
26rmprog="${RMPROG-rm}"
27mkdirprog="${MKDIRPROG-mkdir}"
28
29tranformbasename=""
30transform_arg=""
31instcmd="$mvprog"
32chmodcmd="$chmodprog 0755"
33chowncmd=""
34chgrpcmd=""
35stripcmd=""
36rmcmd="$rmprog -f"
37mvcmd="$mvprog"
38src=""
39dst=""
40dir_arg=""
41
42while [ x"$1" != x ]; do
43 case $1 in
44 -c) instcmd="$cpprog"
45 shift
46 continue;;
47
48 -d) dir_arg=true
49 shift
50 continue;;
51
52 -m) chmodcmd="$chmodprog $2"
53 shift
54 shift
55 continue;;
56
57 -o) chowncmd="$chownprog $2"
58 shift
59 shift
60 continue;;
61
62 -g) chgrpcmd="$chgrpprog $2"
63 shift
64 shift
65 continue;;
66
67 -s) stripcmd="$stripprog"
68 shift
69 continue;;
70
71 -t=*) transformarg=`echo $1 | sed 's/-t=//'`
72 shift
73 continue;;
74
75 -b=*) transformbasename=`echo $1 | sed 's/-b=//'`
76 shift
77 continue;;
78
79 *) if [ x"$src" = x ]
80 then
81 src=$1
82 else
83 # this colon is to work around a 386BSD /bin/sh bug
84 :
85 dst=$1
86 fi
87 shift
88 continue;;
89 esac
90done
91
92if [ x"$src" = x ]
93then
94 echo "install: no input file specified"
95 exit 1
96else
97 true
98fi
99
100if [ x"$dir_arg" != x ]; then
101 dst=$src
102 src=""
103
104 if [ -d $dst ]; then
105 instcmd=:
106 else
107 instcmd=mkdir
108 fi
109else
110
111# Waiting for this to be detected by the "$instcmd $src $dsttmp" command
112# might cause directories to be created, which would be especially bad
113# if $src (and thus $dsttmp) contains '*'.
114
115 if [ -f $src -o -d $src ]
116 then
117 true
118 else
119 echo "install: $src does not exist"
120 exit 1
121 fi
122
123 if [ x"$dst" = x ]
124 then
125 echo "install: no destination specified"
126 exit 1
127 else
128 true
129 fi
130
131# If destination is a directory, append the input filename; if your system
132# does not like double slashes in filenames, you may need to add some logic
133
134 if [ -d $dst ]
135 then
136 dst="$dst"/`basename $src`
137 else
138 true
139 fi
140fi
141
142## this sed command emulates the dirname command
143dstdir=`echo $dst | sed -e 's,[^/]*$,,;s,/$,,;s,^$,.,'`
144
145# Make sure that the destination directory exists.
146# this part is taken from Noah Friedman's mkinstalldirs script
147
148# Skip lots of stat calls in the usual case.
149if [ ! -d "$dstdir" ]; then
150defaultIFS='
151'
152IFS="${IFS-${defaultIFS}}"
153
154oIFS="${IFS}"
155# Some sh's can't handle IFS=/ for some reason.
156IFS='%'
157set - `echo ${dstdir} | sed -e 's@/@%@g' -e 's@^%@/@'`
158IFS="${oIFS}"
159
160pathcomp=''
161
162while [ $# -ne 0 ] ; do
163 pathcomp="${pathcomp}${1}"
164 shift
165
166 if [ ! -d "${pathcomp}" ] ;
167 then
168 $mkdirprog "${pathcomp}"
169 else
170 true
171 fi
172
173 pathcomp="${pathcomp}/"
174done
175fi
176
177if [ x"$dir_arg" != x ]
178then
179 $doit $instcmd $dst &&
180
181 if [ x"$chowncmd" != x ]; then $doit $chowncmd $dst; else true ; fi &&
182 if [ x"$chgrpcmd" != x ]; then $doit $chgrpcmd $dst; else true ; fi &&
183 if [ x"$stripcmd" != x ]; then $doit $stripcmd $dst; else true ; fi &&
184 if [ x"$chmodcmd" != x ]; then $doit $chmodcmd $dst; else true ; fi
185else
186
187# If we're going to rename the final executable, determine the name now.
188
189 if [ x"$transformarg" = x ]
190 then
191 dstfile=`basename $dst`
192 else
193 dstfile=`basename $dst $transformbasename |
194 sed $transformarg`$transformbasename
195 fi
196
197# don't allow the sed command to completely eliminate the filename
198
199 if [ x"$dstfile" = x ]
200 then
201 dstfile=`basename $dst`
202 else
203 true
204 fi
205
206# Make a temp file name in the proper directory.
207
208 dsttmp=$dstdir/#inst.$$#
209
210# Move or copy the file name to the temp name
211
212 $doit $instcmd $src $dsttmp &&
213
214 trap "rm -f ${dsttmp}" 0 &&
215
216# and set any options; do chmod last to preserve setuid bits
217
218# If any of these fail, we abort the whole thing. If we want to
219# ignore errors from any of these, just make sure not to ignore
220# errors from the above "$doit $instcmd $src $dsttmp" command.
221
222 if [ x"$chowncmd" != x ]; then $doit $chowncmd $dsttmp; else true;fi &&
223 if [ x"$chgrpcmd" != x ]; then $doit $chgrpcmd $dsttmp; else true;fi &&
224 if [ x"$stripcmd" != x ]; then $doit $stripcmd $dsttmp; else true;fi &&
225 if [ x"$chmodcmd" != x ]; then $doit $chmodcmd $dsttmp; else true;fi &&
226
227# Now rename the file to the real destination.
228
229 $doit $rmcmd -f $dstdir/$dstfile &&
230 $doit $mvcmd $dsttmp $dstdir/$dstfile
231
232fi &&
233
234
235exit 0
This page took 0.155238 seconds and 4 git commands to generate.