annotate src/libvorbis-1.3.3/install-sh @ 1:05aa0afa9217

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