1a89495f48f185779ff7d9d64ce6e6b037c9ded87The Android Open Source Project#!/bin/sh 2a89495f48f185779ff7d9d64ce6e6b037c9ded87The Android Open Source Project# install - install a program, script, or datafile 3a89495f48f185779ff7d9d64ce6e6b037c9ded87The Android Open Source Project 4a89495f48f185779ff7d9d64ce6e6b037c9ded87The Android Open Source Projectscriptversion=2004-12-17.09 5a89495f48f185779ff7d9d64ce6e6b037c9ded87The Android Open Source Project 6a89495f48f185779ff7d9d64ce6e6b037c9ded87The Android Open Source Project# This originates from X11R5 (mit/util/scripts/install.sh), which was 7a89495f48f185779ff7d9d64ce6e6b037c9ded87The Android Open Source Project# later released in X11R6 (xc/config/util/install.sh) with the 8a89495f48f185779ff7d9d64ce6e6b037c9ded87The Android Open Source Project# following copyright and license. 9a89495f48f185779ff7d9d64ce6e6b037c9ded87The Android Open Source Project# 10a89495f48f185779ff7d9d64ce6e6b037c9ded87The Android Open Source Project# Copyright (C) 1994 X Consortium 11a89495f48f185779ff7d9d64ce6e6b037c9ded87The Android Open Source Project# 12a89495f48f185779ff7d9d64ce6e6b037c9ded87The Android Open Source Project# Permission is hereby granted, free of charge, to any person obtaining a copy 13a89495f48f185779ff7d9d64ce6e6b037c9ded87The Android Open Source Project# of this software and associated documentation files (the "Software"), to 14a89495f48f185779ff7d9d64ce6e6b037c9ded87The Android Open Source Project# deal in the Software without restriction, including without limitation the 15a89495f48f185779ff7d9d64ce6e6b037c9ded87The Android Open Source Project# rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 16a89495f48f185779ff7d9d64ce6e6b037c9ded87The Android Open Source Project# sell copies of the Software, and to permit persons to whom the Software is 17a89495f48f185779ff7d9d64ce6e6b037c9ded87The Android Open Source Project# furnished to do so, subject to the following conditions: 18a89495f48f185779ff7d9d64ce6e6b037c9ded87The Android Open Source Project# 19a89495f48f185779ff7d9d64ce6e6b037c9ded87The Android Open Source Project# The above copyright notice and this permission notice shall be included in 20a89495f48f185779ff7d9d64ce6e6b037c9ded87The Android Open Source Project# all copies or substantial portions of the Software. 21a89495f48f185779ff7d9d64ce6e6b037c9ded87The Android Open Source Project# 22a89495f48f185779ff7d9d64ce6e6b037c9ded87The Android Open Source Project# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 23a89495f48f185779ff7d9d64ce6e6b037c9ded87The Android Open Source Project# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 24a89495f48f185779ff7d9d64ce6e6b037c9ded87The Android Open Source Project# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 25a89495f48f185779ff7d9d64ce6e6b037c9ded87The Android Open Source Project# X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN 26a89495f48f185779ff7d9d64ce6e6b037c9ded87The Android Open Source Project# AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNEC- 27a89495f48f185779ff7d9d64ce6e6b037c9ded87The Android Open Source Project# TION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 28a89495f48f185779ff7d9d64ce6e6b037c9ded87The Android Open Source Project# 29a89495f48f185779ff7d9d64ce6e6b037c9ded87The Android Open Source Project# Except as contained in this notice, the name of the X Consortium shall not 30a89495f48f185779ff7d9d64ce6e6b037c9ded87The Android Open Source Project# be used in advertising or otherwise to promote the sale, use or other deal- 31a89495f48f185779ff7d9d64ce6e6b037c9ded87The Android Open Source Project# ings in this Software without prior written authorization from the X Consor- 32a89495f48f185779ff7d9d64ce6e6b037c9ded87The Android Open Source Project# tium. 33a89495f48f185779ff7d9d64ce6e6b037c9ded87The Android Open Source Project# 34a89495f48f185779ff7d9d64ce6e6b037c9ded87The Android Open Source Project# 35a89495f48f185779ff7d9d64ce6e6b037c9ded87The Android Open Source Project# FSF changes to this file are in the public domain. 36a89495f48f185779ff7d9d64ce6e6b037c9ded87The Android Open Source Project# 37a89495f48f185779ff7d9d64ce6e6b037c9ded87The Android Open Source Project# Calling this script install-sh is preferred over install.sh, to prevent 38a89495f48f185779ff7d9d64ce6e6b037c9ded87The Android Open Source Project# `make' implicit rules from creating a file called install from it 39a89495f48f185779ff7d9d64ce6e6b037c9ded87The Android Open Source Project# when there is no Makefile. 40a89495f48f185779ff7d9d64ce6e6b037c9ded87The Android Open Source Project# 41a89495f48f185779ff7d9d64ce6e6b037c9ded87The Android Open Source Project# This script is compatible with the BSD install script, but was written 42a89495f48f185779ff7d9d64ce6e6b037c9ded87The Android Open Source Project# from scratch. It can only install one file at a time, a restriction 43a89495f48f185779ff7d9d64ce6e6b037c9ded87The Android Open Source Project# shared with many OS's install programs. 44a89495f48f185779ff7d9d64ce6e6b037c9ded87The Android Open Source Project 45a89495f48f185779ff7d9d64ce6e6b037c9ded87The Android Open Source Project# set DOITPROG to echo to test this script 46a89495f48f185779ff7d9d64ce6e6b037c9ded87The Android Open Source Project 47a89495f48f185779ff7d9d64ce6e6b037c9ded87The Android Open Source Project# Don't use :- since 4.3BSD and earlier shells don't like it. 48a89495f48f185779ff7d9d64ce6e6b037c9ded87The Android Open Source Projectdoit="${DOITPROG-}" 49a89495f48f185779ff7d9d64ce6e6b037c9ded87The Android Open Source Project 50a89495f48f185779ff7d9d64ce6e6b037c9ded87The Android Open Source Project# put in absolute paths if you don't have them in your path; or use env. vars. 51a89495f48f185779ff7d9d64ce6e6b037c9ded87The Android Open Source Project 52a89495f48f185779ff7d9d64ce6e6b037c9ded87The Android Open Source Projectmvprog="${MVPROG-mv}" 53a89495f48f185779ff7d9d64ce6e6b037c9ded87The Android Open Source Projectcpprog="${CPPROG-cp}" 54a89495f48f185779ff7d9d64ce6e6b037c9ded87The Android Open Source Projectchmodprog="${CHMODPROG-chmod}" 55a89495f48f185779ff7d9d64ce6e6b037c9ded87The Android Open Source Projectchownprog="${CHOWNPROG-chown}" 56a89495f48f185779ff7d9d64ce6e6b037c9ded87The Android Open Source Projectchgrpprog="${CHGRPPROG-chgrp}" 57a89495f48f185779ff7d9d64ce6e6b037c9ded87The Android Open Source Projectstripprog="${STRIPPROG-strip}" 58a89495f48f185779ff7d9d64ce6e6b037c9ded87The Android Open Source Projectrmprog="${RMPROG-rm}" 59a89495f48f185779ff7d9d64ce6e6b037c9ded87The Android Open Source Projectmkdirprog="${MKDIRPROG-mkdir}" 60a89495f48f185779ff7d9d64ce6e6b037c9ded87The Android Open Source Project 61a89495f48f185779ff7d9d64ce6e6b037c9ded87The Android Open Source Projectchmodcmd="$chmodprog 0755" 62a89495f48f185779ff7d9d64ce6e6b037c9ded87The Android Open Source Projectchowncmd= 63a89495f48f185779ff7d9d64ce6e6b037c9ded87The Android Open Source Projectchgrpcmd= 64a89495f48f185779ff7d9d64ce6e6b037c9ded87The Android Open Source Projectstripcmd= 65a89495f48f185779ff7d9d64ce6e6b037c9ded87The Android Open Source Projectrmcmd="$rmprog -f" 66a89495f48f185779ff7d9d64ce6e6b037c9ded87The Android Open Source Projectmvcmd="$mvprog" 67a89495f48f185779ff7d9d64ce6e6b037c9ded87The Android Open Source Projectsrc= 68a89495f48f185779ff7d9d64ce6e6b037c9ded87The Android Open Source Projectdst= 69a89495f48f185779ff7d9d64ce6e6b037c9ded87The Android Open Source Projectdir_arg= 70a89495f48f185779ff7d9d64ce6e6b037c9ded87The Android Open Source Projectdstarg= 71a89495f48f185779ff7d9d64ce6e6b037c9ded87The Android Open Source Projectno_target_directory= 72a89495f48f185779ff7d9d64ce6e6b037c9ded87The Android Open Source Project 73a89495f48f185779ff7d9d64ce6e6b037c9ded87The Android Open Source Projectusage="Usage: $0 [OPTION]... [-T] SRCFILE DSTFILE 74a89495f48f185779ff7d9d64ce6e6b037c9ded87The Android Open Source Project or: $0 [OPTION]... SRCFILES... DIRECTORY 75a89495f48f185779ff7d9d64ce6e6b037c9ded87The Android Open Source Project or: $0 [OPTION]... -t DIRECTORY SRCFILES... 76a89495f48f185779ff7d9d64ce6e6b037c9ded87The Android Open Source Project or: $0 [OPTION]... -d DIRECTORIES... 77a89495f48f185779ff7d9d64ce6e6b037c9ded87The Android Open Source Project 78a89495f48f185779ff7d9d64ce6e6b037c9ded87The Android Open Source ProjectIn the 1st form, copy SRCFILE to DSTFILE. 79a89495f48f185779ff7d9d64ce6e6b037c9ded87The Android Open Source ProjectIn the 2nd and 3rd, copy all SRCFILES to DIRECTORY. 80a89495f48f185779ff7d9d64ce6e6b037c9ded87The Android Open Source ProjectIn the 4th, create DIRECTORIES. 81a89495f48f185779ff7d9d64ce6e6b037c9ded87The Android Open Source Project 82a89495f48f185779ff7d9d64ce6e6b037c9ded87The Android Open Source ProjectOptions: 83a89495f48f185779ff7d9d64ce6e6b037c9ded87The Android Open Source Project-c (ignored) 84a89495f48f185779ff7d9d64ce6e6b037c9ded87The Android Open Source Project-d create directories instead of installing files. 85a89495f48f185779ff7d9d64ce6e6b037c9ded87The Android Open Source Project-g GROUP $chgrpprog installed files to GROUP. 86a89495f48f185779ff7d9d64ce6e6b037c9ded87The Android Open Source Project-m MODE $chmodprog installed files to MODE. 87a89495f48f185779ff7d9d64ce6e6b037c9ded87The Android Open Source Project-o USER $chownprog installed files to USER. 88a89495f48f185779ff7d9d64ce6e6b037c9ded87The Android Open Source Project-s $stripprog installed files. 89a89495f48f185779ff7d9d64ce6e6b037c9ded87The Android Open Source Project-t DIRECTORY install into DIRECTORY. 90a89495f48f185779ff7d9d64ce6e6b037c9ded87The Android Open Source Project-T report an error if DSTFILE is a directory. 91a89495f48f185779ff7d9d64ce6e6b037c9ded87The Android Open Source Project--help display this help and exit. 92a89495f48f185779ff7d9d64ce6e6b037c9ded87The Android Open Source Project--version display version info and exit. 93a89495f48f185779ff7d9d64ce6e6b037c9ded87The Android Open Source Project 94a89495f48f185779ff7d9d64ce6e6b037c9ded87The Android Open Source ProjectEnvironment variables override the default commands: 95a89495f48f185779ff7d9d64ce6e6b037c9ded87The Android Open Source Project CHGRPPROG CHMODPROG CHOWNPROG CPPROG MKDIRPROG MVPROG RMPROG STRIPPROG 96a89495f48f185779ff7d9d64ce6e6b037c9ded87The Android Open Source Project" 97a89495f48f185779ff7d9d64ce6e6b037c9ded87The Android Open Source Project 98a89495f48f185779ff7d9d64ce6e6b037c9ded87The Android Open Source Projectwhile test -n "$1"; do 99a89495f48f185779ff7d9d64ce6e6b037c9ded87The Android Open Source Project case $1 in 100a89495f48f185779ff7d9d64ce6e6b037c9ded87The Android Open Source Project -c) shift 101a89495f48f185779ff7d9d64ce6e6b037c9ded87The Android Open Source Project continue;; 102a89495f48f185779ff7d9d64ce6e6b037c9ded87The Android Open Source Project 103a89495f48f185779ff7d9d64ce6e6b037c9ded87The Android Open Source Project -d) dir_arg=true 104a89495f48f185779ff7d9d64ce6e6b037c9ded87The Android Open Source Project shift 105a89495f48f185779ff7d9d64ce6e6b037c9ded87The Android Open Source Project continue;; 106a89495f48f185779ff7d9d64ce6e6b037c9ded87The Android Open Source Project 107a89495f48f185779ff7d9d64ce6e6b037c9ded87The Android Open Source Project -g) chgrpcmd="$chgrpprog $2" 108a89495f48f185779ff7d9d64ce6e6b037c9ded87The Android Open Source Project shift 109a89495f48f185779ff7d9d64ce6e6b037c9ded87The Android Open Source Project shift 110a89495f48f185779ff7d9d64ce6e6b037c9ded87The Android Open Source Project continue;; 111a89495f48f185779ff7d9d64ce6e6b037c9ded87The Android Open Source Project 112a89495f48f185779ff7d9d64ce6e6b037c9ded87The Android Open Source Project --help) echo "$usage"; exit 0;; 113a89495f48f185779ff7d9d64ce6e6b037c9ded87The Android Open Source Project 114a89495f48f185779ff7d9d64ce6e6b037c9ded87The Android Open Source Project -m) chmodcmd="$chmodprog $2" 115a89495f48f185779ff7d9d64ce6e6b037c9ded87The Android Open Source Project shift 116a89495f48f185779ff7d9d64ce6e6b037c9ded87The Android Open Source Project shift 117a89495f48f185779ff7d9d64ce6e6b037c9ded87The Android Open Source Project continue;; 118a89495f48f185779ff7d9d64ce6e6b037c9ded87The Android Open Source Project 119a89495f48f185779ff7d9d64ce6e6b037c9ded87The Android Open Source Project -o) chowncmd="$chownprog $2" 120a89495f48f185779ff7d9d64ce6e6b037c9ded87The Android Open Source Project shift 121a89495f48f185779ff7d9d64ce6e6b037c9ded87The Android Open Source Project shift 122a89495f48f185779ff7d9d64ce6e6b037c9ded87The Android Open Source Project continue;; 123a89495f48f185779ff7d9d64ce6e6b037c9ded87The Android Open Source Project 124a89495f48f185779ff7d9d64ce6e6b037c9ded87The Android Open Source Project -s) stripcmd=$stripprog 125a89495f48f185779ff7d9d64ce6e6b037c9ded87The Android Open Source Project shift 126a89495f48f185779ff7d9d64ce6e6b037c9ded87The Android Open Source Project continue;; 127a89495f48f185779ff7d9d64ce6e6b037c9ded87The Android Open Source Project 128a89495f48f185779ff7d9d64ce6e6b037c9ded87The Android Open Source Project -t) dstarg=$2 129a89495f48f185779ff7d9d64ce6e6b037c9ded87The Android Open Source Project shift 130a89495f48f185779ff7d9d64ce6e6b037c9ded87The Android Open Source Project shift 131a89495f48f185779ff7d9d64ce6e6b037c9ded87The Android Open Source Project continue;; 132a89495f48f185779ff7d9d64ce6e6b037c9ded87The Android Open Source Project 133a89495f48f185779ff7d9d64ce6e6b037c9ded87The Android Open Source Project -T) no_target_directory=true 134a89495f48f185779ff7d9d64ce6e6b037c9ded87The Android Open Source Project shift 135a89495f48f185779ff7d9d64ce6e6b037c9ded87The Android Open Source Project continue;; 136a89495f48f185779ff7d9d64ce6e6b037c9ded87The Android Open Source Project 137a89495f48f185779ff7d9d64ce6e6b037c9ded87The Android Open Source Project --version) echo "$0 $scriptversion"; exit 0;; 138a89495f48f185779ff7d9d64ce6e6b037c9ded87The Android Open Source Project 139a89495f48f185779ff7d9d64ce6e6b037c9ded87The Android Open Source Project *) # When -d is used, all remaining arguments are directories to create. 140a89495f48f185779ff7d9d64ce6e6b037c9ded87The Android Open Source Project # When -t is used, the destination is already specified. 141a89495f48f185779ff7d9d64ce6e6b037c9ded87The Android Open Source Project test -n "$dir_arg$dstarg" && break 142a89495f48f185779ff7d9d64ce6e6b037c9ded87The Android Open Source Project # Otherwise, the last argument is the destination. Remove it from $@. 143a89495f48f185779ff7d9d64ce6e6b037c9ded87The Android Open Source Project for arg 144a89495f48f185779ff7d9d64ce6e6b037c9ded87The Android Open Source Project do 145a89495f48f185779ff7d9d64ce6e6b037c9ded87The Android Open Source Project if test -n "$dstarg"; then 146a89495f48f185779ff7d9d64ce6e6b037c9ded87The Android Open Source Project # $@ is not empty: it contains at least $arg. 147a89495f48f185779ff7d9d64ce6e6b037c9ded87The Android Open Source Project set fnord "$@" "$dstarg" 148a89495f48f185779ff7d9d64ce6e6b037c9ded87The Android Open Source Project shift # fnord 149a89495f48f185779ff7d9d64ce6e6b037c9ded87The Android Open Source Project fi 150a89495f48f185779ff7d9d64ce6e6b037c9ded87The Android Open Source Project shift # arg 151a89495f48f185779ff7d9d64ce6e6b037c9ded87The Android Open Source Project dstarg=$arg 152a89495f48f185779ff7d9d64ce6e6b037c9ded87The Android Open Source Project done 153a89495f48f185779ff7d9d64ce6e6b037c9ded87The Android Open Source Project break;; 154a89495f48f185779ff7d9d64ce6e6b037c9ded87The Android Open Source Project esac 155a89495f48f185779ff7d9d64ce6e6b037c9ded87The Android Open Source Projectdone 156a89495f48f185779ff7d9d64ce6e6b037c9ded87The Android Open Source Project 157a89495f48f185779ff7d9d64ce6e6b037c9ded87The Android Open Source Projectif test -z "$1"; then 158a89495f48f185779ff7d9d64ce6e6b037c9ded87The Android Open Source Project if test -z "$dir_arg"; then 159a89495f48f185779ff7d9d64ce6e6b037c9ded87The Android Open Source Project echo "$0: no input file specified." >&2 160a89495f48f185779ff7d9d64ce6e6b037c9ded87The Android Open Source Project exit 1 161a89495f48f185779ff7d9d64ce6e6b037c9ded87The Android Open Source Project fi 162a89495f48f185779ff7d9d64ce6e6b037c9ded87The Android Open Source Project # It's OK to call `install-sh -d' without argument. 163a89495f48f185779ff7d9d64ce6e6b037c9ded87The Android Open Source Project # This can happen when creating conditional directories. 164a89495f48f185779ff7d9d64ce6e6b037c9ded87The Android Open Source Project exit 0 165a89495f48f185779ff7d9d64ce6e6b037c9ded87The Android Open Source Projectfi 166a89495f48f185779ff7d9d64ce6e6b037c9ded87The Android Open Source Project 167a89495f48f185779ff7d9d64ce6e6b037c9ded87The Android Open Source Projectfor src 168a89495f48f185779ff7d9d64ce6e6b037c9ded87The Android Open Source Projectdo 169a89495f48f185779ff7d9d64ce6e6b037c9ded87The Android Open Source Project # Protect names starting with `-'. 170a89495f48f185779ff7d9d64ce6e6b037c9ded87The Android Open Source Project case $src in 171a89495f48f185779ff7d9d64ce6e6b037c9ded87The Android Open Source Project -*) src=./$src ;; 172a89495f48f185779ff7d9d64ce6e6b037c9ded87The Android Open Source Project esac 173a89495f48f185779ff7d9d64ce6e6b037c9ded87The Android Open Source Project 174a89495f48f185779ff7d9d64ce6e6b037c9ded87The Android Open Source Project if test -n "$dir_arg"; then 175a89495f48f185779ff7d9d64ce6e6b037c9ded87The Android Open Source Project dst=$src 176a89495f48f185779ff7d9d64ce6e6b037c9ded87The Android Open Source Project src= 177a89495f48f185779ff7d9d64ce6e6b037c9ded87The Android Open Source Project 178a89495f48f185779ff7d9d64ce6e6b037c9ded87The Android Open Source Project if test -d "$dst"; then 179a89495f48f185779ff7d9d64ce6e6b037c9ded87The Android Open Source Project mkdircmd=: 180a89495f48f185779ff7d9d64ce6e6b037c9ded87The Android Open Source Project chmodcmd= 181a89495f48f185779ff7d9d64ce6e6b037c9ded87The Android Open Source Project else 182a89495f48f185779ff7d9d64ce6e6b037c9ded87The Android Open Source Project mkdircmd=$mkdirprog 183a89495f48f185779ff7d9d64ce6e6b037c9ded87The Android Open Source Project fi 184a89495f48f185779ff7d9d64ce6e6b037c9ded87The Android Open Source Project else 185a89495f48f185779ff7d9d64ce6e6b037c9ded87The Android Open Source Project # Waiting for this to be detected by the "$cpprog $src $dsttmp" command 186a89495f48f185779ff7d9d64ce6e6b037c9ded87The Android Open Source Project # might cause directories to be created, which would be especially bad 187a89495f48f185779ff7d9d64ce6e6b037c9ded87The Android Open Source Project # if $src (and thus $dsttmp) contains '*'. 188a89495f48f185779ff7d9d64ce6e6b037c9ded87The Android Open Source Project if test ! -f "$src" && test ! -d "$src"; then 189a89495f48f185779ff7d9d64ce6e6b037c9ded87The Android Open Source Project echo "$0: $src does not exist." >&2 190a89495f48f185779ff7d9d64ce6e6b037c9ded87The Android Open Source Project exit 1 191a89495f48f185779ff7d9d64ce6e6b037c9ded87The Android Open Source Project fi 192a89495f48f185779ff7d9d64ce6e6b037c9ded87The Android Open Source Project 193a89495f48f185779ff7d9d64ce6e6b037c9ded87The Android Open Source Project if test -z "$dstarg"; then 194a89495f48f185779ff7d9d64ce6e6b037c9ded87The Android Open Source Project echo "$0: no destination specified." >&2 195a89495f48f185779ff7d9d64ce6e6b037c9ded87The Android Open Source Project exit 1 196a89495f48f185779ff7d9d64ce6e6b037c9ded87The Android Open Source Project fi 197a89495f48f185779ff7d9d64ce6e6b037c9ded87The Android Open Source Project 198a89495f48f185779ff7d9d64ce6e6b037c9ded87The Android Open Source Project dst=$dstarg 199a89495f48f185779ff7d9d64ce6e6b037c9ded87The Android Open Source Project # Protect names starting with `-'. 200a89495f48f185779ff7d9d64ce6e6b037c9ded87The Android Open Source Project case $dst in 201a89495f48f185779ff7d9d64ce6e6b037c9ded87The Android Open Source Project -*) dst=./$dst ;; 202a89495f48f185779ff7d9d64ce6e6b037c9ded87The Android Open Source Project esac 203a89495f48f185779ff7d9d64ce6e6b037c9ded87The Android Open Source Project 204a89495f48f185779ff7d9d64ce6e6b037c9ded87The Android Open Source Project # If destination is a directory, append the input filename; won't work 205a89495f48f185779ff7d9d64ce6e6b037c9ded87The Android Open Source Project # if double slashes aren't ignored. 206a89495f48f185779ff7d9d64ce6e6b037c9ded87The Android Open Source Project if test -d "$dst"; then 207a89495f48f185779ff7d9d64ce6e6b037c9ded87The Android Open Source Project if test -n "$no_target_directory"; then 208a89495f48f185779ff7d9d64ce6e6b037c9ded87The Android Open Source Project echo "$0: $dstarg: Is a directory" >&2 209a89495f48f185779ff7d9d64ce6e6b037c9ded87The Android Open Source Project exit 1 210a89495f48f185779ff7d9d64ce6e6b037c9ded87The Android Open Source Project fi 211a89495f48f185779ff7d9d64ce6e6b037c9ded87The Android Open Source Project dst=$dst/`basename "$src"` 212a89495f48f185779ff7d9d64ce6e6b037c9ded87The Android Open Source Project fi 213a89495f48f185779ff7d9d64ce6e6b037c9ded87The Android Open Source Project fi 214a89495f48f185779ff7d9d64ce6e6b037c9ded87The Android Open Source Project 215a89495f48f185779ff7d9d64ce6e6b037c9ded87The Android Open Source Project # This sed command emulates the dirname command. 216a89495f48f185779ff7d9d64ce6e6b037c9ded87The Android Open Source Project dstdir=`echo "$dst" | sed -e 's,/*$,,;s,[^/]*$,,;s,/*$,,;s,^$,.,'` 217a89495f48f185779ff7d9d64ce6e6b037c9ded87The Android Open Source Project 218a89495f48f185779ff7d9d64ce6e6b037c9ded87The Android Open Source Project # Make sure that the destination directory exists. 219a89495f48f185779ff7d9d64ce6e6b037c9ded87The Android Open Source Project 220a89495f48f185779ff7d9d64ce6e6b037c9ded87The Android Open Source Project # Skip lots of stat calls in the usual case. 221a89495f48f185779ff7d9d64ce6e6b037c9ded87The Android Open Source Project if test ! -d "$dstdir"; then 222a89495f48f185779ff7d9d64ce6e6b037c9ded87The Android Open Source Project defaultIFS=' 223a89495f48f185779ff7d9d64ce6e6b037c9ded87The Android Open Source Project ' 224a89495f48f185779ff7d9d64ce6e6b037c9ded87The Android Open Source Project IFS="${IFS-$defaultIFS}" 225a89495f48f185779ff7d9d64ce6e6b037c9ded87The Android Open Source Project 226a89495f48f185779ff7d9d64ce6e6b037c9ded87The Android Open Source Project oIFS=$IFS 227a89495f48f185779ff7d9d64ce6e6b037c9ded87The Android Open Source Project # Some sh's can't handle IFS=/ for some reason. 228a89495f48f185779ff7d9d64ce6e6b037c9ded87The Android Open Source Project IFS='%' 229a89495f48f185779ff7d9d64ce6e6b037c9ded87The Android Open Source Project set x `echo "$dstdir" | sed -e 's@/@%@g' -e 's@^%@/@'` 230a89495f48f185779ff7d9d64ce6e6b037c9ded87The Android Open Source Project shift 231a89495f48f185779ff7d9d64ce6e6b037c9ded87The Android Open Source Project IFS=$oIFS 232a89495f48f185779ff7d9d64ce6e6b037c9ded87The Android Open Source Project 233a89495f48f185779ff7d9d64ce6e6b037c9ded87The Android Open Source Project pathcomp= 234a89495f48f185779ff7d9d64ce6e6b037c9ded87The Android Open Source Project 235a89495f48f185779ff7d9d64ce6e6b037c9ded87The Android Open Source Project while test $# -ne 0 ; do 236a89495f48f185779ff7d9d64ce6e6b037c9ded87The Android Open Source Project pathcomp=$pathcomp$1 237a89495f48f185779ff7d9d64ce6e6b037c9ded87The Android Open Source Project shift 238a89495f48f185779ff7d9d64ce6e6b037c9ded87The Android Open Source Project if test ! -d "$pathcomp"; then 239a89495f48f185779ff7d9d64ce6e6b037c9ded87The Android Open Source Project $mkdirprog "$pathcomp" 240a89495f48f185779ff7d9d64ce6e6b037c9ded87The Android Open Source Project # mkdir can fail with a `File exist' error in case several 241a89495f48f185779ff7d9d64ce6e6b037c9ded87The Android Open Source Project # install-sh are creating the directory concurrently. This 242a89495f48f185779ff7d9d64ce6e6b037c9ded87The Android Open Source Project # is OK. 243a89495f48f185779ff7d9d64ce6e6b037c9ded87The Android Open Source Project test -d "$pathcomp" || exit 244a89495f48f185779ff7d9d64ce6e6b037c9ded87The Android Open Source Project fi 245a89495f48f185779ff7d9d64ce6e6b037c9ded87The Android Open Source Project pathcomp=$pathcomp/ 246a89495f48f185779ff7d9d64ce6e6b037c9ded87The Android Open Source Project done 247a89495f48f185779ff7d9d64ce6e6b037c9ded87The Android Open Source Project fi 248a89495f48f185779ff7d9d64ce6e6b037c9ded87The Android Open Source Project 249a89495f48f185779ff7d9d64ce6e6b037c9ded87The Android Open Source Project if test -n "$dir_arg"; then 250a89495f48f185779ff7d9d64ce6e6b037c9ded87The Android Open Source Project $doit $mkdircmd "$dst" \ 251a89495f48f185779ff7d9d64ce6e6b037c9ded87The Android Open Source Project && { test -z "$chowncmd" || $doit $chowncmd "$dst"; } \ 252a89495f48f185779ff7d9d64ce6e6b037c9ded87The Android Open Source Project && { test -z "$chgrpcmd" || $doit $chgrpcmd "$dst"; } \ 253a89495f48f185779ff7d9d64ce6e6b037c9ded87The Android Open Source Project && { test -z "$stripcmd" || $doit $stripcmd "$dst"; } \ 254a89495f48f185779ff7d9d64ce6e6b037c9ded87The Android Open Source Project && { test -z "$chmodcmd" || $doit $chmodcmd "$dst"; } 255a89495f48f185779ff7d9d64ce6e6b037c9ded87The Android Open Source Project 256a89495f48f185779ff7d9d64ce6e6b037c9ded87The Android Open Source Project else 257a89495f48f185779ff7d9d64ce6e6b037c9ded87The Android Open Source Project dstfile=`basename "$dst"` 258a89495f48f185779ff7d9d64ce6e6b037c9ded87The Android Open Source Project 259a89495f48f185779ff7d9d64ce6e6b037c9ded87The Android Open Source Project # Make a couple of temp file names in the proper directory. 260a89495f48f185779ff7d9d64ce6e6b037c9ded87The Android Open Source Project dsttmp=$dstdir/_inst.$$_ 261a89495f48f185779ff7d9d64ce6e6b037c9ded87The Android Open Source Project rmtmp=$dstdir/_rm.$$_ 262a89495f48f185779ff7d9d64ce6e6b037c9ded87The Android Open Source Project 263a89495f48f185779ff7d9d64ce6e6b037c9ded87The Android Open Source Project # Trap to clean up those temp files at exit. 264a89495f48f185779ff7d9d64ce6e6b037c9ded87The Android Open Source Project trap 'ret=$?; rm -f "$dsttmp" "$rmtmp" && exit $ret' 0 265a89495f48f185779ff7d9d64ce6e6b037c9ded87The Android Open Source Project trap '(exit $?); exit' 1 2 13 15 266a89495f48f185779ff7d9d64ce6e6b037c9ded87The Android Open Source Project 267a89495f48f185779ff7d9d64ce6e6b037c9ded87The Android Open Source Project # Copy the file name to the temp name. 268a89495f48f185779ff7d9d64ce6e6b037c9ded87The Android Open Source Project $doit $cpprog "$src" "$dsttmp" && 269a89495f48f185779ff7d9d64ce6e6b037c9ded87The Android Open Source Project 270a89495f48f185779ff7d9d64ce6e6b037c9ded87The Android Open Source Project # and set any options; do chmod last to preserve setuid bits. 271a89495f48f185779ff7d9d64ce6e6b037c9ded87The Android Open Source Project # 272a89495f48f185779ff7d9d64ce6e6b037c9ded87The Android Open Source Project # If any of these fail, we abort the whole thing. If we want to 273a89495f48f185779ff7d9d64ce6e6b037c9ded87The Android Open Source Project # ignore errors from any of these, just make sure not to ignore 274a89495f48f185779ff7d9d64ce6e6b037c9ded87The Android Open Source Project # errors from the above "$doit $cpprog $src $dsttmp" command. 275a89495f48f185779ff7d9d64ce6e6b037c9ded87The Android Open Source Project # 276a89495f48f185779ff7d9d64ce6e6b037c9ded87The Android Open Source Project { test -z "$chowncmd" || $doit $chowncmd "$dsttmp"; } \ 277a89495f48f185779ff7d9d64ce6e6b037c9ded87The Android Open Source Project && { test -z "$chgrpcmd" || $doit $chgrpcmd "$dsttmp"; } \ 278a89495f48f185779ff7d9d64ce6e6b037c9ded87The Android Open Source Project && { test -z "$stripcmd" || $doit $stripcmd "$dsttmp"; } \ 279a89495f48f185779ff7d9d64ce6e6b037c9ded87The Android Open Source Project && { test -z "$chmodcmd" || $doit $chmodcmd "$dsttmp"; } && 280a89495f48f185779ff7d9d64ce6e6b037c9ded87The Android Open Source Project 281a89495f48f185779ff7d9d64ce6e6b037c9ded87The Android Open Source Project # Now rename the file to the real destination. 282a89495f48f185779ff7d9d64ce6e6b037c9ded87The Android Open Source Project { $doit $mvcmd -f "$dsttmp" "$dstdir/$dstfile" 2>/dev/null \ 283a89495f48f185779ff7d9d64ce6e6b037c9ded87The Android Open Source Project || { 284a89495f48f185779ff7d9d64ce6e6b037c9ded87The Android Open Source Project # The rename failed, perhaps because mv can't rename something else 285a89495f48f185779ff7d9d64ce6e6b037c9ded87The Android Open Source Project # to itself, or perhaps because mv is so ancient that it does not 286a89495f48f185779ff7d9d64ce6e6b037c9ded87The Android Open Source Project # support -f. 287a89495f48f185779ff7d9d64ce6e6b037c9ded87The Android Open Source Project 288a89495f48f185779ff7d9d64ce6e6b037c9ded87The Android Open Source Project # Now remove or move aside any old file at destination location. 289a89495f48f185779ff7d9d64ce6e6b037c9ded87The Android Open Source Project # We try this two ways since rm can't unlink itself on some 290a89495f48f185779ff7d9d64ce6e6b037c9ded87The Android Open Source Project # systems and the destination file might be busy for other 291a89495f48f185779ff7d9d64ce6e6b037c9ded87The Android Open Source Project # reasons. In this case, the final cleanup might fail but the new 292a89495f48f185779ff7d9d64ce6e6b037c9ded87The Android Open Source Project # file should still install successfully. 293a89495f48f185779ff7d9d64ce6e6b037c9ded87The Android Open Source Project { 294a89495f48f185779ff7d9d64ce6e6b037c9ded87The Android Open Source Project if test -f "$dstdir/$dstfile"; then 295a89495f48f185779ff7d9d64ce6e6b037c9ded87The Android Open Source Project $doit $rmcmd -f "$dstdir/$dstfile" 2>/dev/null \ 296a89495f48f185779ff7d9d64ce6e6b037c9ded87The Android Open Source Project || $doit $mvcmd -f "$dstdir/$dstfile" "$rmtmp" 2>/dev/null \ 297a89495f48f185779ff7d9d64ce6e6b037c9ded87The Android Open Source Project || { 298a89495f48f185779ff7d9d64ce6e6b037c9ded87The Android Open Source Project echo "$0: cannot unlink or rename $dstdir/$dstfile" >&2 299a89495f48f185779ff7d9d64ce6e6b037c9ded87The Android Open Source Project (exit 1); exit 1 300a89495f48f185779ff7d9d64ce6e6b037c9ded87The Android Open Source Project } 301a89495f48f185779ff7d9d64ce6e6b037c9ded87The Android Open Source Project else 302a89495f48f185779ff7d9d64ce6e6b037c9ded87The Android Open Source Project : 303a89495f48f185779ff7d9d64ce6e6b037c9ded87The Android Open Source Project fi 304a89495f48f185779ff7d9d64ce6e6b037c9ded87The Android Open Source Project } && 305a89495f48f185779ff7d9d64ce6e6b037c9ded87The Android Open Source Project 306a89495f48f185779ff7d9d64ce6e6b037c9ded87The Android Open Source Project # Now rename the file to the real destination. 307a89495f48f185779ff7d9d64ce6e6b037c9ded87The Android Open Source Project $doit $mvcmd "$dsttmp" "$dstdir/$dstfile" 308a89495f48f185779ff7d9d64ce6e6b037c9ded87The Android Open Source Project } 309a89495f48f185779ff7d9d64ce6e6b037c9ded87The Android Open Source Project } 310a89495f48f185779ff7d9d64ce6e6b037c9ded87The Android Open Source Project fi || { (exit 1); exit 1; } 311a89495f48f185779ff7d9d64ce6e6b037c9ded87The Android Open Source Projectdone 312a89495f48f185779ff7d9d64ce6e6b037c9ded87The Android Open Source Project 313a89495f48f185779ff7d9d64ce6e6b037c9ded87The Android Open Source Project# The final little trick to "correctly" pass the exit status to the exit trap. 314a89495f48f185779ff7d9d64ce6e6b037c9ded87The Android Open Source Project{ 315a89495f48f185779ff7d9d64ce6e6b037c9ded87The Android Open Source Project (exit 0); exit 0 316a89495f48f185779ff7d9d64ce6e6b037c9ded87The Android Open Source Project} 317a89495f48f185779ff7d9d64ce6e6b037c9ded87The Android Open Source Project 318a89495f48f185779ff7d9d64ce6e6b037c9ded87The Android Open Source Project# Local variables: 319a89495f48f185779ff7d9d64ce6e6b037c9ded87The Android Open Source Project# eval: (add-hook 'write-file-hooks 'time-stamp) 320a89495f48f185779ff7d9d64ce6e6b037c9ded87The Android Open Source Project# time-stamp-start: "scriptversion=" 321a89495f48f185779ff7d9d64ce6e6b037c9ded87The Android Open Source Project# time-stamp-format: "%:y-%02m-%02d.%02H" 322a89495f48f185779ff7d9d64ce6e6b037c9ded87The Android Open Source Project# time-stamp-end: "$" 323a89495f48f185779ff7d9d64ce6e6b037c9ded87The Android Open Source Project# End: 324