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