home *** CD-ROM | disk | FTP | other *** search
/ linuxmafia.com 2016 / linuxmafia.com.tar / linuxmafia.com / pub / linux / backup / star-1.3.1.tar.gz / star-1.3.1.tar / star-1.3.1 / conf / install-sh < prev    next >
Text File  |  2001-04-03  |  7KB  |  285 lines

  1. #! /bin/sh
  2. #
  3. # @(#)install-sh    1.5 01/04/03 1999 J. Schilling
  4. #
  5. # install - install a program, script, or datafile
  6. # This comes from X11R5 (mit/util/scripts/install.sh).
  7. # Mods to make install-sh behave reasonable when called by
  8. # non root user by J. Schilling
  9. #
  10. # Copyright 1991 by the Massachusetts Institute of Technology
  11. # Copyright 1999 by J. Schilling
  12. #
  13. # Permission to use, copy, modify, distribute, and sell this software and its
  14. # documentation for any purpose is hereby granted without fee, provided that
  15. # the above copyright notice appear in all copies and that both that
  16. # copyright notice and this permission notice appear in supporting
  17. # documentation, and that the name of M.I.T. not be used in advertising or
  18. # publicity pertaining to distribution of the software without specific,
  19. # written prior permission.  M.I.T. makes no representations about the
  20. # suitability of this software for any purpose.  It is provided "as is"
  21. # without express or implied warranty.
  22. #
  23. # Calling this script install-sh is preferred over install.sh, to prevent
  24. # `make' implicit rules from creating a file called install from it
  25. # when there is no Makefile.
  26. #
  27. # This script is compatible with the BSD install script, but was written
  28. # from scratch.  It can only install one file at a time, a restriction
  29. # shared with many OS's install programs.
  30.  
  31.  
  32. # set DOITPROG to echo to test this script
  33.  
  34. # Don't use :- since 4.3BSD and earlier shells don't like it.
  35. doit="${DOITPROG-}"
  36.  
  37.  
  38. # put in absolute paths if you don't have them in your path; or use env. vars.
  39.  
  40. mvprog="${MVPROG-mv}"
  41. cpprog="${CPPROG-cp}"
  42. chmodprog="${CHMODPROG-chmod}"
  43. chownprog="${CHOWNPROG-chown}"
  44. chgrpprog="${CHGRPPROG-chgrp}"
  45. stripprog="${STRIPPROG-strip}"
  46. rmprog="${RMPROG-rm}"
  47. mkdirprog="${MKDIRPROG-mkdir}"
  48.  
  49. transformbasename=""
  50. transform_arg=""
  51. instcmd="$mvprog"
  52. chmodcmd="$chmodprog 0755"
  53. chowncmd=""
  54. chgrpcmd=""
  55. stripcmd=""
  56. rmcmd="$rmprog -f"
  57. mvcmd="$mvprog"
  58. src=""
  59. dst=""
  60. dir_arg=""
  61.  
  62. #
  63. # Check if we are 'root' to avoid chown as non root user
  64. #
  65. rootflag=FALSE
  66. dsttmp=/tmp/xx.$$
  67. trap "rm -f ${dsttmp}" 0
  68. echo > ${dsttmp}
  69. ${chownprog} root ${dsttmp} 2> /dev/null && ${chmodcmd} ${dsttmp} 2> /dev/null && rootflag=TRUE
  70. #
  71. # Win95 has no user 'root' and chown succeeds always.
  72. # Unfortunately, there is also no user 'bin' and chown complains about
  73. # user 'bin' being non-existant.
  74. # Check if the fie is now really owned by 'root' to avoid the Win95 probems
  75. #
  76. if [ $rootflag = TRUE ]; then
  77.     ls -l ${dsttmp} 2> /dev/null | grep root > /dev/null || rootflag=FALSE
  78. fi
  79. rm -f ${dsttmp}
  80.  
  81. while [ x"$1" != x ]; do
  82.     case $1 in
  83.     -c) instcmd="$cpprog"
  84.         shift
  85.         continue;;
  86.  
  87.     -d) dir_arg=true
  88.         shift
  89.         continue;;
  90.  
  91.     -m) chmodcmd="$chmodprog $2"
  92.         shift
  93.         shift
  94.         continue;;
  95.  
  96.     -o) if [ $rootflag = TRUE ]
  97.         then
  98.         chowncmd="$chownprog $2"
  99.         else
  100.         echo "install: -o option available only to root -- ignored"
  101.         fi
  102.         shift
  103.         shift
  104.         continue;;
  105.  
  106.     -g) if [ $rootflag = TRUE ]
  107.         then
  108.         chgrpcmd="$chgrpprog $2"
  109.         else
  110.         echo "install: -g option available only to root -- ignored"
  111.         fi
  112.         shift
  113.         shift
  114.         continue;;
  115.  
  116.     -s) stripcmd="$stripprog"
  117.         shift
  118.         continue;;
  119.  
  120.     -t=*) transformarg=`echo $1 | sed 's/-t=//'`
  121.         shift
  122.         continue;;
  123.  
  124.     -b=*) transformbasename=`echo $1 | sed 's/-b=//'`
  125.         shift
  126.         continue;;
  127.  
  128.     *)  if [ x"$src" = x ]
  129.         then
  130.         src=$1
  131.         else
  132.         # this colon is to work around a 386BSD /bin/sh bug
  133.         :
  134.         dst=$1
  135.         fi
  136.         shift
  137.         continue;;
  138.     esac
  139. done
  140.  
  141. if [ x"$src" = x ]
  142. then
  143.     echo "install:    no input file specified"
  144.     exit 1
  145. else
  146.     true
  147. fi
  148.  
  149. if [ x"$dir_arg" != x ]; then
  150.     dst=$src
  151.     src=""
  152.     
  153.     if [ -d $dst ]; then
  154.         instcmd=:
  155.     else
  156.         instcmd=mkdir
  157.     fi
  158. else
  159.  
  160. # Waiting for this to be detected by the "$instcmd $src $dsttmp" command
  161. # might cause directories to be created, which would be especially bad 
  162. # if $src (and thus $dsttmp) contains '*'.
  163.  
  164.     if [ -f $src -o -d $src ]
  165.     then
  166.         true
  167.     else
  168.         echo "install:  $src does not exist"
  169.         exit 1
  170.     fi
  171.     
  172.     if [ x"$dst" = x ]
  173.     then
  174.         echo "install:    no destination specified"
  175.         exit 1
  176.     else
  177.         true
  178.     fi
  179.  
  180. # If destination is a directory, append the input filename; if your system
  181. # does not like double slashes in filenames, you may need to add some logic
  182.  
  183.     if [ -d $dst ]
  184.     then
  185.         dst="$dst"/`basename $src`
  186.     else
  187.         true
  188.     fi
  189. fi
  190.  
  191. ## this sed command emulates the dirname command
  192. dstdir=`echo $dst | sed -e 's,[^/]*$,,;s,/$,,;s,^$,.,'`
  193.  
  194. # Make sure that the destination directory exists.
  195. #  this part is taken from Noah Friedman's mkinstalldirs script
  196.  
  197. # Skip lots of stat calls in the usual case.
  198. if [ ! -d "$dstdir" ]; then
  199. defaultIFS='    
  200. '
  201. IFS="${IFS-${defaultIFS}}"
  202.  
  203. oIFS="${IFS}"
  204. # Some sh's can't handle IFS=/ for some reason.
  205. IFS='%'
  206. set - `echo ${dstdir} | sed -e 's@/@%@g' -e 's@^%@/@'`
  207. IFS="${oIFS}"
  208.  
  209. pathcomp=''
  210.  
  211. while [ $# -ne 0 ] ; do
  212.     pathcomp="${pathcomp}${1}"
  213.     shift
  214.  
  215.     if [ ! -d "${pathcomp}" ] ;
  216.         then
  217.         $mkdirprog "${pathcomp}"
  218.     else
  219.         true
  220.     fi
  221.  
  222.     pathcomp="${pathcomp}/"
  223. done
  224. fi
  225.  
  226. if [ x"$dir_arg" != x ]
  227. then
  228.     $doit $instcmd $dst &&
  229.  
  230.     if [ x"$chowncmd" != x ]; then $doit $chowncmd $dst; else true ; fi &&
  231.     if [ x"$chgrpcmd" != x ]; then $doit $chgrpcmd $dst; else true ; fi &&
  232.     if [ x"$stripcmd" != x ]; then $doit $stripcmd $dst; else true ; fi &&
  233.     if [ x"$chmodcmd" != x ]; then $doit $chmodcmd $dst; else true ; fi
  234. else
  235.  
  236. # If we're going to rename the final executable, determine the name now.
  237.  
  238.     if [ x"$transformarg" = x ] 
  239.     then
  240.         dstfile=`basename $dst`
  241.     else
  242.         dstfile=`basename $dst $transformbasename | 
  243.             sed $transformarg`$transformbasename
  244.     fi
  245.  
  246. # don't allow the sed command to completely eliminate the filename
  247.  
  248.     if [ x"$dstfile" = x ] 
  249.     then
  250.         dstfile=`basename $dst`
  251.     else
  252.         true
  253.     fi
  254.  
  255. # Make a temp file name in the proper directory.
  256.  
  257.     dsttmp=$dstdir/#inst.$$#
  258.  
  259. # Move or copy the file name to the temp name
  260.  
  261.     $doit $instcmd $src $dsttmp &&
  262.  
  263.     trap "rm -f ${dsttmp}" 0 &&
  264.  
  265. # and set any options; do chmod last to preserve setuid bits
  266.  
  267. # If any of these fail, we abort the whole thing.  If we want to
  268. # ignore errors from any of these, just make sure not to ignore
  269. # errors from the above "$doit $instcmd $src $dsttmp" command.
  270.  
  271.     if [ x"$chowncmd" != x ]; then $doit $chowncmd $dsttmp; else true;fi &&
  272.     if [ x"$chgrpcmd" != x ]; then $doit $chgrpcmd $dsttmp; else true;fi &&
  273.     if [ x"$stripcmd" != x ]; then $doit $stripcmd $dsttmp; else true;fi &&
  274.     if [ x"$chmodcmd" != x ]; then $doit $chmodcmd $dsttmp; else true;fi &&
  275.  
  276. # Now rename the file to the real destination.
  277.  
  278.     $doit $rmcmd -f $dstdir/$dstfile &&
  279.     $doit $mvcmd $dsttmp $dstdir/$dstfile 
  280.  
  281. fi &&
  282.  
  283.  
  284. exit 0
  285.