/[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.2 by kusanagi, Tue Jul 20 13:04:50 2004 UTC revision 5.0 by kusanagi, Mon Aug 29 09:45:01 2005 UTC
# Line 1  Line 1 
1  #!/bin/sh  #!/bin/sh
2  #  #
3  # install - install a program, script, or datafile  # install - install a program, script, or datafile
 # This comes from X11R5 (mit/util/scripts/install.sh).  
4  #  #
5  # Copyright 1991 by the Massachusetts Institute of Technology  # This originates from X11R5 (mit/util/scripts/install.sh), which was
6    # later released in X11R6 (xc/config/util/install.sh) with the
7    # following copyright and license.
8  #  #
9  # Permission to use, copy, modify, distribute, and sell this software and its  # Copyright (C) 1994 X Consortium
10  # documentation for any purpose is hereby granted without fee, provided that  #
11  # the above copyright notice appear in all copies and that both that  # Permission is hereby granted, free of charge, to any person obtaining a copy
12  # copyright notice and this permission notice appear in supporting  # of this software and associated documentation files (the "Software"), to
13  # documentation, and that the name of M.I.T. not be used in advertising or  # deal in the Software without restriction, including without limitation the
14  # publicity pertaining to distribution of the software without specific,  # rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
15  # written prior permission.  M.I.T. makes no representations about the  # sell copies of the Software, and to permit persons to whom the Software is
16  # suitability of this software for any purpose.  It is provided "as is"  # furnished to do so, subject to the following conditions:
17  # without express or implied warranty.  #
18    # The above copyright notice and this permission notice shall be included in
19    # all copies or substantial portions of the Software.
20    #
21    # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
22    # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
23    # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
24    # X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
25    # AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNEC-
26    # TION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
27    #
28    # Except as contained in this notice, the name of the X Consortium shall not
29    # be used in advertising or otherwise to promote the sale, use or other deal-
30    # ings in this Software without prior written authorization from the X Consor-
31    # tium.
32    #
33    #
34    # FSF changes to this file are in the public domain.
35  #  #
36  # Calling this script install-sh is preferred over install.sh, to prevent  # Calling this script install-sh is preferred over install.sh, to prevent
37  # `make' implicit rules from creating a file called install from it  # `make' implicit rules from creating a file called install from it
# Line 56  dir_arg="" Line 74  dir_arg=""
74    
75  while [ x"$1" != x ]; do  while [ x"$1" != x ]; do
76      case $1 in      case $1 in
77          -c) instcmd="$cpprog"          -c) instcmd=$cpprog
78              shift              shift
79              continue;;              continue;;
80    
# Line 79  while [ x"$1" != x ]; do Line 97  while [ x"$1" != x ]; do
97              shift              shift
98              continue;;              continue;;
99    
100          -s) stripcmd="$stripprog"          -s) stripcmd=$stripprog
101              shift              shift
102              continue;;              continue;;
103    
# Line 106  done Line 124  done
124    
125  if [ x"$src" = x ]  if [ x"$src" = x ]
126  then  then
127          echo "install:  no input file specified"          echo "$0: no input file specified" >&2
128          exit 1          exit 1
129  else  else
130          true          :
131  fi  fi
132    
133  if [ x"$dir_arg" != x ]; then  if [ x"$dir_arg" != x ]; then
134          dst=$src          dst=$src
135          src=""          src=""
136            
137          if [ -d $dst ]; then          if [ -d "$dst" ]; then
138                  instcmd=:                  instcmd=:
139                  chmodcmd=""                  chmodcmd=""
140          else          else
141                  instcmd=mkdir                  instcmd=$mkdirprog
142          fi          fi
143  else  else
144    
145  # Waiting for this to be detected by the "$instcmd $src $dsttmp" command  # Waiting for this to be detected by the "$instcmd $src $dsttmp" command
146  # might cause directories to be created, which would be especially bad  # might cause directories to be created, which would be especially bad
147  # if $src (and thus $dsttmp) contains '*'.  # if $src (and thus $dsttmp) contains '*'.
148    
149          if [ -f $src -o -d $src ]          if [ -f "$src" ] || [ -d "$src" ]
150          then          then
151                  true                  :
152          else          else
153                  echo "install:  $src does not exist"                  echo "$0: $src does not exist" >&2
154                  exit 1                  exit 1
155          fi          fi
156            
157          if [ x"$dst" = x ]          if [ x"$dst" = x ]
158          then          then
159                  echo "install:  no destination specified"                  echo "$0: no destination specified" >&2
160                  exit 1                  exit 1
161          else          else
162                  true                  :
163          fi          fi
164    
165  # If destination is a directory, append the input filename; if your system  # If destination is a directory, append the input filename; if your system
166  # does not like double slashes in filenames, you may need to add some logic  # does not like double slashes in filenames, you may need to add some logic
167    
168          if [ -d $dst ]          if [ -d "$dst" ]
169          then          then
170                  dst="$dst"/`basename $src`                  dst=$dst/`basename "$src"`
171          else          else
172                  true                  :
173          fi          fi
174  fi  fi
175    
176  ## this sed command emulates the dirname command  ## this sed command emulates the dirname command
177  dstdir=`echo $dst | sed -e 's,[^/]*$,,;s,/$,,;s,^$,.,'`  dstdir=`echo "$dst" | sed -e 's,[^/]*$,,;s,/$,,;s,^$,.,'`
178    
179  # Make sure that the destination directory exists.  # Make sure that the destination directory exists.
180  #  this part is taken from Noah Friedman's mkinstalldirs script  #  this part is taken from Noah Friedman's mkinstalldirs script
181    
182  # Skip lots of stat calls in the usual case.  # Skip lots of stat calls in the usual case.
183  if [ ! -d "$dstdir" ]; then  if [ ! -d "$dstdir" ]; then
184  defaultIFS='      defaultIFS='
185  '          '
186  IFS="${IFS-${defaultIFS}}"  IFS="${IFS-$defaultIFS}"
187    
188  oIFS="${IFS}"  oIFS=$IFS
189  # Some sh's can't handle IFS=/ for some reason.  # Some sh's can't handle IFS=/ for some reason.
190  IFS='%'  IFS='%'
191  set - `echo ${dstdir} | sed -e 's@/@%@g' -e 's@^%@/@'`  set - `echo "$dstdir" | sed -e 's@/@%@g' -e 's@^%@/@'`
192  IFS="${oIFS}"  IFS=$oIFS
193    
194  pathcomp=''  pathcomp=''
195    
196  while [ $# -ne 0 ] ; do  while [ $# -ne 0 ] ; do
197          pathcomp="${pathcomp}${1}"          pathcomp=$pathcomp$1
198          shift          shift
199    
200          if [ ! -d "${pathcomp}" ] ;          if [ ! -d "$pathcomp" ] ;
201          then          then
202                  $mkdirprog "${pathcomp}"                  $mkdirprog "$pathcomp"
203          else          else
204                  true                  :
205          fi          fi
206    
207          pathcomp="${pathcomp}/"          pathcomp=$pathcomp/
208  done  done
209  fi  fi
210    
211  if [ x"$dir_arg" != x ]  if [ x"$dir_arg" != x ]
212  then  then
213          $doit $instcmd $dst &&          $doit $instcmd "$dst" &&
214    
215          if [ x"$chowncmd" != x ]; then $doit $chowncmd $dst; else true ; fi &&          if [ x"$chowncmd" != x ]; then $doit $chowncmd "$dst"; else : ; fi &&
216          if [ x"$chgrpcmd" != x ]; then $doit $chgrpcmd $dst; else true ; fi &&          if [ x"$chgrpcmd" != x ]; then $doit $chgrpcmd "$dst"; else : ; fi &&
217          if [ x"$stripcmd" != x ]; then $doit $stripcmd $dst; else true ; fi &&          if [ x"$stripcmd" != x ]; then $doit $stripcmd "$dst"; else : ; fi &&
218          if [ x"$chmodcmd" != x ]; then $doit $chmodcmd $dst; else true ; fi          if [ x"$chmodcmd" != x ]; then $doit $chmodcmd "$dst"; else : ; fi
219  else  else
220    
221  # If we're going to rename the final executable, determine the name now.  # If we're going to rename the final executable, determine the name now.
222    
223          if [ x"$transformarg" = x ]          if [ x"$transformarg" = x ]
224          then          then
225                  dstfile=`basename $dst`                  dstfile=`basename "$dst"`
226          else          else
227                  dstfile=`basename $dst $transformbasename |                  dstfile=`basename "$dst" $transformbasename |
228                          sed $transformarg`$transformbasename                          sed $transformarg`$transformbasename
229          fi          fi
230    
231  # don't allow the sed command to completely eliminate the filename  # don't allow the sed command to completely eliminate the filename
232    
233          if [ x"$dstfile" = x ]          if [ x"$dstfile" = x ]
234          then          then
235                  dstfile=`basename $dst`                  dstfile=`basename "$dst"`
236          else          else
237                  true                  :
238          fi          fi
239    
240  # Make a temp file name in the proper directory.  # Make a couple of temp file names in the proper directory.
241    
242          dsttmp=$dstdir/#inst.$$#          dsttmp=$dstdir/_inst.$$_
243            rmtmp=$dstdir/_rm.$$_
244    
245  # Move or copy the file name to the temp name  # Trap to clean up temp files at exit.
246    
247          $doit $instcmd $src $dsttmp &&          trap 'status=$?; rm -f "$dsttmp" "$rmtmp" && exit $status' 0
248            trap '(exit $?); exit' 1 2 13 15
249    
250    # Move or copy the file name to the temp name
251    
252          trap "rm -f ${dsttmp}" 0 &&          $doit $instcmd "$src" "$dsttmp" &&
253    
254  # and set any options; do chmod last to preserve setuid bits  # and set any options; do chmod last to preserve setuid bits
255    
# Line 235  else Line 257  else
257  # ignore errors from any of these, just make sure not to ignore  # ignore errors from any of these, just make sure not to ignore
258  # errors from the above "$doit $instcmd $src $dsttmp" command.  # errors from the above "$doit $instcmd $src $dsttmp" command.
259    
260          if [ x"$chowncmd" != x ]; then $doit $chowncmd $dsttmp; else true;fi &&          if [ x"$chowncmd" != x ]; then $doit $chowncmd "$dsttmp"; else :;fi &&
261          if [ x"$chgrpcmd" != x ]; then $doit $chgrpcmd $dsttmp; else true;fi &&          if [ x"$chgrpcmd" != x ]; then $doit $chgrpcmd "$dsttmp"; else :;fi &&
262          if [ x"$stripcmd" != x ]; then $doit $stripcmd $dsttmp; else true;fi &&          if [ x"$stripcmd" != x ]; then $doit $stripcmd "$dsttmp"; else :;fi &&
263          if [ x"$chmodcmd" != x ]; then $doit $chmodcmd $dsttmp; else true;fi &&          if [ x"$chmodcmd" != x ]; then $doit $chmodcmd "$dsttmp"; else :;fi &&
264    
265    # Now remove or move aside any old file at destination location.  We try this
266    # two ways since rm can't unlink itself on some systems and the destination
267    # file might be busy for other reasons.  In this case, the final cleanup
268    # might fail but the new file should still install successfully.
269    
270    {
271            if [ -f "$dstdir/$dstfile" ]
272            then
273                    $doit $rmcmd -f "$dstdir/$dstfile" 2>/dev/null ||
274                    $doit $mvcmd -f "$dstdir/$dstfile" "$rmtmp" 2>/dev/null ||
275                    {
276                      echo "$0: cannot unlink or rename $dstdir/$dstfile" >&2
277                      (exit 1); exit
278                    }
279            else
280                    :
281            fi
282    } &&
283    
284  # Now rename the file to the real destination.  # Now rename the file to the real destination.
285    
286          $doit $rmcmd -f $dstdir/$dstfile &&          $doit $mvcmd "$dsttmp" "$dstdir/$dstfile"
         $doit $mvcmd $dsttmp $dstdir/$dstfile  
287    
288  fi &&  fi &&
289    
290    # The final little trick to "correctly" pass the exit status to the exit trap.
291    
292  exit 0  {
293            (exit 0); exit
294    }

Legend:
Removed from v.1.2  
changed lines
  Added in v.5.0

  ViewVC Help
Powered by ViewVC 1.1.23