Mercurial > hg > index.fcgi > gift-gnutella > gift-gnutella-0.0.11-1pba
diff install-sh @ 0:d39e1d0d75b6
initial add
author | paulo@hit-nxdomain.opendns.com |
---|---|
date | Sat, 20 Feb 2010 21:18:28 -0800 |
parents | |
children |
line diff
1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/install-sh Sat Feb 20 21:18:28 2010 -0800 1.3 @@ -0,0 +1,294 @@ 1.4 +#!/bin/sh 1.5 +# 1.6 +# install - install a program, script, or datafile 1.7 +# 1.8 +# This originates from X11R5 (mit/util/scripts/install.sh), which was 1.9 +# later released in X11R6 (xc/config/util/install.sh) with the 1.10 +# following copyright and license. 1.11 +# 1.12 +# Copyright (C) 1994 X Consortium 1.13 +# 1.14 +# Permission is hereby granted, free of charge, to any person obtaining a copy 1.15 +# of this software and associated documentation files (the "Software"), to 1.16 +# deal in the Software without restriction, including without limitation the 1.17 +# rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 1.18 +# sell copies of the Software, and to permit persons to whom the Software is 1.19 +# furnished to do so, subject to the following conditions: 1.20 +# 1.21 +# The above copyright notice and this permission notice shall be included in 1.22 +# all copies or substantial portions of the Software. 1.23 +# 1.24 +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 1.25 +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 1.26 +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 1.27 +# X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN 1.28 +# AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNEC- 1.29 +# TION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 1.30 +# 1.31 +# Except as contained in this notice, the name of the X Consortium shall not 1.32 +# be used in advertising or otherwise to promote the sale, use or other deal- 1.33 +# ings in this Software without prior written authorization from the X Consor- 1.34 +# tium. 1.35 +# 1.36 +# 1.37 +# FSF changes to this file are in the public domain. 1.38 +# 1.39 +# Calling this script install-sh is preferred over install.sh, to prevent 1.40 +# `make' implicit rules from creating a file called install from it 1.41 +# when there is no Makefile. 1.42 +# 1.43 +# This script is compatible with the BSD install script, but was written 1.44 +# from scratch. It can only install one file at a time, a restriction 1.45 +# shared with many OS's install programs. 1.46 + 1.47 + 1.48 +# set DOITPROG to echo to test this script 1.49 + 1.50 +# Don't use :- since 4.3BSD and earlier shells don't like it. 1.51 +doit="${DOITPROG-}" 1.52 + 1.53 + 1.54 +# put in absolute paths if you don't have them in your path; or use env. vars. 1.55 + 1.56 +mvprog="${MVPROG-mv}" 1.57 +cpprog="${CPPROG-cp}" 1.58 +chmodprog="${CHMODPROG-chmod}" 1.59 +chownprog="${CHOWNPROG-chown}" 1.60 +chgrpprog="${CHGRPPROG-chgrp}" 1.61 +stripprog="${STRIPPROG-strip}" 1.62 +rmprog="${RMPROG-rm}" 1.63 +mkdirprog="${MKDIRPROG-mkdir}" 1.64 + 1.65 +transformbasename="" 1.66 +transform_arg="" 1.67 +instcmd="$mvprog" 1.68 +chmodcmd="$chmodprog 0755" 1.69 +chowncmd="" 1.70 +chgrpcmd="" 1.71 +stripcmd="" 1.72 +rmcmd="$rmprog -f" 1.73 +mvcmd="$mvprog" 1.74 +src="" 1.75 +dst="" 1.76 +dir_arg="" 1.77 + 1.78 +while [ x"$1" != x ]; do 1.79 + case $1 in 1.80 + -c) instcmd=$cpprog 1.81 + shift 1.82 + continue;; 1.83 + 1.84 + -d) dir_arg=true 1.85 + shift 1.86 + continue;; 1.87 + 1.88 + -m) chmodcmd="$chmodprog $2" 1.89 + shift 1.90 + shift 1.91 + continue;; 1.92 + 1.93 + -o) chowncmd="$chownprog $2" 1.94 + shift 1.95 + shift 1.96 + continue;; 1.97 + 1.98 + -g) chgrpcmd="$chgrpprog $2" 1.99 + shift 1.100 + shift 1.101 + continue;; 1.102 + 1.103 + -s) stripcmd=$stripprog 1.104 + shift 1.105 + continue;; 1.106 + 1.107 + -t=*) transformarg=`echo $1 | sed 's/-t=//'` 1.108 + shift 1.109 + continue;; 1.110 + 1.111 + -b=*) transformbasename=`echo $1 | sed 's/-b=//'` 1.112 + shift 1.113 + continue;; 1.114 + 1.115 + *) if [ x"$src" = x ] 1.116 + then 1.117 + src=$1 1.118 + else 1.119 + # this colon is to work around a 386BSD /bin/sh bug 1.120 + : 1.121 + dst=$1 1.122 + fi 1.123 + shift 1.124 + continue;; 1.125 + esac 1.126 +done 1.127 + 1.128 +if [ x"$src" = x ] 1.129 +then 1.130 + echo "$0: no input file specified" >&2 1.131 + exit 1 1.132 +else 1.133 + : 1.134 +fi 1.135 + 1.136 +if [ x"$dir_arg" != x ]; then 1.137 + dst=$src 1.138 + src="" 1.139 + 1.140 + if [ -d "$dst" ]; then 1.141 + instcmd=: 1.142 + chmodcmd="" 1.143 + else 1.144 + instcmd=$mkdirprog 1.145 + fi 1.146 +else 1.147 + 1.148 +# Waiting for this to be detected by the "$instcmd $src $dsttmp" command 1.149 +# might cause directories to be created, which would be especially bad 1.150 +# if $src (and thus $dsttmp) contains '*'. 1.151 + 1.152 + if [ -f "$src" ] || [ -d "$src" ] 1.153 + then 1.154 + : 1.155 + else 1.156 + echo "$0: $src does not exist" >&2 1.157 + exit 1 1.158 + fi 1.159 + 1.160 + if [ x"$dst" = x ] 1.161 + then 1.162 + echo "$0: no destination specified" >&2 1.163 + exit 1 1.164 + else 1.165 + : 1.166 + fi 1.167 + 1.168 +# If destination is a directory, append the input filename; if your system 1.169 +# does not like double slashes in filenames, you may need to add some logic 1.170 + 1.171 + if [ -d "$dst" ] 1.172 + then 1.173 + dst=$dst/`basename "$src"` 1.174 + else 1.175 + : 1.176 + fi 1.177 +fi 1.178 + 1.179 +## this sed command emulates the dirname command 1.180 +dstdir=`echo "$dst" | sed -e 's,[^/]*$,,;s,/$,,;s,^$,.,'` 1.181 + 1.182 +# Make sure that the destination directory exists. 1.183 +# this part is taken from Noah Friedman's mkinstalldirs script 1.184 + 1.185 +# Skip lots of stat calls in the usual case. 1.186 +if [ ! -d "$dstdir" ]; then 1.187 +defaultIFS=' 1.188 + ' 1.189 +IFS="${IFS-$defaultIFS}" 1.190 + 1.191 +oIFS=$IFS 1.192 +# Some sh's can't handle IFS=/ for some reason. 1.193 +IFS='%' 1.194 +set - `echo "$dstdir" | sed -e 's@/@%@g' -e 's@^%@/@'` 1.195 +IFS=$oIFS 1.196 + 1.197 +pathcomp='' 1.198 + 1.199 +while [ $# -ne 0 ] ; do 1.200 + pathcomp=$pathcomp$1 1.201 + shift 1.202 + 1.203 + if [ ! -d "$pathcomp" ] ; 1.204 + then 1.205 + $mkdirprog "$pathcomp" 1.206 + else 1.207 + : 1.208 + fi 1.209 + 1.210 + pathcomp=$pathcomp/ 1.211 +done 1.212 +fi 1.213 + 1.214 +if [ x"$dir_arg" != x ] 1.215 +then 1.216 + $doit $instcmd "$dst" && 1.217 + 1.218 + if [ x"$chowncmd" != x ]; then $doit $chowncmd "$dst"; else : ; fi && 1.219 + if [ x"$chgrpcmd" != x ]; then $doit $chgrpcmd "$dst"; else : ; fi && 1.220 + if [ x"$stripcmd" != x ]; then $doit $stripcmd "$dst"; else : ; fi && 1.221 + if [ x"$chmodcmd" != x ]; then $doit $chmodcmd "$dst"; else : ; fi 1.222 +else 1.223 + 1.224 +# If we're going to rename the final executable, determine the name now. 1.225 + 1.226 + if [ x"$transformarg" = x ] 1.227 + then 1.228 + dstfile=`basename "$dst"` 1.229 + else 1.230 + dstfile=`basename "$dst" $transformbasename | 1.231 + sed $transformarg`$transformbasename 1.232 + fi 1.233 + 1.234 +# don't allow the sed command to completely eliminate the filename 1.235 + 1.236 + if [ x"$dstfile" = x ] 1.237 + then 1.238 + dstfile=`basename "$dst"` 1.239 + else 1.240 + : 1.241 + fi 1.242 + 1.243 +# Make a couple of temp file names in the proper directory. 1.244 + 1.245 + dsttmp=$dstdir/_inst.$$_ 1.246 + rmtmp=$dstdir/_rm.$$_ 1.247 + 1.248 +# Trap to clean up temp files at exit. 1.249 + 1.250 + trap 'status=$?; rm -f "$dsttmp" "$rmtmp" && exit $status' 0 1.251 + trap '(exit $?); exit' 1 2 13 15 1.252 + 1.253 +# Move or copy the file name to the temp name 1.254 + 1.255 + $doit $instcmd "$src" "$dsttmp" && 1.256 + 1.257 +# and set any options; do chmod last to preserve setuid bits 1.258 + 1.259 +# If any of these fail, we abort the whole thing. If we want to 1.260 +# ignore errors from any of these, just make sure not to ignore 1.261 +# errors from the above "$doit $instcmd $src $dsttmp" command. 1.262 + 1.263 + if [ x"$chowncmd" != x ]; then $doit $chowncmd "$dsttmp"; else :;fi && 1.264 + if [ x"$chgrpcmd" != x ]; then $doit $chgrpcmd "$dsttmp"; else :;fi && 1.265 + if [ x"$stripcmd" != x ]; then $doit $stripcmd "$dsttmp"; else :;fi && 1.266 + if [ x"$chmodcmd" != x ]; then $doit $chmodcmd "$dsttmp"; else :;fi && 1.267 + 1.268 +# Now remove or move aside any old file at destination location. We try this 1.269 +# two ways since rm can't unlink itself on some systems and the destination 1.270 +# file might be busy for other reasons. In this case, the final cleanup 1.271 +# might fail but the new file should still install successfully. 1.272 + 1.273 +{ 1.274 + if [ -f "$dstdir/$dstfile" ] 1.275 + then 1.276 + $doit $rmcmd -f "$dstdir/$dstfile" 2>/dev/null || 1.277 + $doit $mvcmd -f "$dstdir/$dstfile" "$rmtmp" 2>/dev/null || 1.278 + { 1.279 + echo "$0: cannot unlink or rename $dstdir/$dstfile" >&2 1.280 + (exit 1); exit 1.281 + } 1.282 + else 1.283 + : 1.284 + fi 1.285 +} && 1.286 + 1.287 +# Now rename the file to the real destination. 1.288 + 1.289 + $doit $mvcmd "$dsttmp" "$dstdir/$dstfile" 1.290 + 1.291 +fi && 1.292 + 1.293 +# The final little trick to "correctly" pass the exit status to the exit trap. 1.294 + 1.295 +{ 1.296 + (exit 0); exit 1.297 +}