Back to home page

MITgcm

 
 

    


Warning, /tools/mpack-1.6/install-sh is written in an unsupported language. File is not indexed.

view on githubraw file Latest commit ec6cf3b0 on 2003-08-26 20:45:25 UTC
ec6cf3b09d Ed H*0001 #!/bin/sh
                0002 #
                0003 # install - install a program, script, or datafile
                0004 # This comes from X11R5 (mit/util/scripts/install.sh).
                0005 #
                0006 # Copyright 1991 by the Massachusetts Institute of Technology
                0007 #
                0008 # Permission to use, copy, modify, distribute, and sell this software and its
                0009 # documentation for any purpose is hereby granted without fee, provided that
                0010 # the above copyright notice appear in all copies and that both that
                0011 # copyright notice and this permission notice appear in supporting
                0012 # documentation, and that the name of M.I.T. not be used in advertising or
                0013 # publicity pertaining to distribution of the software without specific,
                0014 # written prior permission.  M.I.T. makes no representations about the
                0015 # suitability of this software for any purpose.  It is provided "as is"
                0016 # without express or implied warranty.
                0017 #
                0018 # Calling this script install-sh is preferred over install.sh, to prevent
                0019 # `make' implicit rules from creating a file called install from it
                0020 # when there is no Makefile.
                0021 #
                0022 # This script is compatible with the BSD install script, but was written
                0023 # from scratch.  It can only install one file at a time, a restriction
                0024 # shared with many OS's install programs.
                0025 
                0026 
                0027 # set DOITPROG to echo to test this script
                0028 
                0029 # Don't use :- since 4.3BSD and earlier shells don't like it.
                0030 doit="${DOITPROG-}"
                0031 
                0032 
                0033 # put in absolute paths if you don't have them in your path; or use env. vars.
                0034 
                0035 mvprog="${MVPROG-mv}"
                0036 cpprog="${CPPROG-cp}"
                0037 chmodprog="${CHMODPROG-chmod}"
                0038 chownprog="${CHOWNPROG-chown}"
                0039 chgrpprog="${CHGRPPROG-chgrp}"
                0040 stripprog="${STRIPPROG-strip}"
                0041 rmprog="${RMPROG-rm}"
                0042 mkdirprog="${MKDIRPROG-mkdir}"
                0043 
                0044 transformbasename=""
                0045 transform_arg=""
                0046 instcmd="$mvprog"
                0047 chmodcmd="$chmodprog 0755"
                0048 chowncmd=""
                0049 chgrpcmd=""
                0050 stripcmd=""
                0051 rmcmd="$rmprog -f"
                0052 mvcmd="$mvprog"
                0053 src=""
                0054 dst=""
                0055 dir_arg=""
                0056 
                0057 while [ x"$1" != x ]; do
                0058     case $1 in
                0059         -c) instcmd="$cpprog"
                0060             shift
                0061             continue;;
                0062 
                0063         -d) dir_arg=true
                0064             shift
                0065             continue;;
                0066 
                0067         -m) chmodcmd="$chmodprog $2"
                0068             shift
                0069             shift
                0070             continue;;
                0071 
                0072         -o) chowncmd="$chownprog $2"
                0073             shift
                0074             shift
                0075             continue;;
                0076 
                0077         -g) chgrpcmd="$chgrpprog $2"
                0078             shift
                0079             shift
                0080             continue;;
                0081 
                0082         -s) stripcmd="$stripprog"
                0083             shift
                0084             continue;;
                0085 
                0086         -t=*) transformarg=`echo $1 | sed 's/-t=//'`
                0087             shift
                0088             continue;;
                0089 
                0090         -b=*) transformbasename=`echo $1 | sed 's/-b=//'`
                0091             shift
                0092             continue;;
                0093 
                0094         *)  if [ x"$src" = x ]
                0095             then
                0096                 src=$1
                0097             else
                0098                 # this colon is to work around a 386BSD /bin/sh bug
                0099                 :
                0100                 dst=$1
                0101             fi
                0102             shift
                0103             continue;;
                0104     esac
                0105 done
                0106 
                0107 if [ x"$src" = x ]
                0108 then
                0109         echo "install:  no input file specified"
                0110         exit 1
                0111 else
                0112         true
                0113 fi
                0114 
                0115 if [ x"$dir_arg" != x ]; then
                0116         dst=$src
                0117         src=""
                0118         
                0119         if [ -d $dst ]; then
                0120                 instcmd=:
                0121                 chmodcmd=""
                0122         else
                0123                 instcmd=mkdir
                0124         fi
                0125 else
                0126 
                0127 # Waiting for this to be detected by the "$instcmd $src $dsttmp" command
                0128 # might cause directories to be created, which would be especially bad 
                0129 # if $src (and thus $dsttmp) contains '*'.
                0130 
                0131         if [ -f $src -o -d $src ]
                0132         then
                0133                 true
                0134         else
                0135                 echo "install:  $src does not exist"
                0136                 exit 1
                0137         fi
                0138         
                0139         if [ x"$dst" = x ]
                0140         then
                0141                 echo "install:  no destination specified"
                0142                 exit 1
                0143         else
                0144                 true
                0145         fi
                0146 
                0147 # If destination is a directory, append the input filename; if your system
                0148 # does not like double slashes in filenames, you may need to add some logic
                0149 
                0150         if [ -d $dst ]
                0151         then
                0152                 dst="$dst"/`basename $src`
                0153         else
                0154                 true
                0155         fi
                0156 fi
                0157 
                0158 ## this sed command emulates the dirname command
                0159 dstdir=`echo $dst | sed -e 's,[^/]*$,,;s,/$,,;s,^$,.,'`
                0160 
                0161 # Make sure that the destination directory exists.
                0162 #  this part is taken from Noah Friedman's mkinstalldirs script
                0163 
                0164 # Skip lots of stat calls in the usual case.
                0165 if [ ! -d "$dstdir" ]; then
                0166 defaultIFS='    
                0167 '
                0168 IFS="${IFS-${defaultIFS}}"
                0169 
                0170 oIFS="${IFS}"
                0171 # Some sh's can't handle IFS=/ for some reason.
                0172 IFS='%'
                0173 set - `echo ${dstdir} | sed -e 's@/@%@g' -e 's@^%@/@'`
                0174 IFS="${oIFS}"
                0175 
                0176 pathcomp=''
                0177 
                0178 while [ $# -ne 0 ] ; do
                0179         pathcomp="${pathcomp}${1}"
                0180         shift
                0181 
                0182         if [ ! -d "${pathcomp}" ] ;
                0183         then
                0184                 $mkdirprog "${pathcomp}"
                0185         else
                0186                 true
                0187         fi
                0188 
                0189         pathcomp="${pathcomp}/"
                0190 done
                0191 fi
                0192 
                0193 if [ x"$dir_arg" != x ]
                0194 then
                0195         $doit $instcmd $dst &&
                0196 
                0197         if [ x"$chowncmd" != x ]; then $doit $chowncmd $dst; else true ; fi &&
                0198         if [ x"$chgrpcmd" != x ]; then $doit $chgrpcmd $dst; else true ; fi &&
                0199         if [ x"$stripcmd" != x ]; then $doit $stripcmd $dst; else true ; fi &&
                0200         if [ x"$chmodcmd" != x ]; then $doit $chmodcmd $dst; else true ; fi
                0201 else
                0202 
                0203 # If we're going to rename the final executable, determine the name now.
                0204 
                0205         if [ x"$transformarg" = x ] 
                0206         then
                0207                 dstfile=`basename $dst`
                0208         else
                0209                 dstfile=`basename $dst $transformbasename | 
                0210                         sed $transformarg`$transformbasename
                0211         fi
                0212 
                0213 # don't allow the sed command to completely eliminate the filename
                0214 
                0215         if [ x"$dstfile" = x ] 
                0216         then
                0217                 dstfile=`basename $dst`
                0218         else
                0219                 true
                0220         fi
                0221 
                0222 # Make a temp file name in the proper directory.
                0223 
                0224         dsttmp=$dstdir/#inst.$$#
                0225 
                0226 # Move or copy the file name to the temp name
                0227 
                0228         $doit $instcmd $src $dsttmp &&
                0229 
                0230         trap "rm -f ${dsttmp}" 0 &&
                0231 
                0232 # and set any options; do chmod last to preserve setuid bits
                0233 
                0234 # If any of these fail, we abort the whole thing.  If we want to
                0235 # ignore errors from any of these, just make sure not to ignore
                0236 # errors from the above "$doit $instcmd $src $dsttmp" command.
                0237 
                0238         if [ x"$chowncmd" != x ]; then $doit $chowncmd $dsttmp; else true;fi &&
                0239         if [ x"$chgrpcmd" != x ]; then $doit $chgrpcmd $dsttmp; else true;fi &&
                0240         if [ x"$stripcmd" != x ]; then $doit $stripcmd $dsttmp; else true;fi &&
                0241         if [ x"$chmodcmd" != x ]; then $doit $chmodcmd $dsttmp; else true;fi &&
                0242 
                0243 # Now rename the file to the real destination.
                0244 
                0245         $doit $rmcmd -f $dstdir/$dstfile &&
                0246         $doit $mvcmd $dsttmp $dstdir/$dstfile 
                0247 
                0248 fi &&
                0249 
                0250 
                0251 exit 0