/[PAMELA software]/yoda/install-sh
ViewVC logotype

Diff of /yoda/install-sh

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.1 by kusanagi, Tue Jul 6 12:20:23 2004 UTC revision 2.0 by kusanagi, Tue Sep 21 20:49:36 2004 UTC
# Line 1  Line 1 
1  #!/bin/sh  #!/bin/sh
 # install - install a program, script, or datafile  
   
 scriptversion=2004-02-15.20  
   
 # This originates from X11R5 (mit/util/scripts/install.sh), which was  
 # later released in X11R6 (xc/config/util/install.sh) with the  
 # following copyright and license.  
 #  
 # Copyright (C) 1994 X Consortium  
 #  
 # Permission is hereby granted, free of charge, to any person obtaining a copy  
 # of this software and associated documentation files (the "Software"), to  
 # deal in the Software without restriction, including without limitation the  
 # rights to use, copy, modify, merge, publish, distribute, sublicense, and/or  
 # sell copies of the Software, and to permit persons to whom the Software is  
 # furnished to do so, subject to the following conditions:  
2  #  #
3  # The above copyright notice and this permission notice shall be included in  # install - install a program, script, or datafile
4  # all copies or substantial portions of the Software.  # This comes from X11R5 (mit/util/scripts/install.sh).
 #  
 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR  
 # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,  
 # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE  
 # X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN  
 # AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNEC-  
 # TION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.  
 #  
 # Except as contained in this notice, the name of the X Consortium shall not  
 # be used in advertising or otherwise to promote the sale, use or other deal-  
 # ings in this Software without prior written authorization from the X Consor-  
 # tium.  
5  #  #
6    # Copyright 1991 by the Massachusetts Institute of Technology
7  #  #
8  # FSF changes to this file are in the public domain.  # Permission to use, copy, modify, distribute, and sell this software and its
9    # documentation for any purpose is hereby granted without fee, provided that
10    # the above copyright notice appear in all copies and that both that
11    # copyright notice and this permission notice appear in supporting
12    # documentation, and that the name of M.I.T. not be used in advertising or
13    # publicity pertaining to distribution of the software without specific,
14    # written prior permission.  M.I.T. makes no representations about the
15    # suitability of this software for any purpose.  It is provided "as is"
16    # without express or implied warranty.
17  #  #
18  # Calling this script install-sh is preferred over install.sh, to prevent  # Calling this script install-sh is preferred over install.sh, to prevent
19  # `make' implicit rules from creating a file called install from it  # `make' implicit rules from creating a file called install from it
# Line 42  scriptversion=2004-02-15.20 Line 23  scriptversion=2004-02-15.20
23  # from scratch.  It can only install one file at a time, a restriction  # from scratch.  It can only install one file at a time, a restriction
24  # shared with many OS's install programs.  # shared with many OS's install programs.
25    
26    
27  # set DOITPROG to echo to test this script  # set DOITPROG to echo to test this script
28    
29  # Don't use :- since 4.3BSD and earlier shells don't like it.  # Don't use :- since 4.3BSD and earlier shells don't like it.
30  doit="${DOITPROG-}"  doit="${DOITPROG-}"
31    
32    
33  # put in absolute paths if you don't have them in your path; or use env. vars.  # put in absolute paths if you don't have them in your path; or use env. vars.
34    
35  mvprog="${MVPROG-mv}"  mvprog="${MVPROG-mv}"
# Line 58  stripprog="${STRIPPROG-strip}" Line 41  stripprog="${STRIPPROG-strip}"
41  rmprog="${RMPROG-rm}"  rmprog="${RMPROG-rm}"
42  mkdirprog="${MKDIRPROG-mkdir}"  mkdirprog="${MKDIRPROG-mkdir}"
43    
44  transformbasename=  transformbasename=""
45  transform_arg=  transform_arg=""
46  instcmd="$mvprog"  instcmd="$mvprog"
47  chmodcmd="$chmodprog 0755"  chmodcmd="$chmodprog 0755"
48  chowncmd=  chowncmd=""
49  chgrpcmd=  chgrpcmd=""
50  stripcmd=  stripcmd=""
51  rmcmd="$rmprog -f"  rmcmd="$rmprog -f"
52  mvcmd="$mvprog"  mvcmd="$mvprog"
53  src=  src=""
54  dst=  dst=""
55  dir_arg=  dir_arg=""
56    
57  usage="Usage: $0 [OPTION]... SRCFILE DSTFILE  while [ x"$1" != x ]; do
58     or: $0 [OPTION]... SRCFILES... DIRECTORY      case $1 in
59     or: $0 -d DIRECTORIES...          -c) instcmd="$cpprog"
60                shift
61  In the first form, install SRCFILE to DSTFILE, removing SRCFILE by default.              continue;;
62  In the second, create the directory path DIR.  
63            -d) dir_arg=true
64  Options:              shift
65  -b=TRANSFORMBASENAME              continue;;
66  -c         copy source (using $cpprog) instead of moving (using $mvprog).  
67  -d         create directories instead of installing files.          -m) chmodcmd="$chmodprog $2"
68  -g GROUP   $chgrp installed files to GROUP.              shift
69  -m MODE    $chmod installed files to MODE.              shift
70  -o USER    $chown installed files to USER.              continue;;
71  -s         strip installed files (using $stripprog).  
72  -t=TRANSFORM          -o) chowncmd="$chownprog $2"
73  --help     display this help and exit.              shift
74  --version  display version info and exit.              shift
75                continue;;
76  Environment variables override the default commands:  
77    CHGRPPROG CHMODPROG CHOWNPROG CPPROG MKDIRPROG MVPROG RMPROG STRIPPROG          -g) chgrpcmd="$chgrpprog $2"
78  "              shift
79                shift
80  while test -n "$1"; do              continue;;
81    case $1 in  
82      -b=*) transformbasename=`echo $1 | sed 's/-b=//'`          -s) stripcmd="$stripprog"
83          shift              shift
84          continue;;              continue;;
85    
86      -c) instcmd=$cpprog          -t=*) transformarg=`echo $1 | sed 's/-t=//'`
87          shift              shift
88          continue;;              continue;;
89    
90      -d) dir_arg=true          -b=*) transformbasename=`echo $1 | sed 's/-b=//'`
91          shift              shift
92          continue;;              continue;;
93    
94      -g) chgrpcmd="$chgrpprog $2"          *)  if [ x"$src" = x ]
95          shift              then
96          shift                  src=$1
97          continue;;              else
98                    # this colon is to work around a 386BSD /bin/sh bug
99      --help) echo "$usage"; exit 0;;                  :
100                    dst=$1
101      -m) chmodcmd="$chmodprog $2"              fi
102          shift              shift
103          shift              continue;;
104          continue;;      esac
   
     -o) chowncmd="$chownprog $2"  
         shift  
         shift  
         continue;;  
   
     -s) stripcmd=$stripprog  
         shift  
         continue;;  
   
     -t=*) transformarg=`echo $1 | sed 's/-t=//'`  
         shift  
         continue;;  
   
     --version) echo "$0 $scriptversion"; exit 0;;  
   
     *)  # When -d is used, all remaining arguments are directories to create.  
         test -n "$dir_arg" && break  
         # Otherwise, the last argument is the destination.  Remove it from $@.  
         for arg  
         do  
           if test -n "$dstarg"; then  
             # $@ is not empty: it contains at least $arg.  
             set fnord "$@" "$dstarg"  
             shift # fnord  
           fi  
           shift # arg  
           dstarg=$arg  
         done  
         break;;  
   esac  
105  done  done
106    
107  if test -z "$1"; then  if [ x"$src" = x ]
108    if test -z "$dir_arg"; then  then
109      echo "$0: no input file specified." >&2          echo "install:  no input file specified"
110      exit 1          exit 1
111    fi  else
112    # It's OK to call `install-sh -d' without argument.          true
   # This can happen when creating conditional directories.  
   exit 0  
113  fi  fi
114    
115  for src  if [ x"$dir_arg" != x ]; then
116  do          dst=$src
117    # Protect names starting with `-'.          src=""
118    case $src in          
119      -*) src=./$src ;;          if [ -d $dst ]; then
120    esac                  instcmd=:
121                    chmodcmd=""
122    if test -n "$dir_arg"; then          else
123      dst=$src                  instcmd=mkdir
124      src=          fi
125    else
126      if test -d "$dst"; then  
127        instcmd=:  # Waiting for this to be detected by the "$instcmd $src $dsttmp" command
128        chmodcmd=  # might cause directories to be created, which would be especially bad
129      else  # if $src (and thus $dsttmp) contains '*'.
130        instcmd=$mkdirprog  
131      fi          if [ -f $src -o -d $src ]
132    else          then
133      # Waiting for this to be detected by the "$instcmd $src $dsttmp" command                  true
134      # might cause directories to be created, which would be especially bad          else
135      # if $src (and thus $dsttmp) contains '*'.                  echo "install:  $src does not exist"
136      if test ! -f "$src" && test ! -d "$src"; then                  exit 1
137        echo "$0: $src does not exist." >&2          fi
138        exit 1          
139      fi          if [ x"$dst" = x ]
140            then
141      if test -z "$dstarg"; then                  echo "install:  no destination specified"
142        echo "$0: no destination specified." >&2                  exit 1
143        exit 1          else
144      fi                  true
145            fi
146      dst=$dstarg  
147      # Protect names starting with `-'.  # If destination is a directory, append the input filename; if your system
148      case $dst in  # does not like double slashes in filenames, you may need to add some logic
149        -*) dst=./$dst ;;  
150      esac          if [ -d $dst ]
151            then
152                    dst="$dst"/`basename $src`
153            else
154                    true
155            fi
156    fi
157    
158    ## this sed command emulates the dirname command
159    dstdir=`echo $dst | sed -e 's,[^/]*$,,;s,/$,,;s,^$,.,'`
160    
161      # If destination is a directory, append the input filename; won't work  # Make sure that the destination directory exists.
162      # if double slashes aren't ignored.  #  this part is taken from Noah Friedman's mkinstalldirs script
163      if test -d "$dst"; then  
164        dst=$dst/`basename "$src"`  # Skip lots of stat calls in the usual case.
165      fi  if [ ! -d "$dstdir" ]; then
166    fi  defaultIFS='    
167    '
168    # This sed command emulates the dirname command.  IFS="${IFS-${defaultIFS}}"
169    dstdir=`echo "$dst" | sed -e 's,[^/]*$,,;s,/$,,;s,^$,.,'`  
170    oIFS="${IFS}"
171    # Make sure that the destination directory exists.  # Some sh's can't handle IFS=/ for some reason.
172    IFS='%'
173    # Skip lots of stat calls in the usual case.  set - `echo ${dstdir} | sed -e 's@/@%@g' -e 's@^%@/@'`
174    if test ! -d "$dstdir"; then  IFS="${oIFS}"
175      defaultIFS='  
176           '  pathcomp=''
177      IFS="${IFS-$defaultIFS}"  
178    while [ $# -ne 0 ] ; do
179      oIFS=$IFS          pathcomp="${pathcomp}${1}"
180      # Some sh's can't handle IFS=/ for some reason.          shift
181      IFS='%'  
182      set - `echo "$dstdir" | sed -e 's@/@%@g' -e 's@^%@/@'`          if [ ! -d "${pathcomp}" ] ;
183      IFS=$oIFS          then
184                    $mkdirprog "${pathcomp}"
185      pathcomp=          else
186                    true
187      while test $# -ne 0 ; do          fi
188        pathcomp=$pathcomp$1  
189        shift          pathcomp="${pathcomp}/"
       if test ! -d "$pathcomp"; then  
         $mkdirprog "$pathcomp" || lasterr=$?  
         # mkdir can fail with a `File exist' error in case several  
         # install-sh are creating the directory concurrently.  This  
         # is OK.  
         test ! -d "$pathcomp" && { (exit ${lasterr-1}); exit; }  
       fi  
       pathcomp=$pathcomp/  
     done  
   fi  
   
   if test -n "$dir_arg"; then  
     $doit $instcmd "$dst" \  
       && { test -z "$chowncmd" || $doit $chowncmd "$dst"; } \  
       && { test -z "$chgrpcmd" || $doit $chgrpcmd "$dst"; } \  
       && { test -z "$stripcmd" || $doit $stripcmd "$dst"; } \  
       && { test -z "$chmodcmd" || $doit $chmodcmd "$dst"; }  
   
   else  
     # If we're going to rename the final executable, determine the name now.  
     if test -z "$transformarg"; then  
       dstfile=`basename "$dst"`  
     else  
       dstfile=`basename "$dst" $transformbasename \  
                | sed $transformarg`$transformbasename  
     fi  
   
     # don't allow the sed command to completely eliminate the filename.  
     test -z "$dstfile" && dstfile=`basename "$dst"`  
   
     # Make a couple of temp file names in the proper directory.  
     dsttmp=$dstdir/_inst.$$_  
     rmtmp=$dstdir/_rm.$$_  
   
     # Trap to clean up those temp files at exit.  
     trap 'status=$?; rm -f "$dsttmp" "$rmtmp" && exit $status' 0  
     trap '(exit $?); exit' 1 2 13 15  
   
     # Move or copy the file name to the temp name  
     $doit $instcmd "$src" "$dsttmp" &&  
   
     # and set any options; do chmod last to preserve setuid bits.  
     #  
     # If any of these fail, we abort the whole thing.  If we want to  
     # ignore errors from any of these, just make sure not to ignore  
     # errors from the above "$doit $instcmd $src $dsttmp" command.  
     #  
     { test -z "$chowncmd" || $doit $chowncmd "$dsttmp"; } \  
       && { test -z "$chgrpcmd" || $doit $chgrpcmd "$dsttmp"; } \  
       && { test -z "$stripcmd" || $doit $stripcmd "$dsttmp"; } \  
       && { test -z "$chmodcmd" || $doit $chmodcmd "$dsttmp"; } &&  
   
     # Now remove or move aside any old file at destination location.  We  
     # try this two ways since rm can't unlink itself on some systems and  
     # the destination file might be busy for other reasons.  In this case,  
     # the final cleanup might fail but the new file should still install  
     # successfully.  
     {  
       if test -f "$dstdir/$dstfile"; then  
         $doit $rmcmd -f "$dstdir/$dstfile" 2>/dev/null \  
         || $doit $mvcmd -f "$dstdir/$dstfile" "$rmtmp" 2>/dev/null \  
         || {  
           echo "$0: cannot unlink or rename $dstdir/$dstfile" >&2  
           (exit 1); exit  
         }  
       else  
         :  
       fi  
     } &&  
   
     # Now rename the file to the real destination.  
     $doit $mvcmd "$dsttmp" "$dstdir/$dstfile"  
   fi || { (exit 1); exit; }  
190  done  done
191    fi
192    
193    if [ x"$dir_arg" != x ]
194    then
195            $doit $instcmd $dst &&
196    
197            if [ x"$chowncmd" != x ]; then $doit $chowncmd $dst; else true ; fi &&
198            if [ x"$chgrpcmd" != x ]; then $doit $chgrpcmd $dst; else true ; fi &&
199            if [ x"$stripcmd" != x ]; then $doit $stripcmd $dst; else true ; fi &&
200            if [ x"$chmodcmd" != x ]; then $doit $chmodcmd $dst; else true ; fi
201    else
202    
203    # If we're going to rename the final executable, determine the name now.
204    
205            if [ x"$transformarg" = x ]
206            then
207                    dstfile=`basename $dst`
208            else
209                    dstfile=`basename $dst $transformbasename |
210                            sed $transformarg`$transformbasename
211            fi
212    
213    # don't allow the sed command to completely eliminate the filename
214    
215            if [ x"$dstfile" = x ]
216            then
217                    dstfile=`basename $dst`
218            else
219                    true
220            fi
221    
222    # Make a temp file name in the proper directory.
223    
224            dsttmp=$dstdir/#inst.$$#
225    
226    # Move or copy the file name to the temp name
227    
228            $doit $instcmd $src $dsttmp &&
229    
230            trap "rm -f ${dsttmp}" 0 &&
231    
232    # and set any options; do chmod last to preserve setuid bits
233    
234    # If any of these fail, we abort the whole thing.  If we want to
235    # ignore errors from any of these, just make sure not to ignore
236    # errors from the above "$doit $instcmd $src $dsttmp" command.
237    
238            if [ x"$chowncmd" != x ]; then $doit $chowncmd $dsttmp; else true;fi &&
239            if [ x"$chgrpcmd" != x ]; then $doit $chgrpcmd $dsttmp; else true;fi &&
240            if [ x"$stripcmd" != x ]; then $doit $stripcmd $dsttmp; else true;fi &&
241            if [ x"$chmodcmd" != x ]; then $doit $chmodcmd $dsttmp; else true;fi &&
242    
243    # Now rename the file to the real destination.
244    
245            $doit $rmcmd -f $dstdir/$dstfile &&
246            $doit $mvcmd $dsttmp $dstdir/$dstfile
247    
248    fi &&
249    
250    
251  # The final little trick to "correctly" pass the exit status to the exit trap.  exit 0
 {  
   (exit 0); exit  
 }  
   
 # Local variables:  
 # eval: (add-hook 'write-file-hooks 'time-stamp)  
 # time-stamp-start: "scriptversion="  
 # time-stamp-format: "%:y-%02m-%02d.%02H"  
 # time-stamp-end: "$"  
 # End:  

Legend:
Removed from v.1.1  
changed lines
  Added in v.2.0

  ViewVC Help
Powered by ViewVC 1.1.23