| Chris@4 | 1 #!/bin/sh | 
| Chris@4 | 2 # install - install a program, script, or datafile | 
| Chris@4 | 3 | 
| Chris@55 | 4 scriptversion=2011-11-20.07; # UTC | 
| Chris@4 | 5 | 
| Chris@4 | 6 # This originates from X11R5 (mit/util/scripts/install.sh), which was | 
| Chris@4 | 7 # later released in X11R6 (xc/config/util/install.sh) with the | 
| Chris@4 | 8 # following copyright and license. | 
| Chris@4 | 9 # | 
| Chris@4 | 10 # Copyright (C) 1994 X Consortium | 
| Chris@4 | 11 # | 
| Chris@4 | 12 # Permission is hereby granted, free of charge, to any person obtaining a copy | 
| Chris@4 | 13 # of this software and associated documentation files (the "Software"), to | 
| Chris@4 | 14 # deal in the Software without restriction, including without limitation the | 
| Chris@4 | 15 # rights to use, copy, modify, merge, publish, distribute, sublicense, and/or | 
| Chris@4 | 16 # sell copies of the Software, and to permit persons to whom the Software is | 
| Chris@4 | 17 # furnished to do so, subject to the following conditions: | 
| Chris@4 | 18 # | 
| Chris@4 | 19 # The above copyright notice and this permission notice shall be included in | 
| Chris@4 | 20 # all copies or substantial portions of the Software. | 
| Chris@4 | 21 # | 
| Chris@4 | 22 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | 
| Chris@4 | 23 # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | 
| Chris@4 | 24 # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE | 
| Chris@4 | 25 # X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN | 
| Chris@4 | 26 # AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNEC- | 
| Chris@4 | 27 # TION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | 
| Chris@4 | 28 # | 
| Chris@4 | 29 # Except as contained in this notice, the name of the X Consortium shall not | 
| Chris@4 | 30 # be used in advertising or otherwise to promote the sale, use or other deal- | 
| Chris@4 | 31 # ings in this Software without prior written authorization from the X Consor- | 
| Chris@4 | 32 # tium. | 
| Chris@4 | 33 # | 
| Chris@4 | 34 # | 
| Chris@4 | 35 # FSF changes to this file are in the public domain. | 
| Chris@4 | 36 # | 
| Chris@4 | 37 # Calling this script install-sh is preferred over install.sh, to prevent | 
| Chris@55 | 38 # 'make' implicit rules from creating a file called install from it | 
| Chris@4 | 39 # when there is no Makefile. | 
| Chris@4 | 40 # | 
| Chris@4 | 41 # This script is compatible with the BSD install script, but was written | 
| Chris@4 | 42 # from scratch. | 
| Chris@4 | 43 | 
| Chris@4 | 44 nl=' | 
| Chris@4 | 45 ' | 
| Chris@4 | 46 IFS=" ""	$nl" | 
| Chris@4 | 47 | 
| Chris@4 | 48 # set DOITPROG to echo to test this script | 
| Chris@4 | 49 | 
| Chris@4 | 50 # Don't use :- since 4.3BSD and earlier shells don't like it. | 
| Chris@4 | 51 doit=${DOITPROG-} | 
| Chris@4 | 52 if test -z "$doit"; then | 
| Chris@4 | 53   doit_exec=exec | 
| Chris@4 | 54 else | 
| Chris@4 | 55   doit_exec=$doit | 
| Chris@4 | 56 fi | 
| Chris@4 | 57 | 
| Chris@4 | 58 # Put in absolute file names if you don't have them in your path; | 
| Chris@4 | 59 # or use environment vars. | 
| Chris@4 | 60 | 
| Chris@4 | 61 chgrpprog=${CHGRPPROG-chgrp} | 
| Chris@4 | 62 chmodprog=${CHMODPROG-chmod} | 
| Chris@4 | 63 chownprog=${CHOWNPROG-chown} | 
| Chris@4 | 64 cmpprog=${CMPPROG-cmp} | 
| Chris@4 | 65 cpprog=${CPPROG-cp} | 
| Chris@4 | 66 mkdirprog=${MKDIRPROG-mkdir} | 
| Chris@4 | 67 mvprog=${MVPROG-mv} | 
| Chris@4 | 68 rmprog=${RMPROG-rm} | 
| Chris@4 | 69 stripprog=${STRIPPROG-strip} | 
| Chris@4 | 70 | 
| Chris@4 | 71 posix_glob='?' | 
| Chris@4 | 72 initialize_posix_glob=' | 
| Chris@4 | 73   test "$posix_glob" != "?" || { | 
| Chris@4 | 74     if (set -f) 2>/dev/null; then | 
| Chris@4 | 75       posix_glob= | 
| Chris@4 | 76     else | 
| Chris@4 | 77       posix_glob=: | 
| Chris@4 | 78     fi | 
| Chris@4 | 79   } | 
| Chris@4 | 80 ' | 
| Chris@4 | 81 | 
| Chris@4 | 82 posix_mkdir= | 
| Chris@4 | 83 | 
| Chris@4 | 84 # Desired mode of installed file. | 
| Chris@4 | 85 mode=0755 | 
| Chris@4 | 86 | 
| Chris@4 | 87 chgrpcmd= | 
| Chris@4 | 88 chmodcmd=$chmodprog | 
| Chris@4 | 89 chowncmd= | 
| Chris@4 | 90 mvcmd=$mvprog | 
| Chris@4 | 91 rmcmd="$rmprog -f" | 
| Chris@4 | 92 stripcmd= | 
| Chris@4 | 93 | 
| Chris@4 | 94 src= | 
| Chris@4 | 95 dst= | 
| Chris@4 | 96 dir_arg= | 
| Chris@4 | 97 dst_arg= | 
| Chris@4 | 98 | 
| Chris@4 | 99 copy_on_change=false | 
| Chris@4 | 100 no_target_directory= | 
| Chris@4 | 101 | 
| Chris@4 | 102 usage="\ | 
| Chris@4 | 103 Usage: $0 [OPTION]... [-T] SRCFILE DSTFILE | 
| Chris@4 | 104    or: $0 [OPTION]... SRCFILES... DIRECTORY | 
| Chris@4 | 105    or: $0 [OPTION]... -t DIRECTORY SRCFILES... | 
| Chris@4 | 106    or: $0 [OPTION]... -d DIRECTORIES... | 
| Chris@4 | 107 | 
| Chris@4 | 108 In the 1st form, copy SRCFILE to DSTFILE. | 
| Chris@4 | 109 In the 2nd and 3rd, copy all SRCFILES to DIRECTORY. | 
| Chris@4 | 110 In the 4th, create DIRECTORIES. | 
| Chris@4 | 111 | 
| Chris@4 | 112 Options: | 
| Chris@4 | 113      --help     display this help and exit. | 
| Chris@4 | 114      --version  display version info and exit. | 
| Chris@4 | 115 | 
| Chris@4 | 116   -c            (ignored) | 
| Chris@4 | 117   -C            install only if different (preserve the last data modification time) | 
| Chris@4 | 118   -d            create directories instead of installing files. | 
| Chris@4 | 119   -g GROUP      $chgrpprog installed files to GROUP. | 
| Chris@4 | 120   -m MODE       $chmodprog installed files to MODE. | 
| Chris@4 | 121   -o USER       $chownprog installed files to USER. | 
| Chris@4 | 122   -s            $stripprog installed files. | 
| Chris@4 | 123   -t DIRECTORY  install into DIRECTORY. | 
| Chris@4 | 124   -T            report an error if DSTFILE is a directory. | 
| Chris@4 | 125 | 
| Chris@4 | 126 Environment variables override the default commands: | 
| Chris@4 | 127   CHGRPPROG CHMODPROG CHOWNPROG CMPPROG CPPROG MKDIRPROG MVPROG | 
| Chris@4 | 128   RMPROG STRIPPROG | 
| Chris@4 | 129 " | 
| Chris@4 | 130 | 
| Chris@4 | 131 while test $# -ne 0; do | 
| Chris@4 | 132   case $1 in | 
| Chris@4 | 133     -c) ;; | 
| Chris@4 | 134 | 
| Chris@4 | 135     -C) copy_on_change=true;; | 
| Chris@4 | 136 | 
| Chris@4 | 137     -d) dir_arg=true;; | 
| Chris@4 | 138 | 
| Chris@4 | 139     -g) chgrpcmd="$chgrpprog $2" | 
| Chris@4 | 140 	shift;; | 
| Chris@4 | 141 | 
| Chris@4 | 142     --help) echo "$usage"; exit $?;; | 
| Chris@4 | 143 | 
| Chris@4 | 144     -m) mode=$2 | 
| Chris@4 | 145 	case $mode in | 
| Chris@4 | 146 	  *' '* | *'	'* | *' | 
| Chris@4 | 147 '*	  | *'*'* | *'?'* | *'['*) | 
| Chris@4 | 148 	    echo "$0: invalid mode: $mode" >&2 | 
| Chris@4 | 149 	    exit 1;; | 
| Chris@4 | 150 	esac | 
| Chris@4 | 151 	shift;; | 
| Chris@4 | 152 | 
| Chris@4 | 153     -o) chowncmd="$chownprog $2" | 
| Chris@4 | 154 	shift;; | 
| Chris@4 | 155 | 
| Chris@4 | 156     -s) stripcmd=$stripprog;; | 
| Chris@4 | 157 | 
| Chris@4 | 158     -t) dst_arg=$2 | 
| Chris@55 | 159 	# Protect names problematic for 'test' and other utilities. | 
| Chris@55 | 160 	case $dst_arg in | 
| Chris@55 | 161 	  -* | [=\(\)!]) dst_arg=./$dst_arg;; | 
| Chris@55 | 162 	esac | 
| Chris@4 | 163 	shift;; | 
| Chris@4 | 164 | 
| Chris@4 | 165     -T) no_target_directory=true;; | 
| Chris@4 | 166 | 
| Chris@4 | 167     --version) echo "$0 $scriptversion"; exit $?;; | 
| Chris@4 | 168 | 
| Chris@4 | 169     --)	shift | 
| Chris@4 | 170 	break;; | 
| Chris@4 | 171 | 
| Chris@4 | 172     -*)	echo "$0: invalid option: $1" >&2 | 
| Chris@4 | 173 	exit 1;; | 
| Chris@4 | 174 | 
| Chris@4 | 175     *)  break;; | 
| Chris@4 | 176   esac | 
| Chris@4 | 177   shift | 
| Chris@4 | 178 done | 
| Chris@4 | 179 | 
| Chris@4 | 180 if test $# -ne 0 && test -z "$dir_arg$dst_arg"; then | 
| Chris@4 | 181   # When -d is used, all remaining arguments are directories to create. | 
| Chris@4 | 182   # When -t is used, the destination is already specified. | 
| Chris@4 | 183   # Otherwise, the last argument is the destination.  Remove it from $@. | 
| Chris@4 | 184   for arg | 
| Chris@4 | 185   do | 
| Chris@4 | 186     if test -n "$dst_arg"; then | 
| Chris@4 | 187       # $@ is not empty: it contains at least $arg. | 
| Chris@4 | 188       set fnord "$@" "$dst_arg" | 
| Chris@4 | 189       shift # fnord | 
| Chris@4 | 190     fi | 
| Chris@4 | 191     shift # arg | 
| Chris@4 | 192     dst_arg=$arg | 
| Chris@55 | 193     # Protect names problematic for 'test' and other utilities. | 
| Chris@55 | 194     case $dst_arg in | 
| Chris@55 | 195       -* | [=\(\)!]) dst_arg=./$dst_arg;; | 
| Chris@55 | 196     esac | 
| Chris@4 | 197   done | 
| Chris@4 | 198 fi | 
| Chris@4 | 199 | 
| Chris@4 | 200 if test $# -eq 0; then | 
| Chris@4 | 201   if test -z "$dir_arg"; then | 
| Chris@4 | 202     echo "$0: no input file specified." >&2 | 
| Chris@4 | 203     exit 1 | 
| Chris@4 | 204   fi | 
| Chris@55 | 205   # It's OK to call 'install-sh -d' without argument. | 
| Chris@4 | 206   # This can happen when creating conditional directories. | 
| Chris@4 | 207   exit 0 | 
| Chris@4 | 208 fi | 
| Chris@4 | 209 | 
| Chris@4 | 210 if test -z "$dir_arg"; then | 
| Chris@55 | 211   do_exit='(exit $ret); exit $ret' | 
| Chris@55 | 212   trap "ret=129; $do_exit" 1 | 
| Chris@55 | 213   trap "ret=130; $do_exit" 2 | 
| Chris@55 | 214   trap "ret=141; $do_exit" 13 | 
| Chris@55 | 215   trap "ret=143; $do_exit" 15 | 
| Chris@4 | 216 | 
| Chris@4 | 217   # Set umask so as not to create temps with too-generous modes. | 
| Chris@4 | 218   # However, 'strip' requires both read and write access to temps. | 
| Chris@4 | 219   case $mode in | 
| Chris@4 | 220     # Optimize common cases. | 
| Chris@4 | 221     *644) cp_umask=133;; | 
| Chris@4 | 222     *755) cp_umask=22;; | 
| Chris@4 | 223 | 
| Chris@4 | 224     *[0-7]) | 
| Chris@4 | 225       if test -z "$stripcmd"; then | 
| Chris@4 | 226 	u_plus_rw= | 
| Chris@4 | 227       else | 
| Chris@4 | 228 	u_plus_rw='% 200' | 
| Chris@4 | 229       fi | 
| Chris@4 | 230       cp_umask=`expr '(' 777 - $mode % 1000 ')' $u_plus_rw`;; | 
| Chris@4 | 231     *) | 
| Chris@4 | 232       if test -z "$stripcmd"; then | 
| Chris@4 | 233 	u_plus_rw= | 
| Chris@4 | 234       else | 
| Chris@4 | 235 	u_plus_rw=,u+rw | 
| Chris@4 | 236       fi | 
| Chris@4 | 237       cp_umask=$mode$u_plus_rw;; | 
| Chris@4 | 238   esac | 
| Chris@4 | 239 fi | 
| Chris@4 | 240 | 
| Chris@4 | 241 for src | 
| Chris@4 | 242 do | 
| Chris@55 | 243   # Protect names problematic for 'test' and other utilities. | 
| Chris@4 | 244   case $src in | 
| Chris@55 | 245     -* | [=\(\)!]) src=./$src;; | 
| Chris@4 | 246   esac | 
| Chris@4 | 247 | 
| Chris@4 | 248   if test -n "$dir_arg"; then | 
| Chris@4 | 249     dst=$src | 
| Chris@4 | 250     dstdir=$dst | 
| Chris@4 | 251     test -d "$dstdir" | 
| Chris@4 | 252     dstdir_status=$? | 
| Chris@4 | 253   else | 
| Chris@4 | 254 | 
| Chris@4 | 255     # Waiting for this to be detected by the "$cpprog $src $dsttmp" command | 
| Chris@4 | 256     # might cause directories to be created, which would be especially bad | 
| Chris@4 | 257     # if $src (and thus $dsttmp) contains '*'. | 
| Chris@4 | 258     if test ! -f "$src" && test ! -d "$src"; then | 
| Chris@4 | 259       echo "$0: $src does not exist." >&2 | 
| Chris@4 | 260       exit 1 | 
| Chris@4 | 261     fi | 
| Chris@4 | 262 | 
| Chris@4 | 263     if test -z "$dst_arg"; then | 
| Chris@4 | 264       echo "$0: no destination specified." >&2 | 
| Chris@4 | 265       exit 1 | 
| Chris@4 | 266     fi | 
| Chris@4 | 267     dst=$dst_arg | 
| Chris@4 | 268 | 
| Chris@4 | 269     # If destination is a directory, append the input filename; won't work | 
| Chris@4 | 270     # if double slashes aren't ignored. | 
| Chris@4 | 271     if test -d "$dst"; then | 
| Chris@4 | 272       if test -n "$no_target_directory"; then | 
| Chris@4 | 273 	echo "$0: $dst_arg: Is a directory" >&2 | 
| Chris@4 | 274 	exit 1 | 
| Chris@4 | 275       fi | 
| Chris@4 | 276       dstdir=$dst | 
| Chris@4 | 277       dst=$dstdir/`basename "$src"` | 
| Chris@4 | 278       dstdir_status=0 | 
| Chris@4 | 279     else | 
| Chris@4 | 280       # Prefer dirname, but fall back on a substitute if dirname fails. | 
| Chris@4 | 281       dstdir=` | 
| Chris@4 | 282 	(dirname "$dst") 2>/dev/null || | 
| Chris@4 | 283 	expr X"$dst" : 'X\(.*[^/]\)//*[^/][^/]*/*$' \| \ | 
| Chris@4 | 284 	     X"$dst" : 'X\(//\)[^/]' \| \ | 
| Chris@4 | 285 	     X"$dst" : 'X\(//\)$' \| \ | 
| Chris@4 | 286 	     X"$dst" : 'X\(/\)' \| . 2>/dev/null || | 
| Chris@4 | 287 	echo X"$dst" | | 
| Chris@4 | 288 	    sed '/^X\(.*[^/]\)\/\/*[^/][^/]*\/*$/{ | 
| Chris@4 | 289 		   s//\1/ | 
| Chris@4 | 290 		   q | 
| Chris@4 | 291 		 } | 
| Chris@4 | 292 		 /^X\(\/\/\)[^/].*/{ | 
| Chris@4 | 293 		   s//\1/ | 
| Chris@4 | 294 		   q | 
| Chris@4 | 295 		 } | 
| Chris@4 | 296 		 /^X\(\/\/\)$/{ | 
| Chris@4 | 297 		   s//\1/ | 
| Chris@4 | 298 		   q | 
| Chris@4 | 299 		 } | 
| Chris@4 | 300 		 /^X\(\/\).*/{ | 
| Chris@4 | 301 		   s//\1/ | 
| Chris@4 | 302 		   q | 
| Chris@4 | 303 		 } | 
| Chris@4 | 304 		 s/.*/./; q' | 
| Chris@4 | 305       ` | 
| Chris@4 | 306 | 
| Chris@4 | 307       test -d "$dstdir" | 
| Chris@4 | 308       dstdir_status=$? | 
| Chris@4 | 309     fi | 
| Chris@4 | 310   fi | 
| Chris@4 | 311 | 
| Chris@4 | 312   obsolete_mkdir_used=false | 
| Chris@4 | 313 | 
| Chris@4 | 314   if test $dstdir_status != 0; then | 
| Chris@4 | 315     case $posix_mkdir in | 
| Chris@4 | 316       '') | 
| Chris@4 | 317 	# Create intermediate dirs using mode 755 as modified by the umask. | 
| Chris@4 | 318 	# This is like FreeBSD 'install' as of 1997-10-28. | 
| Chris@4 | 319 	umask=`umask` | 
| Chris@4 | 320 	case $stripcmd.$umask in | 
| Chris@4 | 321 	  # Optimize common cases. | 
| Chris@4 | 322 	  *[2367][2367]) mkdir_umask=$umask;; | 
| Chris@4 | 323 	  .*0[02][02] | .[02][02] | .[02]) mkdir_umask=22;; | 
| Chris@4 | 324 | 
| Chris@4 | 325 	  *[0-7]) | 
| Chris@4 | 326 	    mkdir_umask=`expr $umask + 22 \ | 
| Chris@4 | 327 	      - $umask % 100 % 40 + $umask % 20 \ | 
| Chris@4 | 328 	      - $umask % 10 % 4 + $umask % 2 | 
| Chris@4 | 329 	    `;; | 
| Chris@4 | 330 	  *) mkdir_umask=$umask,go-w;; | 
| Chris@4 | 331 	esac | 
| Chris@4 | 332 | 
| Chris@4 | 333 	# With -d, create the new directory with the user-specified mode. | 
| Chris@4 | 334 	# Otherwise, rely on $mkdir_umask. | 
| Chris@4 | 335 	if test -n "$dir_arg"; then | 
| Chris@4 | 336 	  mkdir_mode=-m$mode | 
| Chris@4 | 337 	else | 
| Chris@4 | 338 	  mkdir_mode= | 
| Chris@4 | 339 	fi | 
| Chris@4 | 340 | 
| Chris@4 | 341 	posix_mkdir=false | 
| Chris@4 | 342 	case $umask in | 
| Chris@4 | 343 	  *[123567][0-7][0-7]) | 
| Chris@4 | 344 	    # POSIX mkdir -p sets u+wx bits regardless of umask, which | 
| Chris@4 | 345 	    # is incompatible with FreeBSD 'install' when (umask & 300) != 0. | 
| Chris@4 | 346 	    ;; | 
| Chris@4 | 347 	  *) | 
| Chris@4 | 348 	    tmpdir=${TMPDIR-/tmp}/ins$RANDOM-$$ | 
| Chris@4 | 349 	    trap 'ret=$?; rmdir "$tmpdir/d" "$tmpdir" 2>/dev/null; exit $ret' 0 | 
| Chris@4 | 350 | 
| Chris@4 | 351 	    if (umask $mkdir_umask && | 
| Chris@4 | 352 		exec $mkdirprog $mkdir_mode -p -- "$tmpdir/d") >/dev/null 2>&1 | 
| Chris@4 | 353 	    then | 
| Chris@4 | 354 	      if test -z "$dir_arg" || { | 
| Chris@4 | 355 		   # Check for POSIX incompatibilities with -m. | 
| Chris@4 | 356 		   # HP-UX 11.23 and IRIX 6.5 mkdir -m -p sets group- or | 
| Chris@55 | 357 		   # other-writable bit of parent directory when it shouldn't. | 
| Chris@4 | 358 		   # FreeBSD 6.1 mkdir -m -p sets mode of existing directory. | 
| Chris@4 | 359 		   ls_ld_tmpdir=`ls -ld "$tmpdir"` | 
| Chris@4 | 360 		   case $ls_ld_tmpdir in | 
| Chris@4 | 361 		     d????-?r-*) different_mode=700;; | 
| Chris@4 | 362 		     d????-?--*) different_mode=755;; | 
| Chris@4 | 363 		     *) false;; | 
| Chris@4 | 364 		   esac && | 
| Chris@4 | 365 		   $mkdirprog -m$different_mode -p -- "$tmpdir" && { | 
| Chris@4 | 366 		     ls_ld_tmpdir_1=`ls -ld "$tmpdir"` | 
| Chris@4 | 367 		     test "$ls_ld_tmpdir" = "$ls_ld_tmpdir_1" | 
| Chris@4 | 368 		   } | 
| Chris@4 | 369 		 } | 
| Chris@4 | 370 	      then posix_mkdir=: | 
| Chris@4 | 371 	      fi | 
| Chris@4 | 372 	      rmdir "$tmpdir/d" "$tmpdir" | 
| Chris@4 | 373 	    else | 
| Chris@4 | 374 	      # Remove any dirs left behind by ancient mkdir implementations. | 
| Chris@4 | 375 	      rmdir ./$mkdir_mode ./-p ./-- 2>/dev/null | 
| Chris@4 | 376 	    fi | 
| Chris@4 | 377 	    trap '' 0;; | 
| Chris@4 | 378 	esac;; | 
| Chris@4 | 379     esac | 
| Chris@4 | 380 | 
| Chris@4 | 381     if | 
| Chris@4 | 382       $posix_mkdir && ( | 
| Chris@4 | 383 	umask $mkdir_umask && | 
| Chris@4 | 384 	$doit_exec $mkdirprog $mkdir_mode -p -- "$dstdir" | 
| Chris@4 | 385       ) | 
| Chris@4 | 386     then : | 
| Chris@4 | 387     else | 
| Chris@4 | 388 | 
| Chris@4 | 389       # The umask is ridiculous, or mkdir does not conform to POSIX, | 
| Chris@4 | 390       # or it failed possibly due to a race condition.  Create the | 
| Chris@4 | 391       # directory the slow way, step by step, checking for races as we go. | 
| Chris@4 | 392 | 
| Chris@4 | 393       case $dstdir in | 
| Chris@4 | 394 	/*) prefix='/';; | 
| Chris@55 | 395 	[-=\(\)!]*) prefix='./';; | 
| Chris@4 | 396 	*)  prefix='';; | 
| Chris@4 | 397       esac | 
| Chris@4 | 398 | 
| Chris@4 | 399       eval "$initialize_posix_glob" | 
| Chris@4 | 400 | 
| Chris@4 | 401       oIFS=$IFS | 
| Chris@4 | 402       IFS=/ | 
| Chris@4 | 403       $posix_glob set -f | 
| Chris@4 | 404       set fnord $dstdir | 
| Chris@4 | 405       shift | 
| Chris@4 | 406       $posix_glob set +f | 
| Chris@4 | 407       IFS=$oIFS | 
| Chris@4 | 408 | 
| Chris@4 | 409       prefixes= | 
| Chris@4 | 410 | 
| Chris@4 | 411       for d | 
| Chris@4 | 412       do | 
| Chris@55 | 413 	test X"$d" = X && continue | 
| Chris@4 | 414 | 
| Chris@4 | 415 	prefix=$prefix$d | 
| Chris@4 | 416 	if test -d "$prefix"; then | 
| Chris@4 | 417 	  prefixes= | 
| Chris@4 | 418 	else | 
| Chris@4 | 419 	  if $posix_mkdir; then | 
| Chris@4 | 420 	    (umask=$mkdir_umask && | 
| Chris@4 | 421 	     $doit_exec $mkdirprog $mkdir_mode -p -- "$dstdir") && break | 
| Chris@4 | 422 	    # Don't fail if two instances are running concurrently. | 
| Chris@4 | 423 	    test -d "$prefix" || exit 1 | 
| Chris@4 | 424 	  else | 
| Chris@4 | 425 	    case $prefix in | 
| Chris@4 | 426 	      *\'*) qprefix=`echo "$prefix" | sed "s/'/'\\\\\\\\''/g"`;; | 
| Chris@4 | 427 	      *) qprefix=$prefix;; | 
| Chris@4 | 428 	    esac | 
| Chris@4 | 429 	    prefixes="$prefixes '$qprefix'" | 
| Chris@4 | 430 	  fi | 
| Chris@4 | 431 	fi | 
| Chris@4 | 432 	prefix=$prefix/ | 
| Chris@4 | 433       done | 
| Chris@4 | 434 | 
| Chris@4 | 435       if test -n "$prefixes"; then | 
| Chris@4 | 436 	# Don't fail if two instances are running concurrently. | 
| Chris@4 | 437 	(umask $mkdir_umask && | 
| Chris@4 | 438 	 eval "\$doit_exec \$mkdirprog $prefixes") || | 
| Chris@4 | 439 	  test -d "$dstdir" || exit 1 | 
| Chris@4 | 440 	obsolete_mkdir_used=true | 
| Chris@4 | 441       fi | 
| Chris@4 | 442     fi | 
| Chris@4 | 443   fi | 
| Chris@4 | 444 | 
| Chris@4 | 445   if test -n "$dir_arg"; then | 
| Chris@4 | 446     { test -z "$chowncmd" || $doit $chowncmd "$dst"; } && | 
| Chris@4 | 447     { test -z "$chgrpcmd" || $doit $chgrpcmd "$dst"; } && | 
| Chris@4 | 448     { test "$obsolete_mkdir_used$chowncmd$chgrpcmd" = false || | 
| Chris@4 | 449       test -z "$chmodcmd" || $doit $chmodcmd $mode "$dst"; } || exit 1 | 
| Chris@4 | 450   else | 
| Chris@4 | 451 | 
| Chris@4 | 452     # Make a couple of temp file names in the proper directory. | 
| Chris@4 | 453     dsttmp=$dstdir/_inst.$$_ | 
| Chris@4 | 454     rmtmp=$dstdir/_rm.$$_ | 
| Chris@4 | 455 | 
| Chris@4 | 456     # Trap to clean up those temp files at exit. | 
| Chris@4 | 457     trap 'ret=$?; rm -f "$dsttmp" "$rmtmp" && exit $ret' 0 | 
| Chris@4 | 458 | 
| Chris@4 | 459     # Copy the file name to the temp name. | 
| Chris@4 | 460     (umask $cp_umask && $doit_exec $cpprog "$src" "$dsttmp") && | 
| Chris@4 | 461 | 
| Chris@4 | 462     # and set any options; do chmod last to preserve setuid bits. | 
| Chris@4 | 463     # | 
| Chris@4 | 464     # If any of these fail, we abort the whole thing.  If we want to | 
| Chris@4 | 465     # ignore errors from any of these, just make sure not to ignore | 
| Chris@4 | 466     # errors from the above "$doit $cpprog $src $dsttmp" command. | 
| Chris@4 | 467     # | 
| Chris@4 | 468     { test -z "$chowncmd" || $doit $chowncmd "$dsttmp"; } && | 
| Chris@4 | 469     { test -z "$chgrpcmd" || $doit $chgrpcmd "$dsttmp"; } && | 
| Chris@4 | 470     { test -z "$stripcmd" || $doit $stripcmd "$dsttmp"; } && | 
| Chris@4 | 471     { test -z "$chmodcmd" || $doit $chmodcmd $mode "$dsttmp"; } && | 
| Chris@4 | 472 | 
| Chris@4 | 473     # If -C, don't bother to copy if it wouldn't change the file. | 
| Chris@4 | 474     if $copy_on_change && | 
| Chris@4 | 475        old=`LC_ALL=C ls -dlL "$dst"	2>/dev/null` && | 
| Chris@4 | 476        new=`LC_ALL=C ls -dlL "$dsttmp"	2>/dev/null` && | 
| Chris@4 | 477 | 
| Chris@4 | 478        eval "$initialize_posix_glob" && | 
| Chris@4 | 479        $posix_glob set -f && | 
| Chris@4 | 480        set X $old && old=:$2:$4:$5:$6 && | 
| Chris@4 | 481        set X $new && new=:$2:$4:$5:$6 && | 
| Chris@4 | 482        $posix_glob set +f && | 
| Chris@4 | 483 | 
| Chris@4 | 484        test "$old" = "$new" && | 
| Chris@4 | 485        $cmpprog "$dst" "$dsttmp" >/dev/null 2>&1 | 
| Chris@4 | 486     then | 
| Chris@4 | 487       rm -f "$dsttmp" | 
| Chris@4 | 488     else | 
| Chris@4 | 489       # Rename the file to the real destination. | 
| Chris@4 | 490       $doit $mvcmd -f "$dsttmp" "$dst" 2>/dev/null || | 
| Chris@4 | 491 | 
| Chris@4 | 492       # The rename failed, perhaps because mv can't rename something else | 
| Chris@4 | 493       # to itself, or perhaps because mv is so ancient that it does not | 
| Chris@4 | 494       # support -f. | 
| Chris@4 | 495       { | 
| Chris@4 | 496 	# Now remove or move aside any old file at destination location. | 
| Chris@4 | 497 	# We try this two ways since rm can't unlink itself on some | 
| Chris@4 | 498 	# systems and the destination file might be busy for other | 
| Chris@4 | 499 	# reasons.  In this case, the final cleanup might fail but the new | 
| Chris@4 | 500 	# file should still install successfully. | 
| Chris@4 | 501 	{ | 
| Chris@4 | 502 	  test ! -f "$dst" || | 
| Chris@4 | 503 	  $doit $rmcmd -f "$dst" 2>/dev/null || | 
| Chris@4 | 504 	  { $doit $mvcmd -f "$dst" "$rmtmp" 2>/dev/null && | 
| Chris@4 | 505 	    { $doit $rmcmd -f "$rmtmp" 2>/dev/null; :; } | 
| Chris@4 | 506 	  } || | 
| Chris@4 | 507 	  { echo "$0: cannot unlink or rename $dst" >&2 | 
| Chris@4 | 508 	    (exit 1); exit 1 | 
| Chris@4 | 509 	  } | 
| Chris@4 | 510 	} && | 
| Chris@4 | 511 | 
| Chris@4 | 512 	# Now rename the file to the real destination. | 
| Chris@4 | 513 	$doit $mvcmd "$dsttmp" "$dst" | 
| Chris@4 | 514       } | 
| Chris@4 | 515     fi || exit 1 | 
| Chris@4 | 516 | 
| Chris@4 | 517     trap '' 0 | 
| Chris@4 | 518   fi | 
| Chris@4 | 519 done | 
| Chris@4 | 520 | 
| Chris@4 | 521 # Local variables: | 
| Chris@4 | 522 # eval: (add-hook 'write-file-hooks 'time-stamp) | 
| Chris@4 | 523 # time-stamp-start: "scriptversion=" | 
| Chris@4 | 524 # time-stamp-format: "%:y-%02m-%02d.%02H" | 
| Chris@4 | 525 # time-stamp-time-zone: "UTC" | 
| Chris@4 | 526 # time-stamp-end: "; # UTC" | 
| Chris@4 | 527 # End: |