~ubuntu-branches/debian/sid/mtr/sid

« back to all changes in this revision

Viewing changes to install-sh

  • Committer: Bazaar Package Importer
  • Author(s): Robert Woodcock
  • Date: 2008-09-22 07:30:21 UTC
  • mfrom: (1.2.2 upstream)
  • Revision ID: james.westby@ubuntu.com-20080922073021-worxo2arrx3glvtn
Tags: 0.75-2
Use rm -f in rules clean target where necessary, closes: #499789

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
#!/bin/sh
2
2
#
3
3
# install - install a program, script, or datafile
4
 
#
5
 
# This originates from X11R5 (mit/util/scripts/install.sh), which was
6
 
# later released in X11R6 (xc/config/util/install.sh) with the
7
 
# following copyright and license.
8
 
#
9
 
# Copyright (C) 1994 X Consortium
10
 
#
11
 
# Permission is hereby granted, free of charge, to any person obtaining a copy
12
 
# of this software and associated documentation files (the "Software"), to
13
 
# deal in the Software without restriction, including without limitation the
14
 
# rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
15
 
# sell copies of the Software, and to permit persons to whom the Software is
16
 
# furnished to do so, subject to the following conditions:
17
 
#
18
 
# The above copyright notice and this permission notice shall be included in
19
 
# all copies or substantial portions of the Software.
20
 
#
21
 
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
22
 
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
23
 
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
24
 
# X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
25
 
# AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNEC-
26
 
# TION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
27
 
#
28
 
# Except as contained in this notice, the name of the X Consortium shall not
29
 
# be used in advertising or otherwise to promote the sale, use or other deal-
30
 
# ings in this Software without prior written authorization from the X Consor-
31
 
# tium.
32
 
#
33
 
#
34
 
# FSF changes to this file are in the public domain.
 
4
# This comes from X11R5 (mit/util/scripts/install.sh).
 
5
#
 
6
# Copyright 1991 by the Massachusetts Institute of Technology
 
7
#
 
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.
35
17
#
36
18
# Calling this script install-sh is preferred over install.sh, to prevent
37
19
# `make' implicit rules from creating a file called install from it
74
56
 
75
57
while [ x"$1" != x ]; do
76
58
    case $1 in
77
 
        -c) instcmd=$cpprog
 
59
        -c) instcmd="$cpprog"
78
60
            shift
79
61
            continue;;
80
62
 
97
79
            shift
98
80
            continue;;
99
81
 
100
 
        -s) stripcmd=$stripprog
 
82
        -s) stripcmd="$stripprog"
101
83
            shift
102
84
            continue;;
103
85
 
124
106
 
125
107
if [ x"$src" = x ]
126
108
then
127
 
        echo "$0: no input file specified" >&2
 
109
        echo "install:  no input file specified"
128
110
        exit 1
129
111
else
130
 
        :
 
112
        true
131
113
fi
132
114
 
133
115
if [ x"$dir_arg" != x ]; then
134
116
        dst=$src
135
117
        src=""
136
 
 
137
 
        if [ -d "$dst" ]; then
 
118
        
 
119
        if [ -d $dst ]; then
138
120
                instcmd=:
139
 
                chmodcmd=""
140
121
        else
141
 
                instcmd=$mkdirprog
 
122
                instcmd=mkdir
142
123
        fi
143
124
else
144
125
 
145
126
# Waiting for this to be detected by the "$instcmd $src $dsttmp" command
146
 
# might cause directories to be created, which would be especially bad
 
127
# might cause directories to be created, which would be especially bad 
147
128
# if $src (and thus $dsttmp) contains '*'.
148
129
 
149
 
        if [ -f "$src" ] || [ -d "$src" ]
 
130
        if [ -f $src -o -d $src ]
150
131
        then
151
 
                :
 
132
                true
152
133
        else
153
 
                echo "$0: $src does not exist" >&2
 
134
                echo "install:  $src does not exist"
154
135
                exit 1
155
136
        fi
156
 
 
 
137
        
157
138
        if [ x"$dst" = x ]
158
139
        then
159
 
                echo "$0: no destination specified" >&2
 
140
                echo "install:  no destination specified"
160
141
                exit 1
161
142
        else
162
 
                :
 
143
                true
163
144
        fi
164
145
 
165
146
# If destination is a directory, append the input filename; if your system
166
147
# does not like double slashes in filenames, you may need to add some logic
167
148
 
168
 
        if [ -d "$dst" ]
 
149
        if [ -d $dst ]
169
150
        then
170
 
                dst=$dst/`basename "$src"`
 
151
                dst="$dst"/`basename $src`
171
152
        else
172
 
                :
 
153
                true
173
154
        fi
174
155
fi
175
156
 
176
157
## this sed command emulates the dirname command
177
 
dstdir=`echo "$dst" | sed -e 's,[^/]*$,,;s,/$,,;s,^$,.,'`
 
158
dstdir=`echo $dst | sed -e 's,[^/]*$,,;s,/$,,;s,^$,.,'`
178
159
 
179
160
# Make sure that the destination directory exists.
180
161
#  this part is taken from Noah Friedman's mkinstalldirs script
181
162
 
182
163
# Skip lots of stat calls in the usual case.
183
164
if [ ! -d "$dstdir" ]; then
184
 
defaultIFS='
185
 
        '
186
 
IFS="${IFS-$defaultIFS}"
 
165
defaultIFS='    
 
166
'
 
167
IFS="${IFS-${defaultIFS}}"
187
168
 
188
 
oIFS=$IFS
 
169
oIFS="${IFS}"
189
170
# Some sh's can't handle IFS=/ for some reason.
190
171
IFS='%'
191
 
set - `echo "$dstdir" | sed -e 's@/@%@g' -e 's@^%@/@'`
192
 
IFS=$oIFS
 
172
set - `echo ${dstdir} | sed -e 's@/@%@g' -e 's@^%@/@'`
 
173
IFS="${oIFS}"
193
174
 
194
175
pathcomp=''
195
176
 
196
177
while [ $# -ne 0 ] ; do
197
 
        pathcomp=$pathcomp$1
 
178
        pathcomp="${pathcomp}${1}"
198
179
        shift
199
180
 
200
 
        if [ ! -d "$pathcomp" ] ;
 
181
        if [ ! -d "${pathcomp}" ] ;
201
182
        then
202
 
                $mkdirprog "$pathcomp"
 
183
                $mkdirprog "${pathcomp}"
203
184
        else
204
 
                :
 
185
                true
205
186
        fi
206
187
 
207
 
        pathcomp=$pathcomp/
 
188
        pathcomp="${pathcomp}/"
208
189
done
209
190
fi
210
191
 
211
192
if [ x"$dir_arg" != x ]
212
193
then
213
 
        $doit $instcmd "$dst" &&
 
194
        $doit $instcmd $dst &&
214
195
 
215
 
        if [ x"$chowncmd" != x ]; then $doit $chowncmd "$dst"; else : ; fi &&
216
 
        if [ x"$chgrpcmd" != x ]; then $doit $chgrpcmd "$dst"; else : ; fi &&
217
 
        if [ x"$stripcmd" != x ]; then $doit $stripcmd "$dst"; else : ; fi &&
218
 
        if [ x"$chmodcmd" != x ]; then $doit $chmodcmd "$dst"; else : ; fi
 
196
        if [ x"$chowncmd" != x ]; then $doit $chowncmd $dst; else true ; fi &&
 
197
        if [ x"$chgrpcmd" != x ]; then $doit $chgrpcmd $dst; else true ; fi &&
 
198
        if [ x"$stripcmd" != x ]; then $doit $stripcmd $dst; else true ; fi &&
 
199
        if [ x"$chmodcmd" != x ]; then $doit $chmodcmd $dst; else true ; fi
219
200
else
220
201
 
221
202
# If we're going to rename the final executable, determine the name now.
222
203
 
223
 
        if [ x"$transformarg" = x ]
 
204
        if [ x"$transformarg" = x ] 
224
205
        then
225
 
                dstfile=`basename "$dst"`
 
206
                dstfile=`basename $dst`
226
207
        else
227
 
                dstfile=`basename "$dst" $transformbasename |
 
208
                dstfile=`basename $dst $transformbasename | 
228
209
                        sed $transformarg`$transformbasename
229
210
        fi
230
211
 
231
212
# don't allow the sed command to completely eliminate the filename
232
213
 
233
 
        if [ x"$dstfile" = x ]
 
214
        if [ x"$dstfile" = x ] 
234
215
        then
235
 
                dstfile=`basename "$dst"`
 
216
                dstfile=`basename $dst`
236
217
        else
237
 
                :
 
218
                true
238
219
        fi
239
220
 
240
 
# Make a couple of temp file names in the proper directory.
241
 
 
242
 
        dsttmp=$dstdir/_inst.$$_
243
 
        rmtmp=$dstdir/_rm.$$_
244
 
 
245
 
# Trap to clean up temp files at exit.
246
 
 
247
 
        trap 'status=$?; rm -f "$dsttmp" "$rmtmp" && exit $status' 0
248
 
        trap '(exit $?); exit' 1 2 13 15
 
221
# Make a temp file name in the proper directory.
 
222
 
 
223
        dsttmp=$dstdir/#inst.$$#
249
224
 
250
225
# Move or copy the file name to the temp name
251
226
 
252
 
        $doit $instcmd "$src" "$dsttmp" &&
 
227
        $doit $instcmd $src $dsttmp &&
 
228
 
 
229
        trap "rm -f ${dsttmp}" 0 &&
253
230
 
254
231
# and set any options; do chmod last to preserve setuid bits
255
232
 
257
234
# ignore errors from any of these, just make sure not to ignore
258
235
# errors from the above "$doit $instcmd $src $dsttmp" command.
259
236
 
260
 
        if [ x"$chowncmd" != x ]; then $doit $chowncmd "$dsttmp"; else :;fi &&
261
 
        if [ x"$chgrpcmd" != x ]; then $doit $chgrpcmd "$dsttmp"; else :;fi &&
262
 
        if [ x"$stripcmd" != x ]; then $doit $stripcmd "$dsttmp"; else :;fi &&
263
 
        if [ x"$chmodcmd" != x ]; then $doit $chmodcmd "$dsttmp"; else :;fi &&
264
 
 
265
 
# Now remove or move aside any old file at destination location.  We try this
266
 
# two ways since rm can't unlink itself on some systems and the destination
267
 
# file might be busy for other reasons.  In this case, the final cleanup
268
 
# might fail but the new file should still install successfully.
269
 
 
270
 
{
271
 
        if [ -f "$dstdir/$dstfile" ]
272
 
        then
273
 
                $doit $rmcmd -f "$dstdir/$dstfile" 2>/dev/null ||
274
 
                $doit $mvcmd -f "$dstdir/$dstfile" "$rmtmp" 2>/dev/null ||
275
 
                {
276
 
                  echo "$0: cannot unlink or rename $dstdir/$dstfile" >&2
277
 
                  (exit 1); exit
278
 
                }
279
 
        else
280
 
                :
281
 
        fi
282
 
} &&
 
237
        if [ x"$chowncmd" != x ]; then $doit $chowncmd $dsttmp; else true;fi &&
 
238
        if [ x"$chgrpcmd" != x ]; then $doit $chgrpcmd $dsttmp; else true;fi &&
 
239
        if [ x"$stripcmd" != x ]; then $doit $stripcmd $dsttmp; else true;fi &&
 
240
        if [ x"$chmodcmd" != x ]; then $doit $chmodcmd $dsttmp; else true;fi &&
283
241
 
284
242
# Now rename the file to the real destination.
285
243
 
286
 
        $doit $mvcmd "$dsttmp" "$dstdir/$dstfile"
 
244
        $doit $rmcmd -f $dstdir/$dstfile &&
 
245
        $doit $mvcmd $dsttmp $dstdir/$dstfile 
287
246
 
288
247
fi &&
289
248
 
290
 
# The final little trick to "correctly" pass the exit status to the exit trap.
291
249
 
292
 
{
293
 
        (exit 0); exit
294
 
}
 
250
exit 0