Main Page   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members  

install-sh

00001 #!/bin/sh
00002 #
00003 # install - install a program, script, or datafile
00004 # This comes from X11R5 (mit/util/scripts/install.sh).
00005 #
00006 # Copyright 1991 by the Massachusetts Institute of Technology
00007 #
00008 # Permission to use, copy, modify, distribute, and sell this software and its
00009 # documentation for any purpose is hereby granted without fee, provided that
00010 # the above copyright notice appear in all copies and that both that
00011 # copyright notice and this permission notice appear in supporting
00012 # documentation, and that the name of M.I.T. not be used in advertising or
00013 # publicity pertaining to distribution of the software without specific,
00014 # written prior permission.  M.I.T. makes no representations about the
00015 # suitability of this software for any purpose.  It is provided "as is"
00016 # without express or implied warranty.
00017 #
00018 # Calling this script install-sh is preferred over install.sh, to prevent
00019 # `make' implicit rules from creating a file called install from it
00020 # when there is no Makefile.
00021 #
00022 # This script is compatible with the BSD install script, but was written
00023 # from scratch.  It can only install one file at a time, a restriction
00024 # shared with many OS's install programs.
00025 
00026 
00027 # set DOITPROG to echo to test this script
00028 
00029 # Don't use :- since 4.3BSD and earlier shells don't like it.
00030 doit="${DOITPROG-}"
00031 
00032 
00033 # put in absolute paths if you don't have them in your path; or use env. vars.
00034 
00035 mvprog="${MVPROG-mv}"
00036 cpprog="${CPPROG-cp}"
00037 chmodprog="${CHMODPROG-chmod}"
00038 chownprog="${CHOWNPROG-chown}"
00039 chgrpprog="${CHGRPPROG-chgrp}"
00040 stripprog="${STRIPPROG-strip}"
00041 rmprog="${RMPROG-rm}"
00042 mkdirprog="${MKDIRPROG-mkdir}"
00043 
00044 transformbasename=""
00045 transform_arg=""
00046 instcmd="$mvprog"
00047 chmodcmd="$chmodprog 0755"
00048 chowncmd=""
00049 chgrpcmd=""
00050 stripcmd=""
00051 rmcmd="$rmprog -f"
00052 mvcmd="$mvprog"
00053 src=""
00054 dst=""
00055 dir_arg=""
00056 
00057 while [ x"$1" != x ]; do
00058     case $1 in
00059         -c) instcmd="$cpprog"
00060             shift
00061             continue;;
00062 
00063         -d) dir_arg=true
00064             shift
00065             continue;;
00066 
00067         -m) chmodcmd="$chmodprog $2"
00068             shift
00069             shift
00070             continue;;
00071 
00072         -o) chowncmd="$chownprog $2"
00073             shift
00074             shift
00075             continue;;
00076 
00077         -g) chgrpcmd="$chgrpprog $2"
00078             shift
00079             shift
00080             continue;;
00081 
00082         -s) stripcmd="$stripprog"
00083             shift
00084             continue;;
00085 
00086         -t=*) transformarg=`echo $1 | sed 's/-t=//'`
00087             shift
00088             continue;;
00089 
00090         -b=*) transformbasename=`echo $1 | sed 's/-b=//'`
00091             shift
00092             continue;;
00093 
00094         *)  if [ x"$src" = x ]
00095             then
00096                 src=$1
00097             else
00098                 # this colon is to work around a 386BSD /bin/sh bug
00099                 :
00100                 dst=$1
00101             fi
00102             shift
00103             continue;;
00104     esac
00105 done
00106 
00107 if [ x"$src" = x ]
00108 then
00109         echo "install:  no input file specified"
00110         exit 1
00111 else
00112         true
00113 fi
00114 
00115 if [ x"$dir_arg" != x ]; then
00116         dst=$src
00117         src=""
00118         
00119         if [ -d $dst ]; then
00120                 instcmd=:
00121                 chmodcmd=""
00122         else
00123                 instcmd=mkdir
00124         fi
00125 else
00126 
00127 # Waiting for this to be detected by the "$instcmd $src $dsttmp" command
00128 # might cause directories to be created, which would be especially bad 
00129 # if $src (and thus $dsttmp) contains '*'.
00130 
00131         if [ -f $src -o -d $src ]
00132         then
00133                 true
00134         else
00135                 echo "install:  $src does not exist"
00136                 exit 1
00137         fi
00138         
00139         if [ x"$dst" = x ]
00140         then
00141                 echo "install:  no destination specified"
00142                 exit 1
00143         else
00144                 true
00145         fi
00146 
00147 # If destination is a directory, append the input filename; if your system
00148 # does not like double slashes in filenames, you may need to add some logic
00149 
00150         if [ -d $dst ]
00151         then
00152                 dst="$dst"/`basename $src`
00153         else
00154                 true
00155         fi
00156 fi
00157 
00158 ## this sed command emulates the dirname command
00159 dstdir=`echo $dst | sed -e 's,[^/]*$,,;s,/$,,;s,^$,.,'`
00160 
00161 # Make sure that the destination directory exists.
00162 #  this part is taken from Noah Friedman's mkinstalldirs script
00163 
00164 # Skip lots of stat calls in the usual case.
00165 if [ ! -d "$dstdir" ]; then
00166 defaultIFS='    
00167 '
00168 IFS="${IFS-${defaultIFS}}"
00169 
00170 oIFS="${IFS}"
00171 # Some sh's can't handle IFS=/ for some reason.
00172 IFS='%'
00173 set - `echo ${dstdir} | sed -e 's@/@%@g' -e 's@^%@/@'`
00174 IFS="${oIFS}"
00175 
00176 pathcomp=''
00177 
00178 while [ $# -ne 0 ] ; do
00179         pathcomp="${pathcomp}${1}"
00180         shift
00181 
00182         if [ ! -d "${pathcomp}" ] ;
00183         then
00184                 $mkdirprog "${pathcomp}"
00185         else
00186                 true
00187         fi
00188 
00189         pathcomp="${pathcomp}/"
00190 done
00191 fi
00192 
00193 if [ x"$dir_arg" != x ]
00194 then
00195         $doit $instcmd $dst &&
00196 
00197         if [ x"$chowncmd" != x ]; then $doit $chowncmd $dst; else true ; fi &&
00198         if [ x"$chgrpcmd" != x ]; then $doit $chgrpcmd $dst; else true ; fi &&
00199         if [ x"$stripcmd" != x ]; then $doit $stripcmd $dst; else true ; fi &&
00200         if [ x"$chmodcmd" != x ]; then $doit $chmodcmd $dst; else true ; fi
00201 else
00202 
00203 # If we're going to rename the final executable, determine the name now.
00204 
00205         if [ x"$transformarg" = x ] 
00206         then
00207                 dstfile=`basename $dst`
00208         else
00209                 dstfile=`basename $dst $transformbasename | 
00210                         sed $transformarg`$transformbasename
00211         fi
00212 
00213 # don't allow the sed command to completely eliminate the filename
00214 
00215         if [ x"$dstfile" = x ] 
00216         then
00217                 dstfile=`basename $dst`
00218         else
00219                 true
00220         fi
00221 
00222 # Make a temp file name in the proper directory.
00223 
00224         dsttmp=$dstdir/#inst.$$#
00225 
00226 # Move or copy the file name to the temp name
00227 
00228         $doit $instcmd $src $dsttmp &&
00229 
00230         trap "rm -f ${dsttmp}" 0 &&
00231 
00232 # and set any options; do chmod last to preserve setuid bits
00233 
00234 # If any of these fail, we abort the whole thing.  If we want to
00235 # ignore errors from any of these, just make sure not to ignore
00236 # errors from the above "$doit $instcmd $src $dsttmp" command.
00237 
00238         if [ x"$chowncmd" != x ]; then $doit $chowncmd $dsttmp; else true;fi &&
00239         if [ x"$chgrpcmd" != x ]; then $doit $chgrpcmd $dsttmp; else true;fi &&
00240         if [ x"$stripcmd" != x ]; then $doit $stripcmd $dsttmp; else true;fi &&
00241         if [ x"$chmodcmd" != x ]; then $doit $chmodcmd $dsttmp; else true;fi &&
00242 
00243 # Now rename the file to the real destination.
00244 
00245         $doit $rmcmd -f $dstdir/$dstfile &&
00246         $doit $mvcmd $dsttmp $dstdir/$dstfile 
00247 
00248 fi &&
00249 
00250 exit 0

Generated at Tue Dec 5 10:47:46 2000 for ICU by doxygen1.2.3 written by Dimitri van Heesch, © 1997-2000