~ubuntu-branches/ubuntu/utopic/libxpm/utopic

« back to all changes in this revision

Viewing changes to install-sh

  • Committer: Bazaar Package Importer
  • Author(s): Julien Cristau
  • Date: 2007-08-25 10:50:50 UTC
  • mfrom: (1.1.4 upstream) (3.1.1 lenny)
  • Revision ID: james.westby@ubuntu.com-20070825105050-xbytdxkw7wuclhca
Tags: 1:3.5.7-1
* New upstream release.
* Add the upstream URL to debian/copyright.
* Use binary:Version instead of the deprecated Source-Version.
* Add myself to uploaders, and remove Branden with his permission.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
#!/bin/sh
2
2
# install - install a program, script, or datafile
3
3
 
4
 
scriptversion=2005-05-14.22
 
4
scriptversion=2006-10-14.15
5
5
 
6
6
# This originates from X11R5 (mit/util/scripts/install.sh), which was
7
7
# later released in X11R6 (xc/config/util/install.sh) with the
39
39
# when there is no Makefile.
40
40
#
41
41
# This script is compatible with the BSD install script, but was written
42
 
# from scratch.  It can only install one file at a time, a restriction
43
 
# shared with many OS's install programs.
 
42
# from scratch.
 
43
 
 
44
nl='
 
45
'
 
46
IFS=" ""        $nl"
44
47
 
45
48
# set DOITPROG to echo to test this script
46
49
 
47
50
# Don't use :- since 4.3BSD and earlier shells don't like it.
48
51
doit="${DOITPROG-}"
 
52
if test -z "$doit"; then
 
53
  doit_exec=exec
 
54
else
 
55
  doit_exec=$doit
 
56
fi
49
57
 
50
 
# put in absolute paths if you don't have them in your path; or use env. vars.
 
58
# Put in absolute file names if you don't have them in your path;
 
59
# or use environment vars.
51
60
 
52
61
mvprog="${MVPROG-mv}"
53
62
cpprog="${CPPROG-cp}"
58
67
rmprog="${RMPROG-rm}"
59
68
mkdirprog="${MKDIRPROG-mkdir}"
60
69
 
61
 
chmodcmd="$chmodprog 0755"
 
70
posix_glob=
 
71
posix_mkdir=
 
72
 
 
73
# Desired mode of installed file.
 
74
mode=0755
 
75
 
 
76
chmodcmd=$chmodprog
62
77
chowncmd=
63
78
chgrpcmd=
64
79
stripcmd=
95
110
  CHGRPPROG CHMODPROG CHOWNPROG CPPROG MKDIRPROG MVPROG RMPROG STRIPPROG
96
111
"
97
112
 
98
 
while test -n "$1"; do
 
113
while test $# -ne 0; do
99
114
  case $1 in
100
115
    -c) shift
101
116
        continue;;
111
126
 
112
127
    --help) echo "$usage"; exit $?;;
113
128
 
114
 
    -m) chmodcmd="$chmodprog $2"
115
 
        shift
116
 
        shift
 
129
    -m) mode=$2
 
130
        shift
 
131
        shift
 
132
        case $mode in
 
133
          *' '* | *'    '* | *'
 
134
'*        | *'*'* | *'?'* | *'['*)
 
135
            echo "$0: invalid mode: $mode" >&2
 
136
            exit 1;;
 
137
        esac
117
138
        continue;;
118
139
 
119
140
    -o) chowncmd="$chownprog $2"
136
157
 
137
158
    --version) echo "$0 $scriptversion"; exit $?;;
138
159
 
139
 
    *)  # When -d is used, all remaining arguments are directories to create.
140
 
        # When -t is used, the destination is already specified.
141
 
        test -n "$dir_arg$dstarg" && break
142
 
        # Otherwise, the last argument is the destination.  Remove it from $@.
143
 
        for arg
144
 
        do
145
 
          if test -n "$dstarg"; then
146
 
            # $@ is not empty: it contains at least $arg.
147
 
            set fnord "$@" "$dstarg"
148
 
            shift # fnord
149
 
          fi
150
 
          shift # arg
151
 
          dstarg=$arg
152
 
        done
 
160
    --) shift
153
161
        break;;
 
162
 
 
163
    -*) echo "$0: invalid option: $1" >&2
 
164
        exit 1;;
 
165
 
 
166
    *)  break;;
154
167
  esac
155
168
done
156
169
 
157
 
if test -z "$1"; then
 
170
if test $# -ne 0 && test -z "$dir_arg$dstarg"; then
 
171
  # When -d is used, all remaining arguments are directories to create.
 
172
  # When -t is used, the destination is already specified.
 
173
  # Otherwise, the last argument is the destination.  Remove it from $@.
 
174
  for arg
 
175
  do
 
176
    if test -n "$dstarg"; then
 
177
      # $@ is not empty: it contains at least $arg.
 
178
      set fnord "$@" "$dstarg"
 
179
      shift # fnord
 
180
    fi
 
181
    shift # arg
 
182
    dstarg=$arg
 
183
  done
 
184
fi
 
185
 
 
186
if test $# -eq 0; then
158
187
  if test -z "$dir_arg"; then
159
188
    echo "$0: no input file specified." >&2
160
189
    exit 1
164
193
  exit 0
165
194
fi
166
195
 
 
196
if test -z "$dir_arg"; then
 
197
  trap '(exit $?); exit' 1 2 13 15
 
198
 
 
199
  # Set umask so as not to create temps with too-generous modes.
 
200
  # However, 'strip' requires both read and write access to temps.
 
201
  case $mode in
 
202
    # Optimize common cases.
 
203
    *644) cp_umask=133;;
 
204
    *755) cp_umask=22;;
 
205
 
 
206
    *[0-7])
 
207
      if test -z "$stripcmd"; then
 
208
        u_plus_rw=
 
209
      else
 
210
        u_plus_rw='% 200'
 
211
      fi
 
212
      cp_umask=`expr '(' 777 - $mode % 1000 ')' $u_plus_rw`;;
 
213
    *)
 
214
      if test -z "$stripcmd"; then
 
215
        u_plus_rw=
 
216
      else
 
217
        u_plus_rw=,u+rw
 
218
      fi
 
219
      cp_umask=$mode$u_plus_rw;;
 
220
  esac
 
221
fi
 
222
 
167
223
for src
168
224
do
169
225
  # Protect names starting with `-'.
173
229
 
174
230
  if test -n "$dir_arg"; then
175
231
    dst=$src
176
 
    src=
 
232
    dstdir=$dst
 
233
    test -d "$dstdir"
 
234
    dstdir_status=$?
 
235
  else
177
236
 
178
 
    if test -d "$dst"; then
179
 
      mkdircmd=:
180
 
      chmodcmd=
181
 
    else
182
 
      mkdircmd=$mkdirprog
183
 
    fi
184
 
  else
185
237
    # Waiting for this to be detected by the "$cpprog $src $dsttmp" command
186
238
    # might cause directories to be created, which would be especially bad
187
239
    # if $src (and thus $dsttmp) contains '*'.
208
260
        echo "$0: $dstarg: Is a directory" >&2
209
261
        exit 1
210
262
      fi
211
 
      dst=$dst/`basename "$src"`
 
263
      dstdir=$dst
 
264
      dst=$dstdir/`basename "$src"`
 
265
      dstdir_status=0
 
266
    else
 
267
      # Prefer dirname, but fall back on a substitute if dirname fails.
 
268
      dstdir=`
 
269
        (dirname "$dst") 2>/dev/null ||
 
270
        expr X"$dst" : 'X\(.*[^/]\)//*[^/][^/]*/*$' \| \
 
271
             X"$dst" : 'X\(//\)[^/]' \| \
 
272
             X"$dst" : 'X\(//\)$' \| \
 
273
             X"$dst" : 'X\(/\)' \| . 2>/dev/null ||
 
274
        echo X"$dst" |
 
275
            sed '/^X\(.*[^/]\)\/\/*[^/][^/]*\/*$/{
 
276
                   s//\1/
 
277
                   q
 
278
                 }
 
279
                 /^X\(\/\/\)[^/].*/{
 
280
                   s//\1/
 
281
                   q
 
282
                 }
 
283
                 /^X\(\/\/\)$/{
 
284
                   s//\1/
 
285
                   q
 
286
                 }
 
287
                 /^X\(\/\).*/{
 
288
                   s//\1/
 
289
                   q
 
290
                 }
 
291
                 s/.*/./; q'
 
292
      `
 
293
 
 
294
      test -d "$dstdir"
 
295
      dstdir_status=$?
212
296
    fi
213
297
  fi
214
298
 
215
 
  # This sed command emulates the dirname command.
216
 
  dstdir=`echo "$dst" | sed -e 's,/*$,,;s,[^/]*$,,;s,/*$,,;s,^$,.,'`
217
 
 
218
 
  # Make sure that the destination directory exists.
219
 
 
220
 
  # Skip lots of stat calls in the usual case.
221
 
  if test ! -d "$dstdir"; then
222
 
    defaultIFS='
223
 
         '
224
 
    IFS="${IFS-$defaultIFS}"
225
 
 
226
 
    oIFS=$IFS
227
 
    # Some sh's can't handle IFS=/ for some reason.
228
 
    IFS='%'
229
 
    set x `echo "$dstdir" | sed -e 's@/@%@g' -e 's@^%@/@'`
230
 
    shift
231
 
    IFS=$oIFS
232
 
 
233
 
    pathcomp=
234
 
 
235
 
    while test $# -ne 0 ; do
236
 
      pathcomp=$pathcomp$1
 
299
  obsolete_mkdir_used=false
 
300
 
 
301
  if test $dstdir_status != 0; then
 
302
    case $posix_mkdir in
 
303
      '')
 
304
        # Create intermediate dirs using mode 755 as modified by the umask.
 
305
        # This is like FreeBSD 'install' as of 1997-10-28.
 
306
        umask=`umask`
 
307
        case $stripcmd.$umask in
 
308
          # Optimize common cases.
 
309
          *[2367][2367]) mkdir_umask=$umask;;
 
310
          .*0[02][02] | .[02][02] | .[02]) mkdir_umask=22;;
 
311
 
 
312
          *[0-7])
 
313
            mkdir_umask=`expr $umask + 22 \
 
314
              - $umask % 100 % 40 + $umask % 20 \
 
315
              - $umask % 10 % 4 + $umask % 2
 
316
            `;;
 
317
          *) mkdir_umask=$umask,go-w;;
 
318
        esac
 
319
 
 
320
        # With -d, create the new directory with the user-specified mode.
 
321
        # Otherwise, rely on $mkdir_umask.
 
322
        if test -n "$dir_arg"; then
 
323
          mkdir_mode=-m$mode
 
324
        else
 
325
          mkdir_mode=
 
326
        fi
 
327
 
 
328
        posix_mkdir=false
 
329
        case $umask in
 
330
          *[123567][0-7][0-7])
 
331
            # POSIX mkdir -p sets u+wx bits regardless of umask, which
 
332
            # is incompatible with FreeBSD 'install' when (umask & 300) != 0.
 
333
            ;;
 
334
          *)
 
335
            tmpdir=${TMPDIR-/tmp}/ins$RANDOM-$$
 
336
            trap 'ret=$?; rmdir "$tmpdir/d" "$tmpdir" 2>/dev/null; exit $ret' 0
 
337
 
 
338
            if (umask $mkdir_umask &&
 
339
                exec $mkdirprog $mkdir_mode -p -- "$tmpdir/d") >/dev/null 2>&1
 
340
            then
 
341
              if test -z "$dir_arg" || {
 
342
                   # Check for POSIX incompatibilities with -m.
 
343
                   # HP-UX 11.23 and IRIX 6.5 mkdir -m -p sets group- or
 
344
                   # other-writeable bit of parent directory when it shouldn't.
 
345
                   # FreeBSD 6.1 mkdir -m -p sets mode of existing directory.
 
346
                   ls_ld_tmpdir=`ls -ld "$tmpdir"`
 
347
                   case $ls_ld_tmpdir in
 
348
                     d????-?r-*) different_mode=700;;
 
349
                     d????-?--*) different_mode=755;;
 
350
                     *) false;;
 
351
                   esac &&
 
352
                   $mkdirprog -m$different_mode -p -- "$tmpdir" && {
 
353
                     ls_ld_tmpdir_1=`ls -ld "$tmpdir"`
 
354
                     test "$ls_ld_tmpdir" = "$ls_ld_tmpdir_1"
 
355
                   }
 
356
                 }
 
357
              then posix_mkdir=:
 
358
              fi
 
359
              rmdir "$tmpdir/d" "$tmpdir"
 
360
            else
 
361
              # Remove any dirs left behind by ancient mkdir implementations.
 
362
              rmdir ./$mkdir_mode ./-p ./-- 2>/dev/null
 
363
            fi
 
364
            trap '' 0;;
 
365
        esac;;
 
366
    esac
 
367
 
 
368
    if
 
369
      $posix_mkdir && (
 
370
        umask $mkdir_umask &&
 
371
        $doit_exec $mkdirprog $mkdir_mode -p -- "$dstdir"
 
372
      )
 
373
    then :
 
374
    else
 
375
 
 
376
      # The umask is ridiculous, or mkdir does not conform to POSIX,
 
377
      # or it failed possibly due to a race condition.  Create the
 
378
      # directory the slow way, step by step, checking for races as we go.
 
379
 
 
380
      case $dstdir in
 
381
        /*) prefix=/ ;;
 
382
        -*) prefix=./ ;;
 
383
        *)  prefix= ;;
 
384
      esac
 
385
 
 
386
      case $posix_glob in
 
387
        '')
 
388
          if (set -f) 2>/dev/null; then
 
389
            posix_glob=true
 
390
          else
 
391
            posix_glob=false
 
392
          fi ;;
 
393
      esac
 
394
 
 
395
      oIFS=$IFS
 
396
      IFS=/
 
397
      $posix_glob && set -f
 
398
      set fnord $dstdir
237
399
      shift
238
 
      if test ! -d "$pathcomp"; then
239
 
        $mkdirprog "$pathcomp"
240
 
        # mkdir can fail with a `File exist' error in case several
241
 
        # install-sh are creating the directory concurrently.  This
242
 
        # is OK.
243
 
        test -d "$pathcomp" || exit
 
400
      $posix_glob && set +f
 
401
      IFS=$oIFS
 
402
 
 
403
      prefixes=
 
404
 
 
405
      for d
 
406
      do
 
407
        test -z "$d" && continue
 
408
 
 
409
        prefix=$prefix$d
 
410
        if test -d "$prefix"; then
 
411
          prefixes=
 
412
        else
 
413
          if $posix_mkdir; then
 
414
            (umask=$mkdir_umask &&
 
415
             $doit_exec $mkdirprog $mkdir_mode -p -- "$dstdir") && break
 
416
            # Don't fail if two instances are running concurrently.
 
417
            test -d "$prefix" || exit 1
 
418
          else
 
419
            case $prefix in
 
420
              *\'*) qprefix=`echo "$prefix" | sed "s/'/'\\\\\\\\''/g"`;;
 
421
              *) qprefix=$prefix;;
 
422
            esac
 
423
            prefixes="$prefixes '$qprefix'"
 
424
          fi
 
425
        fi
 
426
        prefix=$prefix/
 
427
      done
 
428
 
 
429
      if test -n "$prefixes"; then
 
430
        # Don't fail if two instances are running concurrently.
 
431
        (umask $mkdir_umask &&
 
432
         eval "\$doit_exec \$mkdirprog $prefixes") ||
 
433
          test -d "$dstdir" || exit 1
 
434
        obsolete_mkdir_used=true
244
435
      fi
245
 
      pathcomp=$pathcomp/
246
 
    done
 
436
    fi
247
437
  fi
248
438
 
249
439
  if test -n "$dir_arg"; then
250
 
    $doit $mkdircmd "$dst" \
251
 
      && { test -z "$chowncmd" || $doit $chowncmd "$dst"; } \
252
 
      && { test -z "$chgrpcmd" || $doit $chgrpcmd "$dst"; } \
253
 
      && { test -z "$stripcmd" || $doit $stripcmd "$dst"; } \
254
 
      && { test -z "$chmodcmd" || $doit $chmodcmd "$dst"; }
255
 
 
 
440
    { test -z "$chowncmd" || $doit $chowncmd "$dst"; } &&
 
441
    { test -z "$chgrpcmd" || $doit $chgrpcmd "$dst"; } &&
 
442
    { test "$obsolete_mkdir_used$chowncmd$chgrpcmd" = false ||
 
443
      test -z "$chmodcmd" || $doit $chmodcmd $mode "$dst"; } || exit 1
256
444
  else
257
 
    dstfile=`basename "$dst"`
258
445
 
259
446
    # Make a couple of temp file names in the proper directory.
260
447
    dsttmp=$dstdir/_inst.$$_
262
449
 
263
450
    # Trap to clean up those temp files at exit.
264
451
    trap 'ret=$?; rm -f "$dsttmp" "$rmtmp" && exit $ret' 0
265
 
    trap '(exit $?); exit' 1 2 13 15
266
452
 
267
453
    # Copy the file name to the temp name.
268
 
    $doit $cpprog "$src" "$dsttmp" &&
 
454
    (umask $cp_umask && $doit_exec $cpprog "$src" "$dsttmp") &&
269
455
 
270
456
    # and set any options; do chmod last to preserve setuid bits.
271
457
    #
276
462
    { test -z "$chowncmd" || $doit $chowncmd "$dsttmp"; } \
277
463
      && { test -z "$chgrpcmd" || $doit $chgrpcmd "$dsttmp"; } \
278
464
      && { test -z "$stripcmd" || $doit $stripcmd "$dsttmp"; } \
279
 
      && { test -z "$chmodcmd" || $doit $chmodcmd "$dsttmp"; } &&
 
465
      && { test -z "$chmodcmd" || $doit $chmodcmd $mode "$dsttmp"; } &&
280
466
 
281
467
    # Now rename the file to the real destination.
282
 
    { $doit $mvcmd -f "$dsttmp" "$dstdir/$dstfile" 2>/dev/null \
 
468
    { $doit $mvcmd -f "$dsttmp" "$dst" 2>/dev/null \
283
469
      || {
284
470
           # The rename failed, perhaps because mv can't rename something else
285
471
           # to itself, or perhaps because mv is so ancient that it does not
291
477
           # reasons.  In this case, the final cleanup might fail but the new
292
478
           # file should still install successfully.
293
479
           {
294
 
             if test -f "$dstdir/$dstfile"; then
295
 
               $doit $rmcmd -f "$dstdir/$dstfile" 2>/dev/null \
296
 
               || $doit $mvcmd -f "$dstdir/$dstfile" "$rmtmp" 2>/dev/null \
 
480
             if test -f "$dst"; then
 
481
               $doit $rmcmd -f "$dst" 2>/dev/null \
 
482
               || { $doit $mvcmd -f "$dst" "$rmtmp" 2>/dev/null \
 
483
                     && { $doit $rmcmd -f "$rmtmp" 2>/dev/null; :; }; }\
297
484
               || {
298
 
                 echo "$0: cannot unlink or rename $dstdir/$dstfile" >&2
 
485
                 echo "$0: cannot unlink or rename $dst" >&2
299
486
                 (exit 1); exit 1
300
487
               }
301
488
             else
304
491
           } &&
305
492
 
306
493
           # Now rename the file to the real destination.
307
 
           $doit $mvcmd "$dsttmp" "$dstdir/$dstfile"
 
494
           $doit $mvcmd "$dsttmp" "$dst"
308
495
         }
309
 
    }
310
 
  fi || { (exit 1); exit 1; }
 
496
    } || exit 1
 
497
 
 
498
    trap '' 0
 
499
  fi
311
500
done
312
501
 
313
 
# The final little trick to "correctly" pass the exit status to the exit trap.
314
 
{
315
 
  (exit 0); exit 0
316
 
}
317
 
 
318
502
# Local variables:
319
503
# eval: (add-hook 'write-file-hooks 'time-stamp)
320
504
# time-stamp-start: "scriptversion="