~ubuntu-branches/ubuntu/maverick/kde-i18n-tg/maverick

« back to all changes in this revision

Viewing changes to admin/install-sh

  • Committer: Bazaar Package Importer
  • Author(s): Jonathan Riddell
  • Date: 2007-10-01 15:22:49 UTC
  • mfrom: (1.1.9 upstream)
  • Revision ID: james.westby@ubuntu.com-20071001152249-id1nbzjsj8n3hm1d
Tags: 4:3.5.8~pre20071001-0ubuntu1
New snapshot

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-11-07.23
 
4
scriptversion=2005-05-14.22
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
 
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
 
61
chmodcmd="$chmodprog 0755"
76
62
chowncmd=
77
63
chgrpcmd=
78
64
stripcmd=
125
111
 
126
112
    --help) echo "$usage"; exit $?;;
127
113
 
128
 
    -m) mode=$2
 
114
    -m) chmodcmd="$chmodprog $2"
129
115
        shift
130
116
        shift
131
117
        continue;;
178
164
  exit 0
179
165
fi
180
166
 
181
 
test -n "$dir_arg" || trap '(exit $?); exit' 1 2 13 15
182
 
 
183
167
for src
184
168
do
185
169
  # Protect names starting with `-'.
189
173
 
190
174
  if test -n "$dir_arg"; then
191
175
    dst=$src
192
 
    dstdir=$dst
193
 
    test -d "$dstdir"
194
 
    dstdir_status=$?
 
176
    src=
 
177
 
 
178
    if test -d "$dst"; then
 
179
      mkdircmd=:
 
180
      chmodcmd=
 
181
    else
 
182
      mkdircmd=$mkdirprog
 
183
    fi
195
184
  else
196
 
 
197
185
    # Waiting for this to be detected by the "$cpprog $src $dsttmp" command
198
186
    # might cause directories to be created, which would be especially bad
199
187
    # if $src (and thus $dsttmp) contains '*'.
220
208
        echo "$0: $dstarg: Is a directory" >&2
221
209
        exit 1
222
210
      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=$?
 
211
      dst=$dst/`basename "$src"`
245
212
    fi
246
213
  fi
247
214
 
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
 
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
313
237
      shift
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
 
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
 
244
      fi
 
245
      pathcomp=$pathcomp/
 
246
    done
331
247
  fi
332
248
 
333
249
  if test -n "$dir_arg"; then
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
 
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
 
338
256
  else
 
257
    dstfile=`basename "$dst"`
339
258
 
340
259
    # Make a couple of temp file names in the proper directory.
341
260
    dsttmp=$dstdir/_inst.$$_
343
262
 
344
263
    # Trap to clean up those temp files at exit.
345
264
    trap 'ret=$?; rm -f "$dsttmp" "$rmtmp" && exit $ret' 0
 
265
    trap '(exit $?); exit' 1 2 13 15
346
266
 
347
267
    # Copy the file name to the temp name.
348
268
    $doit $cpprog "$src" "$dsttmp" &&
356
276
    { test -z "$chowncmd" || $doit $chowncmd "$dsttmp"; } \
357
277
      && { test -z "$chgrpcmd" || $doit $chgrpcmd "$dsttmp"; } \
358
278
      && { test -z "$stripcmd" || $doit $stripcmd "$dsttmp"; } \
359
 
      && { test -z "$chmodcmd" || $doit $chmodcmd "$mode" "$dsttmp"; } &&
 
279
      && { test -z "$chmodcmd" || $doit $chmodcmd "$dsttmp"; } &&
360
280
 
361
281
    # Now rename the file to the real destination.
362
 
    { $doit $mvcmd -f "$dsttmp" "$dst" 2>/dev/null \
 
282
    { $doit $mvcmd -f "$dsttmp" "$dstdir/$dstfile" 2>/dev/null \
363
283
      || {
364
284
           # The rename failed, perhaps because mv can't rename something else
365
285
           # to itself, or perhaps because mv is so ancient that it does not
371
291
           # reasons.  In this case, the final cleanup might fail but the new
372
292
           # file should still install successfully.
373
293
           {
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; :; }; }\
 
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 \
378
297
               || {
379
 
                 echo "$0: cannot unlink or rename $dst" >&2
 
298
                 echo "$0: cannot unlink or rename $dstdir/$dstfile" >&2
380
299
                 (exit 1); exit 1
381
300
               }
382
301
             else
385
304
           } &&
386
305
 
387
306
           # Now rename the file to the real destination.
388
 
           $doit $mvcmd "$dsttmp" "$dst"
 
307
           $doit $mvcmd "$dsttmp" "$dstdir/$dstfile"
389
308
         }
390
 
    } || exit 1
391
 
 
392
 
    trap '' 0
393
 
  fi
 
309
    }
 
310
  fi || { (exit 1); exit 1; }
394
311
done
395
312
 
 
313
# The final little trick to "correctly" pass the exit status to the exit trap.
 
314
{
 
315
  (exit 0); exit 0
 
316
}
 
317
 
396
318
# Local variables:
397
319
# eval: (add-hook 'write-file-hooks 'time-stamp)
398
320
# time-stamp-start: "scriptversion="