home *** CD-ROM | disk | FTP | other *** search
/ Source Code 1992 March / Source_Code_CD-ROM_Walnut_Creek_March_1992.iso / usenet / altsrcs / 2 / 2912 / install.SH < prev    next >
Encoding:
Text File  |  1991-03-03  |  3.1 KB  |  196 lines

  1. case $CONFIG in
  2. '')
  3.     if test ! -f config.sh; then
  4.     ln ../config.sh . || \
  5.     ln ../../config.sh . || \
  6.     ln ../../../config.sh . || \
  7.     (echo "Can't find config.sh."; exit 1)
  8.     fi
  9.     . config.sh
  10.     ;;
  11. esac
  12. case "$0" in
  13. */*) cd `expr X$0 : 'X\(.*\)/'` ;;
  14. esac
  15. echo "Extracting install (with variable substitutions)"
  16. $spitshell >install <<!GROK!THIS!
  17. $startsh
  18. # @(#) Installing script accepting bsd-style arguments
  19. # Derived from a script found in the X11R4 distribution.
  20.  
  21. # $Id: install.SH,v 2.0 91/02/19 15:49:42 ram Exp $
  22. #
  23. # $Log:    install.SH,v $
  24. # Revision 2.0  91/02/19  15:49:42  ram
  25. # Baseline for first official release.
  26.  
  27. chown='$chown'
  28. chmod='$chmod'
  29. chgrp='$chgrp'
  30. !GROK!THIS!
  31. $spitshell >>install <<'!NO!SUBS!'
  32.  
  33. mode=""
  34. dst=""
  35. src=""
  36. dostrip=""
  37. newdir=""
  38. uid=""
  39. gid=""
  40.  
  41. mkdir_p()
  42. {
  43.     # recursively called to build a path (simulates the BSD `mkdir -p')
  44.     # Bourne shell cannot handle recursive functions -- use subshells
  45.  
  46.     (
  47.         name=$1
  48.         if test ! -d $name
  49.         then
  50.             mkdir_p `dirname $name`
  51.             mkdir $name
  52.             echo "install: created directory $name" >&2
  53.         fi
  54.     )
  55. }
  56.  
  57. while test x$1 != x
  58. do
  59.     case $1 in 
  60.     -c) shift
  61.         continue
  62.         ;;
  63.     -m) mode="$2 "
  64.         shift
  65.         shift
  66.         continue
  67.         ;;
  68.     -o) uid="$2 "
  69.         shift
  70.         shift
  71.         continue
  72.         ;;
  73.     -g) gid="$2 "
  74.         shift
  75.         shift
  76.         continue
  77.         ;;
  78.     -s) dostrip="strip"
  79.         shift
  80.         continue
  81.         ;;
  82.     -d) newdir="$newdir$2 "
  83.         shift
  84.         shift
  85.         continue
  86.         ;;
  87.     *) if test x$src = x
  88.         then
  89.             src=$1
  90.         else
  91.             dst=$1
  92.         fi
  93.         shift
  94.         continue
  95.         ;;
  96.     esac
  97. done
  98.  
  99. # if -d option is used, we have to create the path given
  100. # mkdir -p may not exist, so do it by hand
  101. if test ! x$newdir = x
  102. then
  103.     for i in $newdir
  104.     do
  105.         mkdir_p $i
  106.     done
  107.     exit 0        # -d is the only action
  108. fi
  109.  
  110. if test x$src = x
  111. then
  112.     echo "install:  no input file specified" >&2
  113.     exit 1
  114. fi
  115.  
  116. if test x$dst = x
  117. then
  118.     echo "install:  no destination specified" >&2
  119.     exit 1
  120. fi
  121.  
  122. # Set up some variable to be used later
  123. rmcmd=""
  124. srcdir="."
  125.  
  126. # In case we are interrupted
  127. trap "$rmcmd ; exit 1" 1 2 3 15
  128.  
  129. # If the destination isn't a directory we'll need to copy it first
  130. if test ! -d $dst
  131. then
  132.     dstbase=`basename $dst`
  133.     cp $src /tmp/$dstbase
  134.     rmcmd="rm -f /tmp/$dstbase"
  135.     src=$dstbase
  136.     srcdir=/tmp
  137.     dst="`echo $dst | sed 's,^\(.*\)/.*$,\1,'`"
  138.     if test x$dst = x
  139.     then
  140.         dst="."
  141.     fi
  142. fi
  143.  
  144. # If the src file has a directory, copy it to /tmp to make install happy
  145. srcbase=`basename $src`
  146.  
  147. if test "$src" != "$srcbase" -a "$src" != "./$srcbase"
  148. then
  149.     cp $src /tmp/$srcbase
  150.     src=$srcbase
  151.     srcdir=/tmp
  152.     rmcmd="rm -f /tmp/$srcbase"
  153. fi
  154.  
  155. # Now start the install procedure
  156. (
  157.     cd $srcdir
  158.  
  159.     # first, copy the src to dst, renaming old version
  160.     if test -f $dst/$src
  161.     then
  162.         mv $dst/$src $dst/OLD$src &&
  163.         echo "install: $dst/$src renamed as OLD$src"
  164.     fi
  165.     cp $src $dst/$src &&
  166.     echo "install: $src installed as $dst/$src"
  167.  
  168.     # Alter mode
  169.     if test ! x$uid = x
  170.     then
  171.         $chown $uid $dst/$src
  172.     fi
  173.     if test ! x$gid = x
  174.     then
  175.         $chgrp $gid $dst/$src
  176.     fi
  177.     if test ! x$mode = x
  178.     then
  179.         $chmod $mode $dst/$src
  180.     fi
  181.  
  182.     # strip dest if necessary
  183.     if test ! x$dostrip = x
  184.     then
  185.         echo "install: stripping $dst/$src"
  186.         strip $dst/$src
  187.     fi
  188. )
  189.  
  190. # And clean up
  191. $rmcmd
  192. !NO!SUBS!
  193. chmod 755 install
  194. $eunicefix install
  195.