annotate src/flac-1.2.1/install-sh @ 83:ae30d91d2ffe

Replace these with versions built using an older toolset (so as to avoid ABI compatibilities when linking on Ubuntu 14.04 for packaging purposes)
author Chris Cannam
date Fri, 07 Feb 2020 11:51:13 +0000
parents 05aa0afa9217
children
rev   line source
Chris@1 1 #!/bin/sh
Chris@1 2 #
Chris@1 3 # install - install a program, script, or datafile
Chris@1 4 #
Chris@1 5 # This originates from X11R5 (mit/util/scripts/install.sh), which was
Chris@1 6 # later released in X11R6 (xc/config/util/install.sh) with the
Chris@1 7 # following copyright and license.
Chris@1 8 #
Chris@1 9 # Copyright (C) 1994 X Consortium
Chris@1 10 #
Chris@1 11 # Permission is hereby granted, free of charge, to any person obtaining a copy
Chris@1 12 # of this software and associated documentation files (the "Software"), to
Chris@1 13 # deal in the Software without restriction, including without limitation the
Chris@1 14 # rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
Chris@1 15 # sell copies of the Software, and to permit persons to whom the Software is
Chris@1 16 # furnished to do so, subject to the following conditions:
Chris@1 17 #
Chris@1 18 # The above copyright notice and this permission notice shall be included in
Chris@1 19 # all copies or substantial portions of the Software.
Chris@1 20 #
Chris@1 21 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
Chris@1 22 # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
Chris@1 23 # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
Chris@1 24 # X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
Chris@1 25 # AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNEC-
Chris@1 26 # TION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
Chris@1 27 #
Chris@1 28 # Except as contained in this notice, the name of the X Consortium shall not
Chris@1 29 # be used in advertising or otherwise to promote the sale, use or other deal-
Chris@1 30 # ings in this Software without prior written authorization from the X Consor-
Chris@1 31 # tium.
Chris@1 32 #
Chris@1 33 #
Chris@1 34 # FSF changes to this file are in the public domain.
Chris@1 35 #
Chris@1 36 # Calling this script install-sh is preferred over install.sh, to prevent
Chris@1 37 # `make' implicit rules from creating a file called install from it
Chris@1 38 # when there is no Makefile.
Chris@1 39 #
Chris@1 40 # This script is compatible with the BSD install script, but was written
Chris@1 41 # from scratch. It can only install one file at a time, a restriction
Chris@1 42 # shared with many OS's install programs.
Chris@1 43
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
Chris@1 51 # put in absolute paths if you don't have them in your path; or use env. vars.
Chris@1 52
Chris@1 53 mvprog="${MVPROG-mv}"
Chris@1 54 cpprog="${CPPROG-cp}"
Chris@1 55 chmodprog="${CHMODPROG-chmod}"
Chris@1 56 chownprog="${CHOWNPROG-chown}"
Chris@1 57 chgrpprog="${CHGRPPROG-chgrp}"
Chris@1 58 stripprog="${STRIPPROG-strip}"
Chris@1 59 rmprog="${RMPROG-rm}"
Chris@1 60 mkdirprog="${MKDIRPROG-mkdir}"
Chris@1 61
Chris@1 62 transformbasename=""
Chris@1 63 transform_arg=""
Chris@1 64 instcmd="$mvprog"
Chris@1 65 chmodcmd="$chmodprog 0755"
Chris@1 66 chowncmd=""
Chris@1 67 chgrpcmd=""
Chris@1 68 stripcmd=""
Chris@1 69 rmcmd="$rmprog -f"
Chris@1 70 mvcmd="$mvprog"
Chris@1 71 src=""
Chris@1 72 dst=""
Chris@1 73 dir_arg=""
Chris@1 74
Chris@1 75 while [ x"$1" != x ]; do
Chris@1 76 case $1 in
Chris@1 77 -c) instcmd=$cpprog
Chris@1 78 shift
Chris@1 79 continue;;
Chris@1 80
Chris@1 81 -d) dir_arg=true
Chris@1 82 shift
Chris@1 83 continue;;
Chris@1 84
Chris@1 85 -m) chmodcmd="$chmodprog $2"
Chris@1 86 shift
Chris@1 87 shift
Chris@1 88 continue;;
Chris@1 89
Chris@1 90 -o) chowncmd="$chownprog $2"
Chris@1 91 shift
Chris@1 92 shift
Chris@1 93 continue;;
Chris@1 94
Chris@1 95 -g) chgrpcmd="$chgrpprog $2"
Chris@1 96 shift
Chris@1 97 shift
Chris@1 98 continue;;
Chris@1 99
Chris@1 100 -s) stripcmd=$stripprog
Chris@1 101 shift
Chris@1 102 continue;;
Chris@1 103
Chris@1 104 -t=*) transformarg=`echo $1 | sed 's/-t=//'`
Chris@1 105 shift
Chris@1 106 continue;;
Chris@1 107
Chris@1 108 -b=*) transformbasename=`echo $1 | sed 's/-b=//'`
Chris@1 109 shift
Chris@1 110 continue;;
Chris@1 111
Chris@1 112 *) if [ x"$src" = x ]
Chris@1 113 then
Chris@1 114 src=$1
Chris@1 115 else
Chris@1 116 # this colon is to work around a 386BSD /bin/sh bug
Chris@1 117 :
Chris@1 118 dst=$1
Chris@1 119 fi
Chris@1 120 shift
Chris@1 121 continue;;
Chris@1 122 esac
Chris@1 123 done
Chris@1 124
Chris@1 125 if [ x"$src" = x ]
Chris@1 126 then
Chris@1 127 echo "$0: no input file specified" >&2
Chris@1 128 exit 1
Chris@1 129 else
Chris@1 130 :
Chris@1 131 fi
Chris@1 132
Chris@1 133 if [ x"$dir_arg" != x ]; then
Chris@1 134 dst=$src
Chris@1 135 src=""
Chris@1 136
Chris@1 137 if [ -d "$dst" ]; then
Chris@1 138 instcmd=:
Chris@1 139 chmodcmd=""
Chris@1 140 else
Chris@1 141 instcmd=$mkdirprog
Chris@1 142 fi
Chris@1 143 else
Chris@1 144
Chris@1 145 # Waiting for this to be detected by the "$instcmd $src $dsttmp" command
Chris@1 146 # might cause directories to be created, which would be especially bad
Chris@1 147 # if $src (and thus $dsttmp) contains '*'.
Chris@1 148
Chris@1 149 if [ -f "$src" ] || [ -d "$src" ]
Chris@1 150 then
Chris@1 151 :
Chris@1 152 else
Chris@1 153 echo "$0: $src does not exist" >&2
Chris@1 154 exit 1
Chris@1 155 fi
Chris@1 156
Chris@1 157 if [ x"$dst" = x ]
Chris@1 158 then
Chris@1 159 echo "$0: no destination specified" >&2
Chris@1 160 exit 1
Chris@1 161 else
Chris@1 162 :
Chris@1 163 fi
Chris@1 164
Chris@1 165 # If destination is a directory, append the input filename; if your system
Chris@1 166 # does not like double slashes in filenames, you may need to add some logic
Chris@1 167
Chris@1 168 if [ -d "$dst" ]
Chris@1 169 then
Chris@1 170 dst=$dst/`basename "$src"`
Chris@1 171 else
Chris@1 172 :
Chris@1 173 fi
Chris@1 174 fi
Chris@1 175
Chris@1 176 ## this sed command emulates the dirname command
Chris@1 177 dstdir=`echo "$dst" | sed -e 's,[^/]*$,,;s,/$,,;s,^$,.,'`
Chris@1 178
Chris@1 179 # Make sure that the destination directory exists.
Chris@1 180 # this part is taken from Noah Friedman's mkinstalldirs script
Chris@1 181
Chris@1 182 # Skip lots of stat calls in the usual case.
Chris@1 183 if [ ! -d "$dstdir" ]; then
Chris@1 184 defaultIFS='
Chris@1 185 '
Chris@1 186 IFS="${IFS-$defaultIFS}"
Chris@1 187
Chris@1 188 oIFS=$IFS
Chris@1 189 # Some sh's can't handle IFS=/ for some reason.
Chris@1 190 IFS='%'
Chris@1 191 set - `echo "$dstdir" | sed -e 's@/@%@g' -e 's@^%@/@'`
Chris@1 192 IFS=$oIFS
Chris@1 193
Chris@1 194 pathcomp=''
Chris@1 195
Chris@1 196 while [ $# -ne 0 ] ; do
Chris@1 197 pathcomp=$pathcomp$1
Chris@1 198 shift
Chris@1 199
Chris@1 200 if [ ! -d "$pathcomp" ] ;
Chris@1 201 then
Chris@1 202 $mkdirprog "$pathcomp"
Chris@1 203 else
Chris@1 204 :
Chris@1 205 fi
Chris@1 206
Chris@1 207 pathcomp=$pathcomp/
Chris@1 208 done
Chris@1 209 fi
Chris@1 210
Chris@1 211 if [ x"$dir_arg" != x ]
Chris@1 212 then
Chris@1 213 $doit $instcmd "$dst" &&
Chris@1 214
Chris@1 215 if [ x"$chowncmd" != x ]; then $doit $chowncmd "$dst"; else : ; fi &&
Chris@1 216 if [ x"$chgrpcmd" != x ]; then $doit $chgrpcmd "$dst"; else : ; fi &&
Chris@1 217 if [ x"$stripcmd" != x ]; then $doit $stripcmd "$dst"; else : ; fi &&
Chris@1 218 if [ x"$chmodcmd" != x ]; then $doit $chmodcmd "$dst"; else : ; fi
Chris@1 219 else
Chris@1 220
Chris@1 221 # If we're going to rename the final executable, determine the name now.
Chris@1 222
Chris@1 223 if [ x"$transformarg" = x ]
Chris@1 224 then
Chris@1 225 dstfile=`basename "$dst"`
Chris@1 226 else
Chris@1 227 dstfile=`basename "$dst" $transformbasename |
Chris@1 228 sed $transformarg`$transformbasename
Chris@1 229 fi
Chris@1 230
Chris@1 231 # don't allow the sed command to completely eliminate the filename
Chris@1 232
Chris@1 233 if [ x"$dstfile" = x ]
Chris@1 234 then
Chris@1 235 dstfile=`basename "$dst"`
Chris@1 236 else
Chris@1 237 :
Chris@1 238 fi
Chris@1 239
Chris@1 240 # Make a couple of temp file names in the proper directory.
Chris@1 241
Chris@1 242 dsttmp=$dstdir/_inst.$$_
Chris@1 243 rmtmp=$dstdir/_rm.$$_
Chris@1 244
Chris@1 245 # Trap to clean up temp files at exit.
Chris@1 246
Chris@1 247 trap 'status=$?; rm -f "$dsttmp" "$rmtmp" && exit $status' 0
Chris@1 248 trap '(exit $?); exit' 1 2 13 15
Chris@1 249
Chris@1 250 # Move or copy the file name to the temp name
Chris@1 251
Chris@1 252 $doit $instcmd "$src" "$dsttmp" &&
Chris@1 253
Chris@1 254 # and set any options; do chmod last to preserve setuid bits
Chris@1 255
Chris@1 256 # If any of these fail, we abort the whole thing. If we want to
Chris@1 257 # ignore errors from any of these, just make sure not to ignore
Chris@1 258 # errors from the above "$doit $instcmd $src $dsttmp" command.
Chris@1 259
Chris@1 260 if [ x"$chowncmd" != x ]; then $doit $chowncmd "$dsttmp"; else :;fi &&
Chris@1 261 if [ x"$chgrpcmd" != x ]; then $doit $chgrpcmd "$dsttmp"; else :;fi &&
Chris@1 262 if [ x"$stripcmd" != x ]; then $doit $stripcmd "$dsttmp"; else :;fi &&
Chris@1 263 if [ x"$chmodcmd" != x ]; then $doit $chmodcmd "$dsttmp"; else :;fi &&
Chris@1 264
Chris@1 265 # Now remove or move aside any old file at destination location. We try this
Chris@1 266 # two ways since rm can't unlink itself on some systems and the destination
Chris@1 267 # file might be busy for other reasons. In this case, the final cleanup
Chris@1 268 # might fail but the new file should still install successfully.
Chris@1 269
Chris@1 270 {
Chris@1 271 if [ -f "$dstdir/$dstfile" ]
Chris@1 272 then
Chris@1 273 $doit $rmcmd -f "$dstdir/$dstfile" 2>/dev/null ||
Chris@1 274 $doit $mvcmd -f "$dstdir/$dstfile" "$rmtmp" 2>/dev/null ||
Chris@1 275 {
Chris@1 276 echo "$0: cannot unlink or rename $dstdir/$dstfile" >&2
Chris@1 277 (exit 1); exit
Chris@1 278 }
Chris@1 279 else
Chris@1 280 :
Chris@1 281 fi
Chris@1 282 } &&
Chris@1 283
Chris@1 284 # Now rename the file to the real destination.
Chris@1 285
Chris@1 286 $doit $mvcmd "$dsttmp" "$dstdir/$dstfile"
Chris@1 287
Chris@1 288 fi &&
Chris@1 289
Chris@1 290 # The final little trick to "correctly" pass the exit status to the exit trap.
Chris@1 291
Chris@1 292 {
Chris@1 293 (exit 0); exit
Chris@1 294 }