~ubuntu-branches/ubuntu/intrepid/plplot/intrepid

« back to all changes in this revision

Viewing changes to libltdl/install-sh

  • Committer: Bazaar Package Importer
  • Author(s): Rafael Laboissiere
  • Date: 2006-11-04 10:19:34 UTC
  • mfrom: (2.1.8 edgy)
  • Revision ID: james.westby@ubuntu.com-20061104101934-mlirvdg4gpwi6i5q
Tags: 5.6.1-10
* Orphaning the package
* debian/control: Changed the maintainer to the Debian QA Group

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=2004-02-15.20
 
4
scriptversion=2005-11-07.23
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
58
58
rmprog="${RMPROG-rm}"
59
59
mkdirprog="${MKDIRPROG-mkdir}"
60
60
 
61
 
transformbasename=
62
 
transform_arg=
63
 
instcmd="$mvprog"
64
 
chmodcmd="$chmodprog 0755"
 
61
posix_glob=
 
62
posix_mkdir=
 
63
 
 
64
# Symbolic mode for testing mkdir with directories.
 
65
# It is the same as 755, but also tests that "u+" works.
 
66
test_mode=u=rwx,g=rx,o=rx,u+wx
 
67
 
 
68
# Desired mode of installed file.
 
69
mode=0755
 
70
 
 
71
# Desired mode of newly created intermediate directories.
 
72
# It is empty if not known yet.
 
73
intermediate_mode=
 
74
 
 
75
chmodcmd=$chmodprog
65
76
chowncmd=
66
77
chgrpcmd=
67
78
stripcmd=
70
81
src=
71
82
dst=
72
83
dir_arg=
 
84
dstarg=
 
85
no_target_directory=
73
86
 
74
 
usage="Usage: $0 [OPTION]... SRCFILE DSTFILE
 
87
usage="Usage: $0 [OPTION]... [-T] SRCFILE DSTFILE
75
88
   or: $0 [OPTION]... SRCFILES... DIRECTORY
76
 
   or: $0 -d DIRECTORIES...
 
89
   or: $0 [OPTION]... -t DIRECTORY SRCFILES...
 
90
   or: $0 [OPTION]... -d DIRECTORIES...
77
91
 
78
 
In the first form, install SRCFILE to DSTFILE, removing SRCFILE by default.
79
 
In the second, create the directory path DIR.
 
92
In the 1st form, copy SRCFILE to DSTFILE.
 
93
In the 2nd and 3rd, copy all SRCFILES to DIRECTORY.
 
94
In the 4th, create DIRECTORIES.
80
95
 
81
96
Options:
82
 
-b=TRANSFORMBASENAME
83
 
-c         copy source (using $cpprog) instead of moving (using $mvprog).
 
97
-c         (ignored)
84
98
-d         create directories instead of installing files.
85
 
-g GROUP   $chgrp installed files to GROUP.
86
 
-m MODE    $chmod installed files to MODE.
87
 
-o USER    $chown installed files to USER.
88
 
-s         strip installed files (using $stripprog).
89
 
-t=TRANSFORM
 
99
-g GROUP   $chgrpprog installed files to GROUP.
 
100
-m MODE    $chmodprog installed files to MODE.
 
101
-o USER    $chownprog installed files to USER.
 
102
-s         $stripprog installed files.
 
103
-t DIRECTORY  install into DIRECTORY.
 
104
-T         report an error if DSTFILE is a directory.
90
105
--help     display this help and exit.
91
106
--version  display version info and exit.
92
107
 
96
111
 
97
112
while test -n "$1"; do
98
113
  case $1 in
99
 
    -b=*) transformbasename=`echo $1 | sed 's/-b=//'`
100
 
        shift
101
 
        continue;;
102
 
 
103
 
    -c) instcmd=$cpprog
104
 
        shift
 
114
    -c) shift
105
115
        continue;;
106
116
 
107
117
    -d) dir_arg=true
113
123
        shift
114
124
        continue;;
115
125
 
116
 
    --help) echo "$usage"; exit 0;;
 
126
    --help) echo "$usage"; exit $?;;
117
127
 
118
 
    -m) chmodcmd="$chmodprog $2"
 
128
    -m) mode=$2
119
129
        shift
120
130
        shift
121
131
        continue;;
129
139
        shift
130
140
        continue;;
131
141
 
132
 
    -t=*) transformarg=`echo $1 | sed 's/-t=//'`
133
 
        shift
134
 
        continue;;
135
 
 
136
 
    --version) echo "$0 $scriptversion"; exit 0;;
 
142
    -t) dstarg=$2
 
143
        shift
 
144
        shift
 
145
        continue;;
 
146
 
 
147
    -T) no_target_directory=true
 
148
        shift
 
149
        continue;;
 
150
 
 
151
    --version) echo "$0 $scriptversion"; exit $?;;
137
152
 
138
153
    *)  # When -d is used, all remaining arguments are directories to create.
139
 
        test -n "$dir_arg" && break
 
154
        # When -t is used, the destination is already specified.
 
155
        test -n "$dir_arg$dstarg" && break
140
156
        # Otherwise, the last argument is the destination.  Remove it from $@.
141
157
        for arg
142
158
        do
162
178
  exit 0
163
179
fi
164
180
 
 
181
test -n "$dir_arg" || trap '(exit $?); exit' 1 2 13 15
 
182
 
165
183
for src
166
184
do
167
185
  # Protect names starting with `-'.
171
189
 
172
190
  if test -n "$dir_arg"; then
173
191
    dst=$src
174
 
    src=
 
192
    dstdir=$dst
 
193
    test -d "$dstdir"
 
194
    dstdir_status=$?
 
195
  else
175
196
 
176
 
    if test -d "$dst"; then
177
 
      instcmd=:
178
 
      chmodcmd=
179
 
    else
180
 
      instcmd=$mkdirprog
181
 
    fi
182
 
  else
183
 
    # Waiting for this to be detected by the "$instcmd $src $dsttmp" command
 
197
    # Waiting for this to be detected by the "$cpprog $src $dsttmp" command
184
198
    # might cause directories to be created, which would be especially bad
185
199
    # if $src (and thus $dsttmp) contains '*'.
186
200
    if test ! -f "$src" && test ! -d "$src"; then
202
216
    # If destination is a directory, append the input filename; won't work
203
217
    # if double slashes aren't ignored.
204
218
    if test -d "$dst"; then
205
 
      dst=$dst/`basename "$src"`
 
219
      if test -n "$no_target_directory"; then
 
220
        echo "$0: $dstarg: Is a directory" >&2
 
221
        exit 1
 
222
      fi
 
223
      dstdir=$dst
 
224
      dst=$dstdir/`basename "$src"`
 
225
      dstdir_status=0
 
226
    else
 
227
      # Prefer dirname, but fall back on a substitute if dirname fails.
 
228
      dstdir=`
 
229
        (dirname "$dst") 2>/dev/null ||
 
230
        expr X"$dst" : 'X\(.*[^/]\)//*[^/][^/]*/*$' \| \
 
231
             X"$dst" : 'X\(//\)[^/]' \| \
 
232
             X"$dst" : 'X\(//\)$' \| \
 
233
             X"$dst" : 'X\(/\)' \| \
 
234
             .       : '\(.\)' 2>/dev/null ||
 
235
        echo X"$dst" |
 
236
            sed '/^X\(.*[^/]\)\/\/*[^/][^/]*\/*$/{ s//\1/; q; }
 
237
                  /^X\(\/\/\)[^/].*/{ s//\1/; q; }
 
238
                  /^X\(\/\/\)$/{ s//\1/; q; }
 
239
                  /^X\(\/\).*/{ s//\1/; q; }
 
240
                  s/.*/./; q'
 
241
      `
 
242
 
 
243
      test -d "$dstdir"
 
244
      dstdir_status=$?
206
245
    fi
207
246
  fi
208
247
 
209
 
  # This sed command emulates the dirname command.
210
 
  dstdir=`echo "$dst" | sed -e 's,[^/]*$,,;s,/$,,;s,^$,.,'`
211
 
 
212
 
  # Make sure that the destination directory exists.
213
 
 
214
 
  # Skip lots of stat calls in the usual case.
215
 
  if test ! -d "$dstdir"; then
216
 
    defaultIFS='
217
 
         '
218
 
    IFS="${IFS-$defaultIFS}"
219
 
 
220
 
    oIFS=$IFS
221
 
    # Some sh's can't handle IFS=/ for some reason.
222
 
    IFS='%'
223
 
    set - `echo "$dstdir" | sed -e 's@/@%@g' -e 's@^%@/@'`
224
 
    IFS=$oIFS
225
 
 
226
 
    pathcomp=
227
 
 
228
 
    while test $# -ne 0 ; do
229
 
      pathcomp=$pathcomp$1
 
248
  obsolete_mkdir_used=false
 
249
 
 
250
  if test $dstdir_status != 0; then
 
251
    case $posix_mkdir in
 
252
      '')
 
253
        posix_mkdir=false
 
254
        if $mkdirprog -m $test_mode -p -- / >/dev/null 2>&1; then
 
255
          posix_mkdir=true
 
256
        else
 
257
          # Remove any dirs left behind by ancient mkdir implementations.
 
258
          rmdir ./-m "$test_mode" ./-p ./-- 2>/dev/null
 
259
        fi ;;
 
260
    esac
 
261
 
 
262
    if
 
263
      $posix_mkdir && {
 
264
 
 
265
        # With -d, create the new directory with the user-specified mode.
 
266
        # Otherwise, create it using the same intermediate mode that
 
267
        # mkdir -p would use when creating intermediate directories.
 
268
        # POSIX says that this mode is "$(umask -S),u+wx", so use that
 
269
        # if umask -S works.
 
270
 
 
271
        if test -n "$dir_arg"; then
 
272
          mkdir_mode=$mode
 
273
        else
 
274
          case $intermediate_mode in
 
275
            '')
 
276
              if umask_S=`(umask -S) 2>/dev/null`; then
 
277
                intermediate_mode=$umask_S,u+wx
 
278
              else
 
279
                intermediate_mode=$test_mode
 
280
              fi ;;
 
281
          esac
 
282
          mkdir_mode=$intermediate_mode
 
283
        fi
 
284
 
 
285
        $mkdirprog -m "$mkdir_mode" -p -- "$dstdir"
 
286
      }
 
287
    then :
 
288
    else
 
289
 
 
290
      # mkdir does not conform to POSIX, or it failed possibly due to
 
291
      # a race condition.  Create the directory the slow way, step by
 
292
      # step, checking for races as we go.
 
293
 
 
294
      case $dstdir in
 
295
        /*) pathcomp=/ ;;
 
296
        -*) pathcomp=./ ;;
 
297
        *)  pathcomp= ;;
 
298
      esac
 
299
 
 
300
      case $posix_glob in
 
301
        '')
 
302
          if (set -f) 2>/dev/null; then
 
303
            posix_glob=true
 
304
          else
 
305
            posix_glob=false
 
306
          fi ;;
 
307
      esac
 
308
 
 
309
      oIFS=$IFS
 
310
      IFS=/
 
311
      $posix_glob && set -f
 
312
      set fnord $dstdir
230
313
      shift
231
 
      if test ! -d "$pathcomp"; then
232
 
        $mkdirprog "$pathcomp" || lasterr=$?
233
 
        # mkdir can fail with a `File exist' error in case several
234
 
        # install-sh are creating the directory concurrently.  This
235
 
        # is OK.
236
 
        test ! -d "$pathcomp" && { (exit ${lasterr-1}); exit; }
237
 
      fi
238
 
      pathcomp=$pathcomp/
239
 
    done
 
314
      $posix_glob && set +f
 
315
      IFS=$oIFS
 
316
 
 
317
      for d
 
318
      do
 
319
        test "x$d" = x && continue
 
320
 
 
321
        pathcomp=$pathcomp$d
 
322
        if test ! -d "$pathcomp"; then
 
323
          $mkdirprog "$pathcomp"
 
324
          # Don't fail if two instances are running concurrently.
 
325
          test -d "$pathcomp" || exit 1
 
326
        fi
 
327
        pathcomp=$pathcomp/
 
328
      done
 
329
      obsolete_mkdir_used=true
 
330
    fi
240
331
  fi
241
332
 
242
333
  if test -n "$dir_arg"; then
243
 
    $doit $instcmd "$dst" \
244
 
      && { test -z "$chowncmd" || $doit $chowncmd "$dst"; } \
245
 
      && { test -z "$chgrpcmd" || $doit $chgrpcmd "$dst"; } \
246
 
      && { test -z "$stripcmd" || $doit $stripcmd "$dst"; } \
247
 
      && { test -z "$chmodcmd" || $doit $chmodcmd "$dst"; }
248
 
 
 
334
    { test -z "$chowncmd" || $doit $chowncmd "$dst"; } &&
 
335
    { test -z "$chgrpcmd" || $doit $chgrpcmd "$dst"; } &&
 
336
    { test "$obsolete_mkdir_used$chowncmd$chgrpcmd" = false ||
 
337
      test -z "$chmodcmd" || $doit $chmodcmd "$mode" "$dst"; } || exit 1
249
338
  else
250
 
    # If we're going to rename the final executable, determine the name now.
251
 
    if test -z "$transformarg"; then
252
 
      dstfile=`basename "$dst"`
253
 
    else
254
 
      dstfile=`basename "$dst" $transformbasename \
255
 
               | sed $transformarg`$transformbasename
256
 
    fi
257
 
 
258
 
    # don't allow the sed command to completely eliminate the filename.
259
 
    test -z "$dstfile" && dstfile=`basename "$dst"`
260
339
 
261
340
    # Make a couple of temp file names in the proper directory.
262
341
    dsttmp=$dstdir/_inst.$$_
263
342
    rmtmp=$dstdir/_rm.$$_
264
343
 
265
344
    # Trap to clean up those temp files at exit.
266
 
    trap 'status=$?; rm -f "$dsttmp" "$rmtmp" && exit $status' 0
267
 
    trap '(exit $?); exit' 1 2 13 15
 
345
    trap 'ret=$?; rm -f "$dsttmp" "$rmtmp" && exit $ret' 0
268
346
 
269
 
    # Move or copy the file name to the temp name
270
 
    $doit $instcmd "$src" "$dsttmp" &&
 
347
    # Copy the file name to the temp name.
 
348
    $doit $cpprog "$src" "$dsttmp" &&
271
349
 
272
350
    # and set any options; do chmod last to preserve setuid bits.
273
351
    #
274
352
    # If any of these fail, we abort the whole thing.  If we want to
275
353
    # ignore errors from any of these, just make sure not to ignore
276
 
    # errors from the above "$doit $instcmd $src $dsttmp" command.
 
354
    # errors from the above "$doit $cpprog $src $dsttmp" command.
277
355
    #
278
356
    { test -z "$chowncmd" || $doit $chowncmd "$dsttmp"; } \
279
357
      && { test -z "$chgrpcmd" || $doit $chgrpcmd "$dsttmp"; } \
280
358
      && { test -z "$stripcmd" || $doit $stripcmd "$dsttmp"; } \
281
 
      && { test -z "$chmodcmd" || $doit $chmodcmd "$dsttmp"; } &&
282
 
 
283
 
    # Now remove or move aside any old file at destination location.  We
284
 
    # try this two ways since rm can't unlink itself on some systems and
285
 
    # the destination file might be busy for other reasons.  In this case,
286
 
    # the final cleanup might fail but the new file should still install
287
 
    # successfully.
288
 
    {
289
 
      if test -f "$dstdir/$dstfile"; then
290
 
        $doit $rmcmd -f "$dstdir/$dstfile" 2>/dev/null \
291
 
        || $doit $mvcmd -f "$dstdir/$dstfile" "$rmtmp" 2>/dev/null \
292
 
        || {
293
 
          echo "$0: cannot unlink or rename $dstdir/$dstfile" >&2
294
 
          (exit 1); exit
295
 
        }
296
 
      else
297
 
        :
298
 
      fi
299
 
    } &&
 
359
      && { test -z "$chmodcmd" || $doit $chmodcmd "$mode" "$dsttmp"; } &&
300
360
 
301
361
    # Now rename the file to the real destination.
302
 
    $doit $mvcmd "$dsttmp" "$dstdir/$dstfile"
303
 
  fi || { (exit 1); exit; }
 
362
    { $doit $mvcmd -f "$dsttmp" "$dst" 2>/dev/null \
 
363
      || {
 
364
           # The rename failed, perhaps because mv can't rename something else
 
365
           # to itself, or perhaps because mv is so ancient that it does not
 
366
           # support -f.
 
367
 
 
368
           # Now remove or move aside any old file at destination location.
 
369
           # We try this two ways since rm can't unlink itself on some
 
370
           # systems and the destination file might be busy for other
 
371
           # reasons.  In this case, the final cleanup might fail but the new
 
372
           # file should still install successfully.
 
373
           {
 
374
             if test -f "$dst"; then
 
375
               $doit $rmcmd -f "$dst" 2>/dev/null \
 
376
               || { $doit $mvcmd -f "$dst" "$rmtmp" 2>/dev/null \
 
377
                     && { $doit $rmcmd -f "$rmtmp" 2>/dev/null; :; }; }\
 
378
               || {
 
379
                 echo "$0: cannot unlink or rename $dst" >&2
 
380
                 (exit 1); exit 1
 
381
               }
 
382
             else
 
383
               :
 
384
             fi
 
385
           } &&
 
386
 
 
387
           # Now rename the file to the real destination.
 
388
           $doit $mvcmd "$dsttmp" "$dst"
 
389
         }
 
390
    } || exit 1
 
391
 
 
392
    trap '' 0
 
393
  fi
304
394
done
305
395
 
306
 
# The final little trick to "correctly" pass the exit status to the exit trap.
307
 
{
308
 
  (exit 0); exit
309
 
}
310
 
 
311
396
# Local variables:
312
397
# eval: (add-hook 'write-file-hooks 'time-stamp)
313
398
# time-stamp-start: "scriptversion="