gst-gpac/install-sh
author melunko
Thu Mar 13 16:29:38 2008 +0000 (2008-03-13)
branchtrunk
changeset 942 c93bfa74c71f
permissions -rwxr-xr-x
[svn r951] gmyth now is 0.8.1. Added methods epg_is_connected() and scheduler_is_connected()
melunko@917
     1
#!/bin/sh
melunko@917
     2
# install - install a program, script, or datafile
melunko@917
     3
melunko@917
     4
scriptversion=2005-05-14.22
melunko@917
     5
melunko@917
     6
# This originates from X11R5 (mit/util/scripts/install.sh), which was
melunko@917
     7
# later released in X11R6 (xc/config/util/install.sh) with the
melunko@917
     8
# following copyright and license.
melunko@917
     9
#
melunko@917
    10
# Copyright (C) 1994 X Consortium
melunko@917
    11
#
melunko@917
    12
# Permission is hereby granted, free of charge, to any person obtaining a copy
melunko@917
    13
# of this software and associated documentation files (the "Software"), to
melunko@917
    14
# deal in the Software without restriction, including without limitation the
melunko@917
    15
# rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
melunko@917
    16
# sell copies of the Software, and to permit persons to whom the Software is
melunko@917
    17
# furnished to do so, subject to the following conditions:
melunko@917
    18
#
melunko@917
    19
# The above copyright notice and this permission notice shall be included in
melunko@917
    20
# all copies or substantial portions of the Software.
melunko@917
    21
#
melunko@917
    22
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
melunko@917
    23
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
melunko@917
    24
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
melunko@917
    25
# X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
melunko@917
    26
# AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNEC-
melunko@917
    27
# TION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
melunko@917
    28
#
melunko@917
    29
# Except as contained in this notice, the name of the X Consortium shall not
melunko@917
    30
# be used in advertising or otherwise to promote the sale, use or other deal-
melunko@917
    31
# ings in this Software without prior written authorization from the X Consor-
melunko@917
    32
# tium.
melunko@917
    33
#
melunko@917
    34
#
melunko@917
    35
# FSF changes to this file are in the public domain.
melunko@917
    36
#
melunko@917
    37
# Calling this script install-sh is preferred over install.sh, to prevent
melunko@917
    38
# `make' implicit rules from creating a file called install from it
melunko@917
    39
# when there is no Makefile.
melunko@917
    40
#
melunko@917
    41
# This script is compatible with the BSD install script, but was written
melunko@917
    42
# from scratch.  It can only install one file at a time, a restriction
melunko@917
    43
# shared with many OS's install programs.
melunko@917
    44
melunko@917
    45
# set DOITPROG to echo to test this script
melunko@917
    46
melunko@917
    47
# Don't use :- since 4.3BSD and earlier shells don't like it.
melunko@917
    48
doit="${DOITPROG-}"
melunko@917
    49
melunko@917
    50
# put in absolute paths if you don't have them in your path; or use env. vars.
melunko@917
    51
melunko@917
    52
mvprog="${MVPROG-mv}"
melunko@917
    53
cpprog="${CPPROG-cp}"
melunko@917
    54
chmodprog="${CHMODPROG-chmod}"
melunko@917
    55
chownprog="${CHOWNPROG-chown}"
melunko@917
    56
chgrpprog="${CHGRPPROG-chgrp}"
melunko@917
    57
stripprog="${STRIPPROG-strip}"
melunko@917
    58
rmprog="${RMPROG-rm}"
melunko@917
    59
mkdirprog="${MKDIRPROG-mkdir}"
melunko@917
    60
melunko@917
    61
chmodcmd="$chmodprog 0755"
melunko@917
    62
chowncmd=
melunko@917
    63
chgrpcmd=
melunko@917
    64
stripcmd=
melunko@917
    65
rmcmd="$rmprog -f"
melunko@917
    66
mvcmd="$mvprog"
melunko@917
    67
src=
melunko@917
    68
dst=
melunko@917
    69
dir_arg=
melunko@917
    70
dstarg=
melunko@917
    71
no_target_directory=
melunko@917
    72
melunko@917
    73
usage="Usage: $0 [OPTION]... [-T] SRCFILE DSTFILE
melunko@917
    74
   or: $0 [OPTION]... SRCFILES... DIRECTORY
melunko@917
    75
   or: $0 [OPTION]... -t DIRECTORY SRCFILES...
melunko@917
    76
   or: $0 [OPTION]... -d DIRECTORIES...
melunko@917
    77
melunko@917
    78
In the 1st form, copy SRCFILE to DSTFILE.
melunko@917
    79
In the 2nd and 3rd, copy all SRCFILES to DIRECTORY.
melunko@917
    80
In the 4th, create DIRECTORIES.
melunko@917
    81
melunko@917
    82
Options:
melunko@917
    83
-c         (ignored)
melunko@917
    84
-d         create directories instead of installing files.
melunko@917
    85
-g GROUP   $chgrpprog installed files to GROUP.
melunko@917
    86
-m MODE    $chmodprog installed files to MODE.
melunko@917
    87
-o USER    $chownprog installed files to USER.
melunko@917
    88
-s         $stripprog installed files.
melunko@917
    89
-t DIRECTORY  install into DIRECTORY.
melunko@917
    90
-T         report an error if DSTFILE is a directory.
melunko@917
    91
--help     display this help and exit.
melunko@917
    92
--version  display version info and exit.
melunko@917
    93
melunko@917
    94
Environment variables override the default commands:
melunko@917
    95
  CHGRPPROG CHMODPROG CHOWNPROG CPPROG MKDIRPROG MVPROG RMPROG STRIPPROG
melunko@917
    96
"
melunko@917
    97
melunko@917
    98
while test -n "$1"; do
melunko@917
    99
  case $1 in
melunko@917
   100
    -c) shift
melunko@917
   101
        continue;;
melunko@917
   102
melunko@917
   103
    -d) dir_arg=true
melunko@917
   104
        shift
melunko@917
   105
        continue;;
melunko@917
   106
melunko@917
   107
    -g) chgrpcmd="$chgrpprog $2"
melunko@917
   108
        shift
melunko@917
   109
        shift
melunko@917
   110
        continue;;
melunko@917
   111
melunko@917
   112
    --help) echo "$usage"; exit $?;;
melunko@917
   113
melunko@917
   114
    -m) chmodcmd="$chmodprog $2"
melunko@917
   115
        shift
melunko@917
   116
        shift
melunko@917
   117
        continue;;
melunko@917
   118
melunko@917
   119
    -o) chowncmd="$chownprog $2"
melunko@917
   120
        shift
melunko@917
   121
        shift
melunko@917
   122
        continue;;
melunko@917
   123
melunko@917
   124
    -s) stripcmd=$stripprog
melunko@917
   125
        shift
melunko@917
   126
        continue;;
melunko@917
   127
melunko@917
   128
    -t) dstarg=$2
melunko@917
   129
	shift
melunko@917
   130
	shift
melunko@917
   131
	continue;;
melunko@917
   132
melunko@917
   133
    -T) no_target_directory=true
melunko@917
   134
	shift
melunko@917
   135
	continue;;
melunko@917
   136
melunko@917
   137
    --version) echo "$0 $scriptversion"; exit $?;;
melunko@917
   138
melunko@917
   139
    *)  # When -d is used, all remaining arguments are directories to create.
melunko@917
   140
	# When -t is used, the destination is already specified.
melunko@917
   141
	test -n "$dir_arg$dstarg" && break
melunko@917
   142
        # Otherwise, the last argument is the destination.  Remove it from $@.
melunko@917
   143
	for arg
melunko@917
   144
	do
melunko@917
   145
          if test -n "$dstarg"; then
melunko@917
   146
	    # $@ is not empty: it contains at least $arg.
melunko@917
   147
	    set fnord "$@" "$dstarg"
melunko@917
   148
	    shift # fnord
melunko@917
   149
	  fi
melunko@917
   150
	  shift # arg
melunko@917
   151
	  dstarg=$arg
melunko@917
   152
	done
melunko@917
   153
	break;;
melunko@917
   154
  esac
melunko@917
   155
done
melunko@917
   156
melunko@917
   157
if test -z "$1"; then
melunko@917
   158
  if test -z "$dir_arg"; then
melunko@917
   159
    echo "$0: no input file specified." >&2
melunko@917
   160
    exit 1
melunko@917
   161
  fi
melunko@917
   162
  # It's OK to call `install-sh -d' without argument.
melunko@917
   163
  # This can happen when creating conditional directories.
melunko@917
   164
  exit 0
melunko@917
   165
fi
melunko@917
   166
melunko@917
   167
for src
melunko@917
   168
do
melunko@917
   169
  # Protect names starting with `-'.
melunko@917
   170
  case $src in
melunko@917
   171
    -*) src=./$src ;;
melunko@917
   172
  esac
melunko@917
   173
melunko@917
   174
  if test -n "$dir_arg"; then
melunko@917
   175
    dst=$src
melunko@917
   176
    src=
melunko@917
   177
melunko@917
   178
    if test -d "$dst"; then
melunko@917
   179
      mkdircmd=:
melunko@917
   180
      chmodcmd=
melunko@917
   181
    else
melunko@917
   182
      mkdircmd=$mkdirprog
melunko@917
   183
    fi
melunko@917
   184
  else
melunko@917
   185
    # Waiting for this to be detected by the "$cpprog $src $dsttmp" command
melunko@917
   186
    # might cause directories to be created, which would be especially bad
melunko@917
   187
    # if $src (and thus $dsttmp) contains '*'.
melunko@917
   188
    if test ! -f "$src" && test ! -d "$src"; then
melunko@917
   189
      echo "$0: $src does not exist." >&2
melunko@917
   190
      exit 1
melunko@917
   191
    fi
melunko@917
   192
melunko@917
   193
    if test -z "$dstarg"; then
melunko@917
   194
      echo "$0: no destination specified." >&2
melunko@917
   195
      exit 1
melunko@917
   196
    fi
melunko@917
   197
melunko@917
   198
    dst=$dstarg
melunko@917
   199
    # Protect names starting with `-'.
melunko@917
   200
    case $dst in
melunko@917
   201
      -*) dst=./$dst ;;
melunko@917
   202
    esac
melunko@917
   203
melunko@917
   204
    # If destination is a directory, append the input filename; won't work
melunko@917
   205
    # if double slashes aren't ignored.
melunko@917
   206
    if test -d "$dst"; then
melunko@917
   207
      if test -n "$no_target_directory"; then
melunko@917
   208
	echo "$0: $dstarg: Is a directory" >&2
melunko@917
   209
	exit 1
melunko@917
   210
      fi
melunko@917
   211
      dst=$dst/`basename "$src"`
melunko@917
   212
    fi
melunko@917
   213
  fi
melunko@917
   214
melunko@917
   215
  # This sed command emulates the dirname command.
melunko@917
   216
  dstdir=`echo "$dst" | sed -e 's,/*$,,;s,[^/]*$,,;s,/*$,,;s,^$,.,'`
melunko@917
   217
melunko@917
   218
  # Make sure that the destination directory exists.
melunko@917
   219
melunko@917
   220
  # Skip lots of stat calls in the usual case.
melunko@917
   221
  if test ! -d "$dstdir"; then
melunko@917
   222
    defaultIFS='
melunko@917
   223
	 '
melunko@917
   224
    IFS="${IFS-$defaultIFS}"
melunko@917
   225
melunko@917
   226
    oIFS=$IFS
melunko@917
   227
    # Some sh's can't handle IFS=/ for some reason.
melunko@917
   228
    IFS='%'
melunko@917
   229
    set x `echo "$dstdir" | sed -e 's@/@%@g' -e 's@^%@/@'`
melunko@917
   230
    shift
melunko@917
   231
    IFS=$oIFS
melunko@917
   232
melunko@917
   233
    pathcomp=
melunko@917
   234
melunko@917
   235
    while test $# -ne 0 ; do
melunko@917
   236
      pathcomp=$pathcomp$1
melunko@917
   237
      shift
melunko@917
   238
      if test ! -d "$pathcomp"; then
melunko@917
   239
        $mkdirprog "$pathcomp"
melunko@917
   240
	# mkdir can fail with a `File exist' error in case several
melunko@917
   241
	# install-sh are creating the directory concurrently.  This
melunko@917
   242
	# is OK.
melunko@917
   243
	test -d "$pathcomp" || exit
melunko@917
   244
      fi
melunko@917
   245
      pathcomp=$pathcomp/
melunko@917
   246
    done
melunko@917
   247
  fi
melunko@917
   248
melunko@917
   249
  if test -n "$dir_arg"; then
melunko@917
   250
    $doit $mkdircmd "$dst" \
melunko@917
   251
      && { test -z "$chowncmd" || $doit $chowncmd "$dst"; } \
melunko@917
   252
      && { test -z "$chgrpcmd" || $doit $chgrpcmd "$dst"; } \
melunko@917
   253
      && { test -z "$stripcmd" || $doit $stripcmd "$dst"; } \
melunko@917
   254
      && { test -z "$chmodcmd" || $doit $chmodcmd "$dst"; }
melunko@917
   255
melunko@917
   256
  else
melunko@917
   257
    dstfile=`basename "$dst"`
melunko@917
   258
melunko@917
   259
    # Make a couple of temp file names in the proper directory.
melunko@917
   260
    dsttmp=$dstdir/_inst.$$_
melunko@917
   261
    rmtmp=$dstdir/_rm.$$_
melunko@917
   262
melunko@917
   263
    # Trap to clean up those temp files at exit.
melunko@917
   264
    trap 'ret=$?; rm -f "$dsttmp" "$rmtmp" && exit $ret' 0
melunko@917
   265
    trap '(exit $?); exit' 1 2 13 15
melunko@917
   266
melunko@917
   267
    # Copy the file name to the temp name.
melunko@917
   268
    $doit $cpprog "$src" "$dsttmp" &&
melunko@917
   269
melunko@917
   270
    # and set any options; do chmod last to preserve setuid bits.
melunko@917
   271
    #
melunko@917
   272
    # If any of these fail, we abort the whole thing.  If we want to
melunko@917
   273
    # ignore errors from any of these, just make sure not to ignore
melunko@917
   274
    # errors from the above "$doit $cpprog $src $dsttmp" command.
melunko@917
   275
    #
melunko@917
   276
    { test -z "$chowncmd" || $doit $chowncmd "$dsttmp"; } \
melunko@917
   277
      && { test -z "$chgrpcmd" || $doit $chgrpcmd "$dsttmp"; } \
melunko@917
   278
      && { test -z "$stripcmd" || $doit $stripcmd "$dsttmp"; } \
melunko@917
   279
      && { test -z "$chmodcmd" || $doit $chmodcmd "$dsttmp"; } &&
melunko@917
   280
melunko@917
   281
    # Now rename the file to the real destination.
melunko@917
   282
    { $doit $mvcmd -f "$dsttmp" "$dstdir/$dstfile" 2>/dev/null \
melunko@917
   283
      || {
melunko@917
   284
	   # The rename failed, perhaps because mv can't rename something else
melunko@917
   285
	   # to itself, or perhaps because mv is so ancient that it does not
melunko@917
   286
	   # support -f.
melunko@917
   287
melunko@917
   288
	   # Now remove or move aside any old file at destination location.
melunko@917
   289
	   # We try this two ways since rm can't unlink itself on some
melunko@917
   290
	   # systems and the destination file might be busy for other
melunko@917
   291
	   # reasons.  In this case, the final cleanup might fail but the new
melunko@917
   292
	   # file should still install successfully.
melunko@917
   293
	   {
melunko@917
   294
	     if test -f "$dstdir/$dstfile"; then
melunko@917
   295
	       $doit $rmcmd -f "$dstdir/$dstfile" 2>/dev/null \
melunko@917
   296
	       || $doit $mvcmd -f "$dstdir/$dstfile" "$rmtmp" 2>/dev/null \
melunko@917
   297
	       || {
melunko@917
   298
		 echo "$0: cannot unlink or rename $dstdir/$dstfile" >&2
melunko@917
   299
		 (exit 1); exit 1
melunko@917
   300
	       }
melunko@917
   301
	     else
melunko@917
   302
	       :
melunko@917
   303
	     fi
melunko@917
   304
	   } &&
melunko@917
   305
melunko@917
   306
	   # Now rename the file to the real destination.
melunko@917
   307
	   $doit $mvcmd "$dsttmp" "$dstdir/$dstfile"
melunko@917
   308
	 }
melunko@917
   309
    }
melunko@917
   310
  fi || { (exit 1); exit 1; }
melunko@917
   311
done
melunko@917
   312
melunko@917
   313
# The final little trick to "correctly" pass the exit status to the exit trap.
melunko@917
   314
{
melunko@917
   315
  (exit 0); exit 0
melunko@917
   316
}
melunko@917
   317
melunko@917
   318
# Local variables:
melunko@917
   319
# eval: (add-hook 'write-file-hooks 'time-stamp)
melunko@917
   320
# time-stamp-start: "scriptversion="
melunko@917
   321
# time-stamp-format: "%:y-%02m-%02d.%02H"
melunko@917
   322
# time-stamp-end: "$"
melunko@917
   323
# End: