/[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 4.0 by kusanagi, Sun Mar 6 04:33: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
4    #
 scriptversion=2004-02-15.20  
   
5  # This originates from X11R5 (mit/util/scripts/install.sh), which was  # This originates from X11R5 (mit/util/scripts/install.sh), which was
6  # later released in X11R6 (xc/config/util/install.sh) with the  # later released in X11R6 (xc/config/util/install.sh) with the
7  # following copyright and license.  # following copyright and license.
# Line 42  scriptversion=2004-02-15.20 Line 41  scriptversion=2004-02-15.20
41  # 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
42  # shared with many OS's install programs.  # shared with many OS's install programs.
43    
44    
45  # set DOITPROG to echo to test this script  # set DOITPROG to echo to test this script
46    
47  # 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.
48  doit="${DOITPROG-}"  doit="${DOITPROG-}"
49    
50    
51  # 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.
52    
53  mvprog="${MVPROG-mv}"  mvprog="${MVPROG-mv}"
# Line 58  stripprog="${STRIPPROG-strip}" Line 59  stripprog="${STRIPPROG-strip}"
59  rmprog="${RMPROG-rm}"  rmprog="${RMPROG-rm}"
60  mkdirprog="${MKDIRPROG-mkdir}"  mkdirprog="${MKDIRPROG-mkdir}"
61    
62  transformbasename=  transformbasename=""
63  transform_arg=  transform_arg=""
64  instcmd="$mvprog"  instcmd="$mvprog"
65  chmodcmd="$chmodprog 0755"  chmodcmd="$chmodprog 0755"
66  chowncmd=  chowncmd=""
67  chgrpcmd=  chgrpcmd=""
68  stripcmd=  stripcmd=""
69  rmcmd="$rmprog -f"  rmcmd="$rmprog -f"
70  mvcmd="$mvprog"  mvcmd="$mvprog"
71  src=  src=""
72  dst=  dst=""
73  dir_arg=  dir_arg=""
74    
75  usage="Usage: $0 [OPTION]... SRCFILE DSTFILE  while [ x"$1" != x ]; do
76     or: $0 [OPTION]... SRCFILES... DIRECTORY      case $1 in
77     or: $0 -d DIRECTORIES...          -c) instcmd=$cpprog
78                shift
79  In the first form, install SRCFILE to DSTFILE, removing SRCFILE by default.              continue;;
80  In the second, create the directory path DIR.  
81            -d) dir_arg=true
82  Options:              shift
83  -b=TRANSFORMBASENAME              continue;;
84  -c         copy source (using $cpprog) instead of moving (using $mvprog).  
85  -d         create directories instead of installing files.          -m) chmodcmd="$chmodprog $2"
86  -g GROUP   $chgrp installed files to GROUP.              shift
87  -m MODE    $chmod installed files to MODE.              shift
88  -o USER    $chown installed files to USER.              continue;;
89  -s         strip installed files (using $stripprog).  
90  -t=TRANSFORM          -o) chowncmd="$chownprog $2"
91  --help     display this help and exit.              shift
92  --version  display version info and exit.              shift
93                continue;;
94  Environment variables override the default commands:  
95    CHGRPPROG CHMODPROG CHOWNPROG CPPROG MKDIRPROG MVPROG RMPROG STRIPPROG          -g) chgrpcmd="$chgrpprog $2"
96  "              shift
97                shift
98  while test -n "$1"; do              continue;;
99    case $1 in  
100      -b=*) transformbasename=`echo $1 | sed 's/-b=//'`          -s) stripcmd=$stripprog
101          shift              shift
102          continue;;              continue;;
103    
104      -c) instcmd=$cpprog          -t=*) transformarg=`echo $1 | sed 's/-t=//'`
105          shift              shift
106          continue;;              continue;;
107    
108      -d) dir_arg=true          -b=*) transformbasename=`echo $1 | sed 's/-b=//'`
109          shift              shift
110          continue;;              continue;;
111    
112      -g) chgrpcmd="$chgrpprog $2"          *)  if [ x"$src" = x ]
113          shift              then
114          shift                  src=$1
115          continue;;              else
116                    # this colon is to work around a 386BSD /bin/sh bug
117      --help) echo "$usage"; exit 0;;                  :
118                    dst=$1
119      -m) chmodcmd="$chmodprog $2"              fi
120          shift              shift
121          shift              continue;;
122          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  
123  done  done
124    
125  if test -z "$1"; then  if [ x"$src" = x ]
126    if test -z "$dir_arg"; then  then
127      echo "$0: no input file specified." >&2          echo "$0: no input file specified" >&2
128      exit 1          exit 1
129    fi  else
130    # It's OK to call `install-sh -d' without argument.          :
   # This can happen when creating conditional directories.  
   exit 0  
131  fi  fi
132    
133  for src  if [ x"$dir_arg" != x ]; then
134  do          dst=$src
135    # Protect names starting with `-'.          src=""
136    case $src in  
137      -*) src=./$src ;;          if [ -d "$dst" ]; then
138    esac                  instcmd=:
139                    chmodcmd=""
140    if test -n "$dir_arg"; then          else
141      dst=$src                  instcmd=$mkdirprog
142      src=          fi
143    else
144      if test -d "$dst"; then  
145        instcmd=:  # Waiting for this to be detected by the "$instcmd $src $dsttmp" command
146        chmodcmd=  # might cause directories to be created, which would be especially bad
147      else  # if $src (and thus $dsttmp) contains '*'.
148        instcmd=$mkdirprog  
149      fi          if [ -f "$src" ] || [ -d "$src" ]
150    else          then
151      # Waiting for this to be detected by the "$instcmd $src $dsttmp" command                  :
152      # might cause directories to be created, which would be especially bad          else
153      # if $src (and thus $dsttmp) contains '*'.                  echo "$0: $src does not exist" >&2
154      if test ! -f "$src" && test ! -d "$src"; then                  exit 1
155        echo "$0: $src does not exist." >&2          fi
156        exit 1  
157      fi          if [ x"$dst" = x ]
158            then
159      if test -z "$dstarg"; then                  echo "$0: no destination specified" >&2
160        echo "$0: no destination specified." >&2                  exit 1
161        exit 1          else
162      fi                  :
163            fi
164      dst=$dstarg  
165      # Protect names starting with `-'.  # If destination is a directory, append the input filename; if your system
166      case $dst in  # does not like double slashes in filenames, you may need to add some logic
167        -*) dst=./$dst ;;  
168      esac          if [ -d "$dst" ]
169            then
170                    dst=$dst/`basename "$src"`
171            else
172                    :
173            fi
174    fi
175    
176      # If destination is a directory, append the input filename; won't work  ## this sed command emulates the dirname command
177      # if double slashes aren't ignored.  dstdir=`echo "$dst" | sed -e 's,[^/]*$,,;s,/$,,;s,^$,.,'`
178      if test -d "$dst"; then  
179        dst=$dst/`basename "$src"`  # Make sure that the destination directory exists.
180      fi  #  this part is taken from Noah Friedman's mkinstalldirs script
181    fi  
182    # Skip lots of stat calls in the usual case.
183    # This sed command emulates the dirname command.  if [ ! -d "$dstdir" ]; then
184    dstdir=`echo "$dst" | sed -e 's,[^/]*$,,;s,/$,,;s,^$,.,'`  defaultIFS='
185            '
186    # Make sure that the destination directory exists.  IFS="${IFS-$defaultIFS}"
187    
188    # Skip lots of stat calls in the usual case.  oIFS=$IFS
189    if test ! -d "$dstdir"; then  # Some sh's can't handle IFS=/ for some reason.
190      defaultIFS='  IFS='%'
191           '  set - `echo "$dstdir" | sed -e 's@/@%@g' -e 's@^%@/@'`
192      IFS="${IFS-$defaultIFS}"  IFS=$oIFS
193    
194      oIFS=$IFS  pathcomp=''
195      # Some sh's can't handle IFS=/ for some reason.  
196      IFS='%'  while [ $# -ne 0 ] ; do
197      set - `echo "$dstdir" | sed -e 's@/@%@g' -e 's@^%@/@'`          pathcomp=$pathcomp$1
198      IFS=$oIFS          shift
199    
200      pathcomp=          if [ ! -d "$pathcomp" ] ;
201            then
202      while test $# -ne 0 ; do                  $mkdirprog "$pathcomp"
203        pathcomp=$pathcomp$1          else
204        shift                  :
205        if test ! -d "$pathcomp"; then          fi
206          $mkdirprog "$pathcomp" || lasterr=$?  
207          # mkdir can fail with a `File exist' error in case several          pathcomp=$pathcomp/
         # 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; }  
208  done  done
209    fi
210    
211    if [ x"$dir_arg" != x ]
212    then
213            $doit $instcmd "$dst" &&
214    
215            if [ x"$chowncmd" != x ]; then $doit $chowncmd "$dst"; else : ; fi &&
216            if [ x"$chgrpcmd" != x ]; then $doit $chgrpcmd "$dst"; else : ; fi &&
217            if [ x"$stripcmd" != x ]; then $doit $stripcmd "$dst"; else : ; fi &&
218            if [ x"$chmodcmd" != x ]; then $doit $chmodcmd "$dst"; else : ; fi
219    else
220    
221    # If we're going to rename the final executable, determine the name now.
222    
223            if [ x"$transformarg" = x ]
224            then
225                    dstfile=`basename "$dst"`
226            else
227                    dstfile=`basename "$dst" $transformbasename |
228                            sed $transformarg`$transformbasename
229            fi
230    
231    # don't allow the sed command to completely eliminate the filename
232    
233            if [ x"$dstfile" = x ]
234            then
235                    dstfile=`basename "$dst"`
236            else
237                    :
238            fi
239    
240    # Make a couple of temp file names in the proper directory.
241    
242            dsttmp=$dstdir/_inst.$$_
243            rmtmp=$dstdir/_rm.$$_
244    
245    # Trap to clean up temp files at exit.
246    
247            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            $doit $instcmd "$src" "$dsttmp" &&
253    
254    # and set any options; do chmod last to preserve setuid bits
255    
256    # If any of these fail, we abort the whole thing.  If we want to
257    # ignore errors from any of these, just make sure not to ignore
258    # errors from the above "$doit $instcmd $src $dsttmp" command.
259    
260            if [ x"$chowncmd" != x ]; then $doit $chowncmd "$dsttmp"; else :;fi &&
261            if [ x"$chgrpcmd" != x ]; then $doit $chgrpcmd "$dsttmp"; else :;fi &&
262            if [ x"$stripcmd" != x ]; then $doit $stripcmd "$dsttmp"; else :;fi &&
263            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.
285    
286            $doit $mvcmd "$dsttmp" "$dstdir/$dstfile"
287    
288    fi &&
289    
290  # The final little trick to "correctly" pass the exit status to the exit trap.  # The final little trick to "correctly" pass the exit status to the exit trap.
291    
292  {  {
293    (exit 0); exit          (exit 0); exit
294  }  }
   
 # 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.4.0

  ViewVC Help
Powered by ViewVC 1.1.23