1*1208bc7eSAndroid Build Coastguard Worker#! /bin/sh 2*1208bc7eSAndroid Build Coastguard Worker# 3*1208bc7eSAndroid Build Coastguard Worker# install - install a program, script, or datafile 4*1208bc7eSAndroid Build Coastguard Worker# This comes from X11R5 (mit/util/scripts/install.sh). 5*1208bc7eSAndroid Build Coastguard Worker# 6*1208bc7eSAndroid Build Coastguard Worker# Copyright 1991 by the Massachusetts Institute of Technology 7*1208bc7eSAndroid Build Coastguard Worker# 8*1208bc7eSAndroid Build Coastguard Worker# Permission to use, copy, modify, distribute, and sell this software and its 9*1208bc7eSAndroid Build Coastguard Worker# documentation for any purpose is hereby granted without fee, provided that 10*1208bc7eSAndroid Build Coastguard Worker# the above copyright notice appear in all copies and that both that 11*1208bc7eSAndroid Build Coastguard Worker# copyright notice and this permission notice appear in supporting 12*1208bc7eSAndroid Build Coastguard Worker# documentation, and that the name of M.I.T. not be used in advertising or 13*1208bc7eSAndroid Build Coastguard Worker# publicity pertaining to distribution of the software without specific, 14*1208bc7eSAndroid Build Coastguard Worker# written prior permission. M.I.T. makes no representations about the 15*1208bc7eSAndroid Build Coastguard Worker# suitability of this software for any purpose. It is provided "as is" 16*1208bc7eSAndroid Build Coastguard Worker# without express or implied warranty. 17*1208bc7eSAndroid Build Coastguard Worker# 18*1208bc7eSAndroid Build Coastguard Worker# Calling this script install-sh is preferred over install.sh, to prevent 19*1208bc7eSAndroid Build Coastguard Worker# `make' implicit rules from creating a file called install from it 20*1208bc7eSAndroid Build Coastguard Worker# when there is no Makefile. 21*1208bc7eSAndroid Build Coastguard Worker# 22*1208bc7eSAndroid Build Coastguard Worker# This script is compatible with the BSD install script, but was written 23*1208bc7eSAndroid Build Coastguard Worker# from scratch. It can only install one file at a time, a restriction 24*1208bc7eSAndroid Build Coastguard Worker# shared with many OS's install programs. 25*1208bc7eSAndroid Build Coastguard Worker 26*1208bc7eSAndroid Build Coastguard Worker 27*1208bc7eSAndroid Build Coastguard Worker# set DOITPROG to echo to test this script 28*1208bc7eSAndroid Build Coastguard Worker 29*1208bc7eSAndroid Build Coastguard Worker# Don't use :- since 4.3BSD and earlier shells don't like it. 30*1208bc7eSAndroid Build Coastguard Workerdoit="${DOITPROG-}" 31*1208bc7eSAndroid Build Coastguard Worker 32*1208bc7eSAndroid Build Coastguard Worker 33*1208bc7eSAndroid Build Coastguard Worker# put in absolute paths if you don't have them in your path; or use env. vars. 34*1208bc7eSAndroid Build Coastguard Worker 35*1208bc7eSAndroid Build Coastguard Workermvprog="${MVPROG-mv}" 36*1208bc7eSAndroid Build Coastguard Workercpprog="${CPPROG-cp}" 37*1208bc7eSAndroid Build Coastguard Workerchmodprog="${CHMODPROG-chmod}" 38*1208bc7eSAndroid Build Coastguard Workerchownprog="${CHOWNPROG-chown}" 39*1208bc7eSAndroid Build Coastguard Workerchgrpprog="${CHGRPPROG-chgrp}" 40*1208bc7eSAndroid Build Coastguard Workerstripprog="${STRIPPROG-strip}" 41*1208bc7eSAndroid Build Coastguard Workerrmprog="${RMPROG-rm}" 42*1208bc7eSAndroid Build Coastguard Workermkdirprog="${MKDIRPROG-mkdir}" 43*1208bc7eSAndroid Build Coastguard Worker 44*1208bc7eSAndroid Build Coastguard Workertransformbasename="" 45*1208bc7eSAndroid Build Coastguard Workertransform_arg="" 46*1208bc7eSAndroid Build Coastguard Workerinstcmd="$mvprog" 47*1208bc7eSAndroid Build Coastguard Workerchmodcmd="$chmodprog 0755" 48*1208bc7eSAndroid Build Coastguard Workerchowncmd="" 49*1208bc7eSAndroid Build Coastguard Workerchgrpcmd="" 50*1208bc7eSAndroid Build Coastguard Workerstripcmd="" 51*1208bc7eSAndroid Build Coastguard Workerrmcmd="$rmprog -f" 52*1208bc7eSAndroid Build Coastguard Workermvcmd="$mvprog" 53*1208bc7eSAndroid Build Coastguard Workersrc="" 54*1208bc7eSAndroid Build Coastguard Workerdst="" 55*1208bc7eSAndroid Build Coastguard Workerdir_arg="" 56*1208bc7eSAndroid Build Coastguard Worker 57*1208bc7eSAndroid Build Coastguard Workerwhile [ x"$1" != x ]; do 58*1208bc7eSAndroid Build Coastguard Worker case $1 in 59*1208bc7eSAndroid Build Coastguard Worker -c) instcmd="$cpprog" 60*1208bc7eSAndroid Build Coastguard Worker shift 61*1208bc7eSAndroid Build Coastguard Worker continue;; 62*1208bc7eSAndroid Build Coastguard Worker 63*1208bc7eSAndroid Build Coastguard Worker -d) dir_arg=true 64*1208bc7eSAndroid Build Coastguard Worker shift 65*1208bc7eSAndroid Build Coastguard Worker continue;; 66*1208bc7eSAndroid Build Coastguard Worker 67*1208bc7eSAndroid Build Coastguard Worker -m) chmodcmd="$chmodprog $2" 68*1208bc7eSAndroid Build Coastguard Worker shift 69*1208bc7eSAndroid Build Coastguard Worker shift 70*1208bc7eSAndroid Build Coastguard Worker continue;; 71*1208bc7eSAndroid Build Coastguard Worker 72*1208bc7eSAndroid Build Coastguard Worker -o) chowncmd="$chownprog $2" 73*1208bc7eSAndroid Build Coastguard Worker shift 74*1208bc7eSAndroid Build Coastguard Worker shift 75*1208bc7eSAndroid Build Coastguard Worker continue;; 76*1208bc7eSAndroid Build Coastguard Worker 77*1208bc7eSAndroid Build Coastguard Worker -g) chgrpcmd="$chgrpprog $2" 78*1208bc7eSAndroid Build Coastguard Worker shift 79*1208bc7eSAndroid Build Coastguard Worker shift 80*1208bc7eSAndroid Build Coastguard Worker continue;; 81*1208bc7eSAndroid Build Coastguard Worker 82*1208bc7eSAndroid Build Coastguard Worker -s) stripcmd="$stripprog" 83*1208bc7eSAndroid Build Coastguard Worker shift 84*1208bc7eSAndroid Build Coastguard Worker continue;; 85*1208bc7eSAndroid Build Coastguard Worker 86*1208bc7eSAndroid Build Coastguard Worker -t=*) transformarg=`echo $1 | sed 's/-t=//'` 87*1208bc7eSAndroid Build Coastguard Worker shift 88*1208bc7eSAndroid Build Coastguard Worker continue;; 89*1208bc7eSAndroid Build Coastguard Worker 90*1208bc7eSAndroid Build Coastguard Worker -b=*) transformbasename=`echo $1 | sed 's/-b=//'` 91*1208bc7eSAndroid Build Coastguard Worker shift 92*1208bc7eSAndroid Build Coastguard Worker continue;; 93*1208bc7eSAndroid Build Coastguard Worker 94*1208bc7eSAndroid Build Coastguard Worker *) if [ x"$src" = x ] 95*1208bc7eSAndroid Build Coastguard Worker then 96*1208bc7eSAndroid Build Coastguard Worker src=$1 97*1208bc7eSAndroid Build Coastguard Worker else 98*1208bc7eSAndroid Build Coastguard Worker # this colon is to work around a 386BSD /bin/sh bug 99*1208bc7eSAndroid Build Coastguard Worker : 100*1208bc7eSAndroid Build Coastguard Worker dst=$1 101*1208bc7eSAndroid Build Coastguard Worker fi 102*1208bc7eSAndroid Build Coastguard Worker shift 103*1208bc7eSAndroid Build Coastguard Worker continue;; 104*1208bc7eSAndroid Build Coastguard Worker esac 105*1208bc7eSAndroid Build Coastguard Workerdone 106*1208bc7eSAndroid Build Coastguard Worker 107*1208bc7eSAndroid Build Coastguard Workerif [ x"$src" = x ] 108*1208bc7eSAndroid Build Coastguard Workerthen 109*1208bc7eSAndroid Build Coastguard Worker echo "install: no input file specified" 110*1208bc7eSAndroid Build Coastguard Worker exit 1 111*1208bc7eSAndroid Build Coastguard Workerelse 112*1208bc7eSAndroid Build Coastguard Worker true 113*1208bc7eSAndroid Build Coastguard Workerfi 114*1208bc7eSAndroid Build Coastguard Worker 115*1208bc7eSAndroid Build Coastguard Workerif [ x"$dir_arg" != x ]; then 116*1208bc7eSAndroid Build Coastguard Worker dst=$src 117*1208bc7eSAndroid Build Coastguard Worker src="" 118*1208bc7eSAndroid Build Coastguard Worker 119*1208bc7eSAndroid Build Coastguard Worker if [ -d $dst ]; then 120*1208bc7eSAndroid Build Coastguard Worker instcmd=: 121*1208bc7eSAndroid Build Coastguard Worker else 122*1208bc7eSAndroid Build Coastguard Worker instcmd=mkdir 123*1208bc7eSAndroid Build Coastguard Worker fi 124*1208bc7eSAndroid Build Coastguard Workerelse 125*1208bc7eSAndroid Build Coastguard Worker 126*1208bc7eSAndroid Build Coastguard Worker# Waiting for this to be detected by the "$instcmd $src $dsttmp" command 127*1208bc7eSAndroid Build Coastguard Worker# might cause directories to be created, which would be especially bad 128*1208bc7eSAndroid Build Coastguard Worker# if $src (and thus $dsttmp) contains '*'. 129*1208bc7eSAndroid Build Coastguard Worker 130*1208bc7eSAndroid Build Coastguard Worker if [ -f $src -o -d $src ] 131*1208bc7eSAndroid Build Coastguard Worker then 132*1208bc7eSAndroid Build Coastguard Worker true 133*1208bc7eSAndroid Build Coastguard Worker else 134*1208bc7eSAndroid Build Coastguard Worker echo "install: $src does not exist" 135*1208bc7eSAndroid Build Coastguard Worker exit 1 136*1208bc7eSAndroid Build Coastguard Worker fi 137*1208bc7eSAndroid Build Coastguard Worker 138*1208bc7eSAndroid Build Coastguard Worker if [ x"$dst" = x ] 139*1208bc7eSAndroid Build Coastguard Worker then 140*1208bc7eSAndroid Build Coastguard Worker echo "install: no destination specified" 141*1208bc7eSAndroid Build Coastguard Worker exit 1 142*1208bc7eSAndroid Build Coastguard Worker else 143*1208bc7eSAndroid Build Coastguard Worker true 144*1208bc7eSAndroid Build Coastguard Worker fi 145*1208bc7eSAndroid Build Coastguard Worker 146*1208bc7eSAndroid Build Coastguard Worker# If destination is a directory, append the input filename; if your system 147*1208bc7eSAndroid Build Coastguard Worker# does not like double slashes in filenames, you may need to add some logic 148*1208bc7eSAndroid Build Coastguard Worker 149*1208bc7eSAndroid Build Coastguard Worker if [ -d $dst ] 150*1208bc7eSAndroid Build Coastguard Worker then 151*1208bc7eSAndroid Build Coastguard Worker dst="$dst"/`basename $src` 152*1208bc7eSAndroid Build Coastguard Worker else 153*1208bc7eSAndroid Build Coastguard Worker true 154*1208bc7eSAndroid Build Coastguard Worker fi 155*1208bc7eSAndroid Build Coastguard Workerfi 156*1208bc7eSAndroid Build Coastguard Worker 157*1208bc7eSAndroid Build Coastguard Worker## this sed command emulates the dirname command 158*1208bc7eSAndroid Build Coastguard Workerdstdir=`echo $dst | sed -e 's,[^/]*$,,;s,/$,,;s,^$,.,'` 159*1208bc7eSAndroid Build Coastguard Worker 160*1208bc7eSAndroid Build Coastguard Worker# Make sure that the destination directory exists. 161*1208bc7eSAndroid Build Coastguard Worker# this part is taken from Noah Friedman's mkinstalldirs script 162*1208bc7eSAndroid Build Coastguard Worker 163*1208bc7eSAndroid Build Coastguard Worker# Skip lots of stat calls in the usual case. 164*1208bc7eSAndroid Build Coastguard Workerif [ ! -d "$dstdir" ]; then 165*1208bc7eSAndroid Build Coastguard WorkerdefaultIFS=' 166*1208bc7eSAndroid Build Coastguard Worker' 167*1208bc7eSAndroid Build Coastguard WorkerIFS="${IFS-${defaultIFS}}" 168*1208bc7eSAndroid Build Coastguard Worker 169*1208bc7eSAndroid Build Coastguard WorkeroIFS="${IFS}" 170*1208bc7eSAndroid Build Coastguard Worker# Some sh's can't handle IFS=/ for some reason. 171*1208bc7eSAndroid Build Coastguard WorkerIFS='%' 172*1208bc7eSAndroid Build Coastguard Workerset - `echo ${dstdir} | sed -e 's@/@%@g' -e 's@^%@/@'` 173*1208bc7eSAndroid Build Coastguard WorkerIFS="${oIFS}" 174*1208bc7eSAndroid Build Coastguard Worker 175*1208bc7eSAndroid Build Coastguard Workerpathcomp='' 176*1208bc7eSAndroid Build Coastguard Worker 177*1208bc7eSAndroid Build Coastguard Workerwhile [ $# -ne 0 ] ; do 178*1208bc7eSAndroid Build Coastguard Worker pathcomp="${pathcomp}${1}" 179*1208bc7eSAndroid Build Coastguard Worker shift 180*1208bc7eSAndroid Build Coastguard Worker 181*1208bc7eSAndroid Build Coastguard Worker if [ ! -d "${pathcomp}" ] ; 182*1208bc7eSAndroid Build Coastguard Worker then 183*1208bc7eSAndroid Build Coastguard Worker $mkdirprog "${pathcomp}" 184*1208bc7eSAndroid Build Coastguard Worker else 185*1208bc7eSAndroid Build Coastguard Worker true 186*1208bc7eSAndroid Build Coastguard Worker fi 187*1208bc7eSAndroid Build Coastguard Worker 188*1208bc7eSAndroid Build Coastguard Worker pathcomp="${pathcomp}/" 189*1208bc7eSAndroid Build Coastguard Workerdone 190*1208bc7eSAndroid Build Coastguard Workerfi 191*1208bc7eSAndroid Build Coastguard Worker 192*1208bc7eSAndroid Build Coastguard Workerif [ x"$dir_arg" != x ] 193*1208bc7eSAndroid Build Coastguard Workerthen 194*1208bc7eSAndroid Build Coastguard Worker $doit $instcmd $dst && 195*1208bc7eSAndroid Build Coastguard Worker 196*1208bc7eSAndroid Build Coastguard Worker if [ x"$chowncmd" != x ]; then $doit $chowncmd $dst; else true ; fi && 197*1208bc7eSAndroid Build Coastguard Worker if [ x"$chgrpcmd" != x ]; then $doit $chgrpcmd $dst; else true ; fi && 198*1208bc7eSAndroid Build Coastguard Worker if [ x"$stripcmd" != x ]; then $doit $stripcmd $dst; else true ; fi && 199*1208bc7eSAndroid Build Coastguard Worker if [ x"$chmodcmd" != x ]; then $doit $chmodcmd $dst; else true ; fi 200*1208bc7eSAndroid Build Coastguard Workerelse 201*1208bc7eSAndroid Build Coastguard Worker 202*1208bc7eSAndroid Build Coastguard Worker# If we're going to rename the final executable, determine the name now. 203*1208bc7eSAndroid Build Coastguard Worker 204*1208bc7eSAndroid Build Coastguard Worker if [ x"$transformarg" = x ] 205*1208bc7eSAndroid Build Coastguard Worker then 206*1208bc7eSAndroid Build Coastguard Worker dstfile=`basename $dst` 207*1208bc7eSAndroid Build Coastguard Worker else 208*1208bc7eSAndroid Build Coastguard Worker dstfile=`basename $dst $transformbasename | 209*1208bc7eSAndroid Build Coastguard Worker sed $transformarg`$transformbasename 210*1208bc7eSAndroid Build Coastguard Worker fi 211*1208bc7eSAndroid Build Coastguard Worker 212*1208bc7eSAndroid Build Coastguard Worker# don't allow the sed command to completely eliminate the filename 213*1208bc7eSAndroid Build Coastguard Worker 214*1208bc7eSAndroid Build Coastguard Worker if [ x"$dstfile" = x ] 215*1208bc7eSAndroid Build Coastguard Worker then 216*1208bc7eSAndroid Build Coastguard Worker dstfile=`basename $dst` 217*1208bc7eSAndroid Build Coastguard Worker else 218*1208bc7eSAndroid Build Coastguard Worker true 219*1208bc7eSAndroid Build Coastguard Worker fi 220*1208bc7eSAndroid Build Coastguard Worker 221*1208bc7eSAndroid Build Coastguard Worker# Make a temp file name in the proper directory. 222*1208bc7eSAndroid Build Coastguard Worker 223*1208bc7eSAndroid Build Coastguard Worker dsttmp=$dstdir/#inst.$$# 224*1208bc7eSAndroid Build Coastguard Worker 225*1208bc7eSAndroid Build Coastguard Worker# Move or copy the file name to the temp name 226*1208bc7eSAndroid Build Coastguard Worker 227*1208bc7eSAndroid Build Coastguard Worker $doit $instcmd $src $dsttmp && 228*1208bc7eSAndroid Build Coastguard Worker 229*1208bc7eSAndroid Build Coastguard Worker trap "rm -f ${dsttmp}" 0 && 230*1208bc7eSAndroid Build Coastguard Worker 231*1208bc7eSAndroid Build Coastguard Worker# and set any options; do chmod last to preserve setuid bits 232*1208bc7eSAndroid Build Coastguard Worker 233*1208bc7eSAndroid Build Coastguard Worker# If any of these fail, we abort the whole thing. If we want to 234*1208bc7eSAndroid Build Coastguard Worker# ignore errors from any of these, just make sure not to ignore 235*1208bc7eSAndroid Build Coastguard Worker# errors from the above "$doit $instcmd $src $dsttmp" command. 236*1208bc7eSAndroid Build Coastguard Worker 237*1208bc7eSAndroid Build Coastguard Worker if [ x"$chowncmd" != x ]; then $doit $chowncmd $dsttmp; else true;fi && 238*1208bc7eSAndroid Build Coastguard Worker if [ x"$chgrpcmd" != x ]; then $doit $chgrpcmd $dsttmp; else true;fi && 239*1208bc7eSAndroid Build Coastguard Worker if [ x"$stripcmd" != x ]; then $doit $stripcmd $dsttmp; else true;fi && 240*1208bc7eSAndroid Build Coastguard Worker if [ x"$chmodcmd" != x ]; then $doit $chmodcmd $dsttmp; else true;fi && 241*1208bc7eSAndroid Build Coastguard Worker 242*1208bc7eSAndroid Build Coastguard Worker# Now rename the file to the real destination. 243*1208bc7eSAndroid Build Coastguard Worker 244*1208bc7eSAndroid Build Coastguard Worker $doit $rmcmd -f $dstdir/$dstfile && 245*1208bc7eSAndroid Build Coastguard Worker $doit $mvcmd $dsttmp $dstdir/$dstfile 246*1208bc7eSAndroid Build Coastguard Worker 247*1208bc7eSAndroid Build Coastguard Workerfi && 248*1208bc7eSAndroid Build Coastguard Worker 249*1208bc7eSAndroid Build Coastguard Worker 250*1208bc7eSAndroid Build Coastguard Workerexit 0 251