masqmail
diff install-sh @ 0:08114f7dcc23
this is masqmail-0.2.21 from oliver kurth
author | meillo@marmaro.de |
---|---|
date | Fri, 26 Sep 2008 17:05:23 +0200 |
parents | |
children |
line diff
1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/install-sh Fri Sep 26 17:05:23 2008 +0200 1.3 @@ -0,0 +1,251 @@ 1.4 +#!/bin/sh 1.5 +# 1.6 +# install - install a program, script, or datafile 1.7 +# This comes from X11R5 (mit/util/scripts/install.sh). 1.8 +# 1.9 +# Copyright 1991 by the Massachusetts Institute of Technology 1.10 +# 1.11 +# Permission to use, copy, modify, distribute, and sell this software and its 1.12 +# documentation for any purpose is hereby granted without fee, provided that 1.13 +# the above copyright notice appear in all copies and that both that 1.14 +# copyright notice and this permission notice appear in supporting 1.15 +# documentation, and that the name of M.I.T. not be used in advertising or 1.16 +# publicity pertaining to distribution of the software without specific, 1.17 +# written prior permission. M.I.T. makes no representations about the 1.18 +# suitability of this software for any purpose. It is provided "as is" 1.19 +# without express or implied warranty. 1.20 +# 1.21 +# Calling this script install-sh is preferred over install.sh, to prevent 1.22 +# `make' implicit rules from creating a file called install from it 1.23 +# when there is no Makefile. 1.24 +# 1.25 +# This script is compatible with the BSD install script, but was written 1.26 +# from scratch. It can only install one file at a time, a restriction 1.27 +# shared with many OS's install programs. 1.28 + 1.29 + 1.30 +# set DOITPROG to echo to test this script 1.31 + 1.32 +# Don't use :- since 4.3BSD and earlier shells don't like it. 1.33 +doit="${DOITPROG-}" 1.34 + 1.35 + 1.36 +# put in absolute paths if you don't have them in your path; or use env. vars. 1.37 + 1.38 +mvprog="${MVPROG-mv}" 1.39 +cpprog="${CPPROG-cp}" 1.40 +chmodprog="${CHMODPROG-chmod}" 1.41 +chownprog="${CHOWNPROG-chown}" 1.42 +chgrpprog="${CHGRPPROG-chgrp}" 1.43 +stripprog="${STRIPPROG-strip}" 1.44 +rmprog="${RMPROG-rm}" 1.45 +mkdirprog="${MKDIRPROG-mkdir}" 1.46 + 1.47 +transformbasename="" 1.48 +transform_arg="" 1.49 +instcmd="$mvprog" 1.50 +chmodcmd="$chmodprog 0755" 1.51 +chowncmd="" 1.52 +chgrpcmd="" 1.53 +stripcmd="" 1.54 +rmcmd="$rmprog -f" 1.55 +mvcmd="$mvprog" 1.56 +src="" 1.57 +dst="" 1.58 +dir_arg="" 1.59 + 1.60 +while [ x"$1" != x ]; do 1.61 + case $1 in 1.62 + -c) instcmd="$cpprog" 1.63 + shift 1.64 + continue;; 1.65 + 1.66 + -d) dir_arg=true 1.67 + shift 1.68 + continue;; 1.69 + 1.70 + -m) chmodcmd="$chmodprog $2" 1.71 + shift 1.72 + shift 1.73 + continue;; 1.74 + 1.75 + -o) chowncmd="$chownprog $2" 1.76 + shift 1.77 + shift 1.78 + continue;; 1.79 + 1.80 + -g) chgrpcmd="$chgrpprog $2" 1.81 + shift 1.82 + shift 1.83 + continue;; 1.84 + 1.85 + -s) stripcmd="$stripprog" 1.86 + shift 1.87 + continue;; 1.88 + 1.89 + -t=*) transformarg=`echo $1 | sed 's/-t=//'` 1.90 + shift 1.91 + continue;; 1.92 + 1.93 + -b=*) transformbasename=`echo $1 | sed 's/-b=//'` 1.94 + shift 1.95 + continue;; 1.96 + 1.97 + *) if [ x"$src" = x ] 1.98 + then 1.99 + src=$1 1.100 + else 1.101 + # this colon is to work around a 386BSD /bin/sh bug 1.102 + : 1.103 + dst=$1 1.104 + fi 1.105 + shift 1.106 + continue;; 1.107 + esac 1.108 +done 1.109 + 1.110 +if [ x"$src" = x ] 1.111 +then 1.112 + echo "install: no input file specified" 1.113 + exit 1 1.114 +else 1.115 + true 1.116 +fi 1.117 + 1.118 +if [ x"$dir_arg" != x ]; then 1.119 + dst=$src 1.120 + src="" 1.121 + 1.122 + if [ -d $dst ]; then 1.123 + instcmd=: 1.124 + chmodcmd="" 1.125 + else 1.126 + instcmd=mkdir 1.127 + fi 1.128 +else 1.129 + 1.130 +# Waiting for this to be detected by the "$instcmd $src $dsttmp" command 1.131 +# might cause directories to be created, which would be especially bad 1.132 +# if $src (and thus $dsttmp) contains '*'. 1.133 + 1.134 + if [ -f $src -o -d $src ] 1.135 + then 1.136 + true 1.137 + else 1.138 + echo "install: $src does not exist" 1.139 + exit 1 1.140 + fi 1.141 + 1.142 + if [ x"$dst" = x ] 1.143 + then 1.144 + echo "install: no destination specified" 1.145 + exit 1 1.146 + else 1.147 + true 1.148 + fi 1.149 + 1.150 +# If destination is a directory, append the input filename; if your system 1.151 +# does not like double slashes in filenames, you may need to add some logic 1.152 + 1.153 + if [ -d $dst ] 1.154 + then 1.155 + dst="$dst"/`basename $src` 1.156 + else 1.157 + true 1.158 + fi 1.159 +fi 1.160 + 1.161 +## this sed command emulates the dirname command 1.162 +dstdir=`echo $dst | sed -e 's,[^/]*$,,;s,/$,,;s,^$,.,'` 1.163 + 1.164 +# Make sure that the destination directory exists. 1.165 +# this part is taken from Noah Friedman's mkinstalldirs script 1.166 + 1.167 +# Skip lots of stat calls in the usual case. 1.168 +if [ ! -d "$dstdir" ]; then 1.169 +defaultIFS=' 1.170 +' 1.171 +IFS="${IFS-${defaultIFS}}" 1.172 + 1.173 +oIFS="${IFS}" 1.174 +# Some sh's can't handle IFS=/ for some reason. 1.175 +IFS='%' 1.176 +set - `echo ${dstdir} | sed -e 's@/@%@g' -e 's@^%@/@'` 1.177 +IFS="${oIFS}" 1.178 + 1.179 +pathcomp='' 1.180 + 1.181 +while [ $# -ne 0 ] ; do 1.182 + pathcomp="${pathcomp}${1}" 1.183 + shift 1.184 + 1.185 + if [ ! -d "${pathcomp}" ] ; 1.186 + then 1.187 + $mkdirprog "${pathcomp}" 1.188 + else 1.189 + true 1.190 + fi 1.191 + 1.192 + pathcomp="${pathcomp}/" 1.193 +done 1.194 +fi 1.195 + 1.196 +if [ x"$dir_arg" != x ] 1.197 +then 1.198 + $doit $instcmd $dst && 1.199 + 1.200 + if [ x"$chowncmd" != x ]; then $doit $chowncmd $dst; else true ; fi && 1.201 + if [ x"$chgrpcmd" != x ]; then $doit $chgrpcmd $dst; else true ; fi && 1.202 + if [ x"$stripcmd" != x ]; then $doit $stripcmd $dst; else true ; fi && 1.203 + if [ x"$chmodcmd" != x ]; then $doit $chmodcmd $dst; else true ; fi 1.204 +else 1.205 + 1.206 +# If we're going to rename the final executable, determine the name now. 1.207 + 1.208 + if [ x"$transformarg" = x ] 1.209 + then 1.210 + dstfile=`basename $dst` 1.211 + else 1.212 + dstfile=`basename $dst $transformbasename | 1.213 + sed $transformarg`$transformbasename 1.214 + fi 1.215 + 1.216 +# don't allow the sed command to completely eliminate the filename 1.217 + 1.218 + if [ x"$dstfile" = x ] 1.219 + then 1.220 + dstfile=`basename $dst` 1.221 + else 1.222 + true 1.223 + fi 1.224 + 1.225 +# Make a temp file name in the proper directory. 1.226 + 1.227 + dsttmp=$dstdir/#inst.$$# 1.228 + 1.229 +# Move or copy the file name to the temp name 1.230 + 1.231 + $doit $instcmd $src $dsttmp && 1.232 + 1.233 + trap "rm -f ${dsttmp}" 0 && 1.234 + 1.235 +# and set any options; do chmod last to preserve setuid bits 1.236 + 1.237 +# If any of these fail, we abort the whole thing. If we want to 1.238 +# ignore errors from any of these, just make sure not to ignore 1.239 +# errors from the above "$doit $instcmd $src $dsttmp" command. 1.240 + 1.241 + if [ x"$chowncmd" != x ]; then $doit $chowncmd $dsttmp; else true;fi && 1.242 + if [ x"$chgrpcmd" != x ]; then $doit $chgrpcmd $dsttmp; else true;fi && 1.243 + if [ x"$stripcmd" != x ]; then $doit $stripcmd $dsttmp; else true;fi && 1.244 + if [ x"$chmodcmd" != x ]; then $doit $chmodcmd $dsttmp; else true;fi && 1.245 + 1.246 +# Now rename the file to the real destination. 1.247 + 1.248 + $doit $rmcmd -f $dstdir/$dstfile && 1.249 + $doit $mvcmd $dsttmp $dstdir/$dstfile 1.250 + 1.251 +fi && 1.252 + 1.253 + 1.254 +exit 0