~ubuntu-branches/debian/squeeze/ntp/squeeze-201010051545

« back to all changes in this revision

Viewing changes to install-sh

  • Committer: Bazaar Package Importer
  • Author(s): Matt Zimmerman
  • Date: 2004-10-11 16:10:27 UTC
  • mfrom: (1.1.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20041011161027-icyjbji8ujym633o
Tags: 1:4.2.0a-10ubuntu2
Use ntp.ubuntulinux.org instead of pool.ntp.org

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
#! /bin/sh
 
1
#!/bin/sh
2
2
#
3
3
# install - install a program, script, or datafile
4
 
# This comes from X11R5.
 
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.
5
35
#
6
36
# Calling this script install-sh is preferred over install.sh, to prevent
7
37
# `make' implicit rules from creating a file called install from it
8
38
# when there is no Makefile.
9
39
#
10
40
# This script is compatible with the BSD install script, but was written
11
 
# from scratch.
12
 
#
 
41
# from scratch.  It can only install one file at a time, a restriction
 
42
# shared with many OS's install programs.
13
43
 
14
44
 
15
45
# set DOITPROG to echo to test this script
44
74
 
45
75
while [ x"$1" != x ]; do
46
76
    case $1 in
47
 
        -c) instcmd="$cpprog"
 
77
        -c) instcmd=$cpprog
48
78
            shift
49
79
            continue;;
50
80
 
67
97
            shift
68
98
            continue;;
69
99
 
70
 
        -s) stripcmd="$stripprog"
 
100
        -s) stripcmd=$stripprog
71
101
            shift
72
102
            continue;;
73
103
 
94
124
 
95
125
if [ x"$src" = x ]
96
126
then
97
 
        echo "install:  no input file specified"
 
127
        echo "$0: no input file specified" >&2
98
128
        exit 1
99
129
else
100
 
        true
 
130
        :
101
131
fi
102
132
 
103
133
if [ x"$dir_arg" != x ]; then
104
134
        dst=$src
105
135
        src=""
106
 
        
107
 
        if [ -d $dst ]; then
 
136
 
 
137
        if [ -d "$dst" ]; then
108
138
                instcmd=:
 
139
                chmodcmd=""
109
140
        else
110
 
                instcmd=mkdir
 
141
                instcmd=$mkdirprog
111
142
        fi
112
143
else
113
144
 
114
145
# Waiting for this to be detected by the "$instcmd $src $dsttmp" command
115
 
# might cause directories to be created, which would be especially bad 
 
146
# might cause directories to be created, which would be especially bad
116
147
# if $src (and thus $dsttmp) contains '*'.
117
148
 
118
 
        if [ -f $src -o -d $src ]
 
149
        if [ -f "$src" ] || [ -d "$src" ]
119
150
        then
120
 
                true
 
151
                :
121
152
        else
122
 
                echo "install:  $src does not exist"
 
153
                echo "$0: $src does not exist" >&2
123
154
                exit 1
124
155
        fi
125
 
        
 
156
 
126
157
        if [ x"$dst" = x ]
127
158
        then
128
 
                echo "install:  no destination specified"
 
159
                echo "$0: no destination specified" >&2
129
160
                exit 1
130
161
        else
131
 
                true
 
162
                :
132
163
        fi
133
164
 
134
165
# If destination is a directory, append the input filename; if your system
135
166
# does not like double slashes in filenames, you may need to add some logic
136
167
 
137
 
        if [ -d $dst ]
 
168
        if [ -d "$dst" ]
138
169
        then
139
 
                dst="$dst"/`basename $src`
 
170
                dst=$dst/`basename "$src"`
140
171
        else
141
 
                true
 
172
                :
142
173
        fi
143
174
fi
144
175
 
145
176
## this sed command emulates the dirname command
146
 
dstdir=`echo $dst | sed -e 's,[^/]*$,,;s,/$,,;s,^$,.,'`
 
177
dstdir=`echo "$dst" | sed -e 's,[^/]*$,,;s,/$,,;s,^$,.,'`
147
178
 
148
179
# Make sure that the destination directory exists.
149
180
#  this part is taken from Noah Friedman's mkinstalldirs script
150
181
 
151
182
# Skip lots of stat calls in the usual case.
152
183
if [ ! -d "$dstdir" ]; then
153
 
defaultIFS='    
154
 
'
155
 
IFS="${IFS-${defaultIFS}}"
 
184
defaultIFS='
 
185
        '
 
186
IFS="${IFS-$defaultIFS}"
156
187
 
157
 
oIFS="${IFS}"
 
188
oIFS=$IFS
158
189
# Some sh's can't handle IFS=/ for some reason.
159
190
IFS='%'
160
 
set - `echo ${dstdir} | sed -e 's@/@%@g' -e 's@^%@/@'`
161
 
IFS="${oIFS}"
 
191
set - `echo "$dstdir" | sed -e 's@/@%@g' -e 's@^%@/@'`
 
192
IFS=$oIFS
162
193
 
163
194
pathcomp=''
164
195
 
165
196
while [ $# -ne 0 ] ; do
166
 
        pathcomp="${pathcomp}${1}"
 
197
        pathcomp=$pathcomp$1
167
198
        shift
168
199
 
169
 
        if [ ! -d "${pathcomp}" ] ;
 
200
        if [ ! -d "$pathcomp" ] ;
170
201
        then
171
 
                $mkdirprog "${pathcomp}"
 
202
                $mkdirprog "$pathcomp"
172
203
        else
173
 
                true
 
204
                :
174
205
        fi
175
206
 
176
 
        pathcomp="${pathcomp}/"
 
207
        pathcomp=$pathcomp/
177
208
done
178
209
fi
179
210
 
180
211
if [ x"$dir_arg" != x ]
181
212
then
182
 
        $doit $instcmd $dst &&
 
213
        $doit $instcmd "$dst" &&
183
214
 
184
 
        if [ x"$chowncmd" != x ]; then $doit $chowncmd $dst; else true ; fi &&
185
 
        if [ x"$chgrpcmd" != x ]; then $doit $chgrpcmd $dst; else true ; fi &&
186
 
        if [ x"$stripcmd" != x ]; then $doit $stripcmd $dst; else true ; fi &&
187
 
        if [ x"$chmodcmd" != x ]; then $doit $chmodcmd $dst; else true ; fi
 
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
188
219
else
189
220
 
190
221
# If we're going to rename the final executable, determine the name now.
191
222
 
192
 
        if [ x"$transformarg" = x ] 
 
223
        if [ x"$transformarg" = x ]
193
224
        then
194
 
                dstfile=`basename $dst`
 
225
                dstfile=`basename "$dst"`
195
226
        else
196
 
                dstfile=`basename $dst $transformbasename | 
 
227
                dstfile=`basename "$dst" $transformbasename |
197
228
                        sed $transformarg`$transformbasename
198
229
        fi
199
230
 
200
231
# don't allow the sed command to completely eliminate the filename
201
232
 
202
 
        if [ x"$dstfile" = x ] 
 
233
        if [ x"$dstfile" = x ]
203
234
        then
204
 
                dstfile=`basename $dst`
 
235
                dstfile=`basename "$dst"`
205
236
        else
206
 
                true
 
237
                :
207
238
        fi
208
239
 
209
 
# Make a temp file name in the proper directory.
210
 
 
211
 
        dsttmp=$dstdir/#inst.$$#
 
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
212
249
 
213
250
# Move or copy the file name to the temp name
214
251
 
215
 
        $doit $instcmd $src $dsttmp &&
216
 
 
217
 
        trap "rm -f ${dsttmp}" 0 &&
 
252
        $doit $instcmd "$src" "$dsttmp" &&
218
253
 
219
254
# and set any options; do chmod last to preserve setuid bits
220
255
 
222
257
# ignore errors from any of these, just make sure not to ignore
223
258
# errors from the above "$doit $instcmd $src $dsttmp" command.
224
259
 
225
 
        if [ x"$chowncmd" != x ]; then $doit $chowncmd $dsttmp; else true;fi &&
226
 
        if [ x"$chgrpcmd" != x ]; then $doit $chgrpcmd $dsttmp; else true;fi &&
227
 
        if [ x"$stripcmd" != x ]; then $doit $stripcmd $dsttmp; else true;fi &&
228
 
        if [ x"$chmodcmd" != x ]; then $doit $chmodcmd $dsttmp; else true;fi &&
 
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
} &&
229
283
 
230
284
# Now rename the file to the real destination.
231
285
 
232
 
        $doit $rmcmd -f $dstdir/$dstfile &&
233
 
        $doit $mvcmd $dsttmp $dstdir/$dstfile 
 
286
        $doit $mvcmd "$dsttmp" "$dstdir/$dstfile"
234
287
 
235
288
fi &&
236
289
 
 
290
# The final little trick to "correctly" pass the exit status to the exit trap.
237
291
 
238
 
exit 0
 
292
{
 
293
        (exit 0); exit
 
294
}