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