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