1211440Sadrian#! /bin/sh 2211440Sadrian# 3211440Sadrian# install - install a program, script, or datafile 4211440Sadrian# This comes from X11R5. 5211440Sadrian# 6211440Sadrian# Calling this script install-sh is preferred over install.sh, to prevent 7211440Sadrian# `make' implicit rules from creating a file called install from it 8211440Sadrian# when there is no Makefile. 9211440Sadrian# 10211440Sadrian# This script is compatible with the BSD install script, but was written 11211440Sadrian# from scratch. 12211440Sadrian# 13211440Sadrian 14211440Sadrian 15211440Sadrian# set DOITPROG to echo to test this script 16211440Sadrian 17211440Sadrian# Don't use :- since 4.3BSD and earlier shells don't like it. 18211440Sadriandoit="${DOITPROG-}" 19211440Sadrian 20211440Sadrian 21211440Sadrian# put in absolute paths if you don't have them in your path; or use env. vars. 22211440Sadrian 23211440Sadrianmvprog="${MVPROG-mv}" 24211440Sadriancpprog="${CPPROG-cp}" 25211440Sadrianchmodprog="${CHMODPROG-chmod}" 26211440Sadrianchownprog="${CHOWNPROG-chown}" 27211440Sadrianchgrpprog="${CHGRPPROG-chgrp}" 28211440Sadrianstripprog="${STRIPPROG-strip}" 29211440Sadrianrmprog="${RMPROG-rm}" 30211440Sadrianmkdirprog="${MKDIRPROG-mkdir}" 31211440Sadrian 32211440Sadriantranformbasename="" 33211440Sadriantransform_arg="" 34211440Sadrianinstcmd="$mvprog" 35211440Sadrianchmodcmd="$chmodprog 0755" 36211440Sadrianchowncmd="" 37211440Sadrianchgrpcmd="" 38211440Sadrianstripcmd="" 39211440Sadrianrmcmd="$rmprog -f" 40211440Sadrianmvcmd="$mvprog" 41211440Sadriansrc="" 42211440Sadriandst="" 43211440Sadriandir_arg="" 44211440Sadrian 45211440Sadrianwhile [ x"$1" != x ]; do 46211440Sadrian case $1 in 47211440Sadrian -c) instcmd="$cpprog" 48211440Sadrian shift 49211440Sadrian continue;; 50211503Sadrian 51211503Sadrian -d) dir_arg=true 52211503Sadrian shift 53211440Sadrian continue;; 54211440Sadrian 55211440Sadrian -m) chmodcmd="$chmodprog $2" 56211440Sadrian shift 57211440Sadrian shift 58211440Sadrian continue;; 59211440Sadrian 60211440Sadrian -o) chowncmd="$chownprog $2" 61211440Sadrian shift 62211440Sadrian shift 63211440Sadrian continue;; 64211440Sadrian 65211440Sadrian -g) chgrpcmd="$chgrpprog $2" 66211440Sadrian shift 67211440Sadrian shift 68211440Sadrian continue;; 69211440Sadrian 70211440Sadrian -s) stripcmd="$stripprog" 71211440Sadrian shift 72211440Sadrian continue;; 73211440Sadrian 74211440Sadrian -t=*) transformarg=`echo $1 | sed 's/-t=//'` 75211440Sadrian shift 76211440Sadrian continue;; 77211440Sadrian 78211440Sadrian -b=*) transformbasename=`echo $1 | sed 's/-b=//'` 79211440Sadrian shift 80211440Sadrian continue;; 81211440Sadrian 82211440Sadrian *) if [ x"$src" = x ] 83211440Sadrian then 84211440Sadrian src=$1 85 else 86 # this colon is to work around a 386BSD /bin/sh bug 87 : 88 dst=$1 89 fi 90 shift 91 continue;; 92 esac 93done 94 95if [ x"$src" = x ] 96then 97 echo "install: no input file specified" 98 exit 1 99else 100 true 101fi 102 103if [ x"$dir_arg" != x ]; then 104 dst=$src 105 src="" 106 107 if [ -d $dst ]; then 108 instcmd=: 109 else 110 instcmd=mkdir 111 fi 112else 113 114# Waiting for this to be detected by the "$instcmd $src $dsttmp" command 115# might cause directories to be created, which would be especially bad 116# if $src (and thus $dsttmp) contains '*'. 117 118 if [ -f $src -o -d $src ] 119 then 120 true 121 else 122 echo "install: $src does not exist" 123 exit 1 124 fi 125 126 if [ x"$dst" = x ] 127 then 128 echo "install: no destination specified" 129 exit 1 130 else 131 true 132 fi 133 134# If destination is a directory, append the input filename; if your system 135# does not like double slashes in filenames, you may need to add some logic 136 137 if [ -d $dst ] 138 then 139 dst="$dst"/`basename $src` 140 else 141 true 142 fi 143fi 144 145## this sed command emulates the dirname command 146dstdir=`echo $dst | sed -e 's,[^/]*$,,;s,/$,,;s,^$,.,'` 147 148# Make sure that the destination directory exists. 149# this part is taken from Noah Friedman's mkinstalldirs script 150 151# Skip lots of stat calls in the usual case. 152if [ ! -d "$dstdir" ]; then 153defaultIFS=' 154' 155IFS="${IFS-${defaultIFS}}" 156 157oIFS="${IFS}" 158# Some sh's can't handle IFS=/ for some reason. 159IFS='%' 160set - `echo ${dstdir} | sed -e 's@/@%@g' -e 's@^%@/@'` 161IFS="${oIFS}" 162 163pathcomp='' 164 165while [ $# -ne 0 ] ; do 166 pathcomp="${pathcomp}${1}" 167 shift 168 169 if [ ! -d "${pathcomp}" ] ; 170 then 171 $mkdirprog "${pathcomp}" 172 else 173 true 174 fi 175 176 pathcomp="${pathcomp}/" 177done 178fi 179 180if [ x"$dir_arg" != x ] 181then 182 $doit $instcmd $dst && 183 184 if [ x"$chowncmd" != x ]; then $doit $chowncmd $dst; else true ; fi && 185 if [ x"$chgrpcmd" != x ]; then $doit $chgrpcmd $dst; else true ; fi && 186 if [ x"$stripcmd" != x ]; then $doit $stripcmd $dst; else true ; fi && 187 if [ x"$chmodcmd" != x ]; then $doit $chmodcmd $dst; else true ; fi 188else 189 190# If we're going to rename the final executable, determine the name now. 191 192 if [ x"$transformarg" = x ] 193 then 194 dstfile=`basename $dst` 195 else 196 dstfile=`basename $dst $transformbasename | 197 sed $transformarg`$transformbasename 198 fi 199 200# don't allow the sed command to completely eliminate the filename 201 202 if [ x"$dstfile" = x ] 203 then 204 dstfile=`basename $dst` 205 else 206 true 207 fi 208 209# Make a temp file name in the proper directory. 210 211 dsttmp=$dstdir/#inst.$$# 212 213# Move or copy the file name to the temp name 214 215 $doit $instcmd $src $dsttmp && 216 217 trap "rm -f ${dsttmp}" 0 && 218 219# and set any options; do chmod last to preserve setuid bits 220 221# If any of these fail, we abort the whole thing. If we want to 222# ignore errors from any of these, just make sure not to ignore 223# errors from the above "$doit $instcmd $src $dsttmp" command. 224 225 if [ x"$chowncmd" != x ]; then $doit $chowncmd $dsttmp; else true;fi && 226 if [ x"$chgrpcmd" != x ]; then $doit $chgrpcmd $dsttmp; else true;fi && 227 if [ x"$stripcmd" != x ]; then $doit $stripcmd $dsttmp; else true;fi && 228 if [ x"$chmodcmd" != x ]; then $doit $chmodcmd $dsttmp; else true;fi && 229 230# Now rename the file to the real destination. 231 232 $doit $rmcmd -f $dstdir/$dstfile && 233 $doit $mvcmd $dsttmp $dstdir/$dstfile 234 235fi && 236 237 238exit 0 239