home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #27 / NN_1992_27.iso / spool / comp / sources / misc / 4111 / install.SH
Encoding:
Text File  |  1992-11-20  |  3.5 KB  |  209 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 2>/dev/null
  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.  
  20. # $Id: install.SH,v 2.9 92/07/14 16:53:45 ram Exp $
  21. #
  22. #  Copyright (c) 1991, Raphael Manfredi
  23. #
  24. #  You may redistribute only under the terms of the GNU General Public
  25. #  Licence as specified in the README file that comes with dist.
  26. #
  27. # $Log:    install.SH,v $
  28. # Revision 2.9  92/07/14  16:53:45  ram
  29. # 3.0 beta baseline.
  30.  
  31. chown='$chown'
  32. chmod='$chmod'
  33. chgrp='$chgrp'
  34. rm='$rm'
  35. mv='$mv'
  36. test='$test'
  37. sed='$sed'
  38. !GROK!THIS!
  39. $spitshell >>install <<'!NO!SUBS!'
  40.  
  41. mode=""
  42. dst=""
  43. src=""
  44. dostrip=""
  45. newdir=""
  46. uid=""
  47. gid=""
  48.  
  49. # simulates mkdir -p
  50. mkdir_p='
  51. name=$1;
  52. create="";
  53. while $test $name; do
  54.     if $test ! -d "$name"; then
  55.         create="$name $create";
  56.         name=`echo $name | $sed -e "s|^[^/]*$||"`;
  57.         name=`echo $name | $sed -e "s|\(.*\)/.*|\1|"`;
  58.     else
  59.         name="";
  60.     fi;
  61. done;
  62. for file in $create; do
  63.     mkdir $file && $test $verbose &&
  64.     echo "install: created directory $file" >&2;
  65. done
  66. '
  67.  
  68. verbose=''
  69.  
  70. while $test x$1 != x
  71. do
  72.     case $1 in 
  73.     -c) shift
  74.         continue
  75.         ;;
  76.     -m) mode="$2 "
  77.         shift
  78.         shift
  79.         continue
  80.         ;;
  81.     -o) uid="$2 "
  82.         shift
  83.         shift
  84.         continue
  85.         ;;
  86.     -g) gid="$2 "
  87.         shift
  88.         shift
  89.         continue
  90.         ;;
  91.     -s) dostrip="strip"
  92.         shift
  93.         continue
  94.         ;;
  95.     -d) newdir="$newdir$2 "
  96.         shift
  97.         shift
  98.         continue
  99.         ;;
  100.     -v) verbose='true'
  101.         shift
  102.         ;;
  103.     *) if $test x$src = x
  104.         then
  105.             src=$1
  106.         else
  107.             dst=$1
  108.         fi
  109.         shift
  110.         continue
  111.         ;;
  112.     esac
  113. done
  114.  
  115. # if -d option is used, we have to create the path given
  116. if $test ! x$newdir = x
  117. then
  118.     for i in $newdir
  119.     do
  120.         set x $i
  121.         shift
  122.         eval $mkdir_p
  123.     done
  124.     exit 0        # -d is the only action
  125. fi
  126.  
  127. if $test x$src = x
  128. then
  129.     echo "install: no input file specified" >&2
  130.     exit 1
  131. fi
  132.  
  133. if $test x$dst = x
  134. then
  135.     echo "install: no destination specified" >&2
  136.     exit 1
  137. fi
  138.  
  139. srcbase=`basename $src`
  140. dstbase=`basename $dst`
  141.  
  142. # If the destination is a directory, the target name is srcbase...
  143. if $test -d $dst; then
  144.     dstbase=$srcbase
  145. else
  146.     dst="`echo $dst | sed 's,^\(.*\)/.*$,\1,'`"
  147.     if $test ! -d $dst; then
  148.         dstbase=$dst
  149.         dst="."
  150.     fi
  151. fi
  152.  
  153. # If the src has a directory, extract the dir name...
  154. if $test "$src" != "$srcbase" -a "$src" != "./$srcbase"; then
  155.     src="`echo $src | sed 's,^\(.*\)/.*$,\1,'`"
  156. else
  157.     src="."
  158. fi
  159.  
  160. # dst is the destination directory and dstbase the base name.
  161. # srcbase is the base name of source and src the source dir.
  162.  
  163. srcpth=`(cd $src; pwd)`/$srcbase
  164. destpth=`(cd $dst; pwd)`/$dstbase
  165. if $test x$srcpth = x$destpth; then
  166.     $test $verbose && \
  167.     echo "install: destination and source are identical"
  168.     exit 0
  169. fi
  170.  
  171. # Do the install
  172. (
  173.     cd $src
  174.  
  175.     if $test -f $dst/$dstbase; then
  176.         $rm -f $dst/$dstbase && $test $verbose &&
  177.         echo "install: $dst/$dstbase removed"
  178.     fi
  179.     if $test -f $dst/$dstbase; then
  180.         $mv $dst/$dstbase $dst/OLD$dstbase && $test $verbose &&
  181.         echo "install: $dst/$dstbase renamed as OLD$dstbase"
  182.     fi
  183.  
  184.     cp $srcbase $dst/$dstbase && $test $verbose &&
  185.     echo "install: $srcbase installed as $dst/$dstbase"
  186.  
  187.     if $test ! x$dostrip = x; then
  188.         strip $dst/$dstbase 2>/dev/null && $test $verbose &&
  189.         echo "install: stripped $dst/$dstbase"
  190.     fi
  191.  
  192.     if $test ! x$uid = x; then
  193.         $chown $uid $dst/$dstbase
  194.     fi
  195.     if $test ! x$gid = x; then
  196.         $chgrp $gid $dst/$dstbase
  197.     fi
  198.     if $test ! x$mode = x
  199.     then
  200.         $chmod $mode $dst/$dstbase
  201.     fi
  202. )
  203.  
  204. exit 0
  205. !NO!SUBS!
  206. chmod 755 install
  207. $eunicefix install
  208.