home *** CD-ROM | disk | FTP | other *** search
/ PC World Komputer 1999 March B / SCO_CASTOR4RRT.iso / base / root.15 / usr / sbin / install / install~
Text File  |  1998-08-19  |  7KB  |  351 lines

  1. #!/sbin/sh
  2.  
  3. # Copyright (c) 1998 The Santa Cruz Operation, Inc.. All Rights Reserved. 
  4. #                                                                         
  5. #        THIS IS UNPUBLISHED PROPRIETARY SOURCE CODE OF THE               
  6. #                   SANTA CRUZ OPERATION INC.                             
  7. #                                                                         
  8. #   The copyright notice above does not evidence any actual or intended   
  9. #   publication of such source code.                                      
  10.  
  11. #    Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T
  12. #      All Rights Reserved
  13.  
  14. #    THIS IS UNPUBLISHED PROPRIETARY SOURCE CODE OF AT&T
  15. #    The copyright notice above does not evidence any
  16. #    actual or intended publication of such source code.
  17.  
  18. #ident    "@(#)install.sh    15.1"
  19. #ident "$Header: /sms/sinixV5.4es/rcs/s19-full/usr/src/cmd/install/install.sh,v 1.1 91/02/28 17:38:08 ccs Exp $"
  20. #    INSTALL COMMAND
  21.  
  22. FLIST=$ROOT/etc/syslist
  23. DEFAULT="$ROOT/bin $ROOT/usr/bin $ROOT/etc $ROOT/lib $ROOT/usr/lib" FOUND="" MOVOLD=""
  24. ECHO=echo PATH=/bin:/etc:/usr/bin FLAG=off
  25. USAGE="eval echo 'usage: install [options] file [dir1 ...]'; exit 2"
  26. MFLAG=off
  27. UFLAG=off
  28. GFLAG=off
  29.  
  30. MODE=755
  31. GROUP=`expr "\`id\`" : ".*gid=[0-9]*(\([^)]*\))"`
  32. OWNER=`expr "\`id\`" : ".*uid=[0-9]*(\([^)]*\))"`
  33. if [ -z "$GROUP" ]
  34. then
  35.     GROUP=`expr "\`id\`" : ".*gid=\([0-9]*\).*"`
  36. fi
  37. if [ -z "$OWNER" ]
  38. then
  39.     OWNER=`expr "\`id\`" : ".*uid=\([0-9]*\).*"`
  40. fi
  41. if [ "$OWNER" = root ]
  42. then
  43.     ROOTFLAG=on
  44.     OWNER=bin
  45.     GROUP=bin
  46. else
  47.     ROOTFLAG=off
  48. fi
  49.  
  50.  
  51. for i in $*
  52. do
  53.     if [ $FLAG = on ]
  54.     then
  55.         case $i in
  56.             -*) echo "install: The -c, -f, -n options each require a directory following!"
  57.             exit 2;;
  58.              *) FLAG=off
  59.             continue;;
  60.         esac
  61.     fi
  62.     case $i in
  63.         -c) if [ x$ARG = x-f -o x$arg = x-i -o x$arg = x-o -o x$arg = x-n ]
  64.         then
  65.             echo "install: -c dir: illegal option with ${arg-"-f"} option!"
  66.             exit 2
  67.         elif test $# -lt 3
  68.         then
  69.             echo "install: -c option must have at least 3 args!"
  70.             exit 2
  71.         else
  72.             direct=$2
  73.             FLAG=on
  74.             ARG=-c
  75.             shift; shift
  76.         fi;;
  77.         -f) if [ x$ARG = x-c -o x$arg = x-i -o x$arg = x-n ]
  78.         then
  79.             echo "install: -f dir: illegal option with ${arg-"-c"} option!"
  80.             exit 2
  81.         elif test $# -lt 3
  82.         then
  83.             echo "install: -f option must have at least 3 args!"
  84.             exit 2
  85.         else
  86.             direct=$2
  87.             FLAG=on
  88.             ARG=-f
  89.             shift; shift
  90.         fi;;
  91.       -i) if [ x$ARG  = x-c -o x$ARG = x-f ]
  92.         then
  93.             echo "install: -i: illegal option with $ARG option!"
  94.             exit 2
  95.         elif test $# -lt 3
  96.         then
  97.             echo "install: -i option requires at least 3 args!"
  98.             exit 2
  99.         else
  100.             DEFAULT=""
  101.             arg=-i
  102.             shift
  103.         fi;;
  104.         -o) if  [ x$ARG = x-c ]
  105.         then
  106.             echo "install: -o: illegal option with $ARG option!"
  107.             exit 2
  108.         elif test $# -lt 2
  109.         then
  110.             $USAGE
  111.         else
  112.             MOVOLD=yes
  113.             arg=-o
  114.             shift
  115.         fi;;
  116.         -n) if [ x$ARG = x-c -o x$ARG = x-f ]
  117.         then
  118.             echo "install: -n dir: illegal option with $ARG option!"
  119.             exit 2
  120.         elif test $# -lt 3
  121.         then
  122.             echo "install: -n option requires at least 3 args!"
  123.             exit 2
  124.         else
  125.             LASTRES=$2
  126.             FLAG=on
  127.             FOUND=n
  128.             arg=-n
  129.             shift; shift
  130.         fi;;
  131.         -s) if test $# -lt 2
  132.         then
  133.             $USAGE
  134.         else
  135.             ECHO=:
  136.             arg=-s
  137.             shift
  138.         fi;;
  139.         -u) if [ $ROOTFLAG = off ]
  140.         then
  141.             echo "install: -u option available only to root -- ignored"
  142.         else
  143.             OWNER=$2
  144.             UFLAG=on
  145.             echo new owner is $OWNER
  146.         fi
  147.         FLAG=on
  148.         shift; shift;;
  149.         -g) if [ $ROOTFLAG = off ]
  150.         then
  151.             echo "install: -g option available only to root -- ignored"
  152.         else
  153.             GROUP=$2
  154.             GFLAG=on
  155.         fi
  156.         FLAG=on
  157.         shift; shift;;
  158.         -m)    if [ $ROOTFLAG = off ]
  159.         then
  160.             echo "install: -m option available only to root -- ignored"
  161.         else
  162.             MODE=$2
  163.             MFLAG=on
  164.         fi
  165.         FLAG=on
  166.         shift; shift;;
  167.          *) break;;
  168.     esac
  169. done
  170.  
  171. FILEP=$i FILE=`echo $i | sed -e "s/.*\///"`
  172. if [ x$ARG = x-c -o x$ARG = x-f ]
  173. then
  174.     case $2 in
  175.         -*) $USAGE ;;
  176.         "") :    ;;
  177.     esac
  178.     if test -f $direct/$FILE -o -f $direct/$FILE/$FILE
  179.     then
  180.         case $ARG in
  181.             -c) echo "install: $FILE already exists in $direct"
  182.                 exit 2;;
  183.             -f) GRP=`ls -l $direct/$FILE | awk '{print $4}'`
  184.                 OWN=`ls -l $direct/$FILE | awk '{print $3}'`
  185.                 if [ -k $direct/$FILE ]
  186.                 then
  187.                 chmod -t $direct/$FILE
  188.                 $direct/$FILE < /dev/null > /dev/null
  189.                 tbit=on
  190.                 fi
  191.                 if [ "$MOVOLD" = yes ]
  192.                 then
  193.                 mv -f $direct/$FILE $direct/OLD$FILE
  194.                 cp $direct/OLD$FILE $direct/$FILE
  195.                 if [ $? = 0 ]
  196.                 then
  197.                    $ECHO "$FILE moved to $direct/OLD$FILE"
  198.                 else
  199.                    echo "install: mv $direct/OLD$FILE $direct/$FILE failed"
  200.                    exit 2
  201.                 fi
  202.                 fi
  203.                 if cp $FILEP $direct/$FILE
  204.                 then
  205.                 chgrp $GRP $direct/$FILE
  206.                 chown $OWN $direct/$FILE
  207.  
  208.                 if [ "$GFLAG" = on ]
  209.                 then    
  210.                     chgrp $GROUP $direct/$FILE
  211.                 fi
  212.                 if [ "$MFLAG" = on ]
  213.                 then
  214.                     chmod $MODE $direct/$FILE
  215.                 fi
  216.                 if [ "$UFLAG" = on ]
  217.                 then
  218.                     chown $OWNER $direct/$FILE
  219.                 fi
  220.  
  221.                 $ECHO "$FILEP installed as $direct/$FILE"
  222.                 else
  223.                 echo "install: cp $FILEP $direct/$FILE failed "
  224.                 exit 2
  225.                 fi
  226.                 if [ "$tbit" = on ]
  227.                 then
  228.                 chmod +t $direct/$FILE
  229.                 fi
  230.                 exit;;
  231.         esac
  232.     else
  233.         cp $FILEP $direct/$FILE
  234.         if [ $? = 0 ]
  235.         then
  236.             $ECHO "$FILEP installed as $direct/$FILE"
  237.             chgrp $GROUP $direct/$FILE
  238.             chown $OWNER $direct/$FILE
  239.             chmod $MODE $direct/$FILE
  240.         else
  241.             echo "install: cp $FILEP $direct/$FILE failed "
  242.             exit 2
  243.         fi
  244.     fi
  245.     exit
  246. fi
  247.  
  248. shift
  249.  
  250. PUTHERE=""
  251. for i in $*
  252. do
  253.     case $i in
  254.         -*) $USAGE ;;
  255.     esac
  256.     PUTHOLD=`find $i -name $FILE -type f -print`
  257.     PUTHERE=`expr "\`echo $PUTHOLD\`" : '\([^ ]*\)'`
  258.     if [ "$PUTHERE" != "" ]
  259.     then break
  260.     fi
  261. done
  262. if [ -r $FLIST -a "$PUTHERE" = "" ]
  263. then
  264.     PUTHERE=`grep "/${FILE}$" $FLIST | sed  -n -e '1p'`
  265.     if [ "$PUTHERE" != "" -a "$ROOT" != "" ]
  266.     then
  267.         PUTHERE=${ROOT}${PUTHERE}
  268.     fi
  269. fi
  270. if [ "$PUTHERE" = "" ]
  271. then
  272.     for i in $DEFAULT
  273.     do
  274.         PUTHOLD=`find $i -name $FILE -type f -print`
  275.         PUTHERE=`expr "\`echo $PUTHOLD\`" : '\([^ ]*\)'`
  276.         if [ "$PUTHERE" != "" ]
  277.         then break
  278.         fi
  279.     done
  280. fi
  281. if [ "$PUTHERE" != "" ]
  282. then
  283.             GRP=`ls -l $PUTHERE | awk '{print $4}'`
  284.             OWN=`ls -l $PUTHERE | awk '{print $3}'`
  285.             if [ -k $PUTHERE ]
  286.             then
  287.             chmod -t $PUTHERE
  288.             $PUTHERE < /dev/null > /dev/null
  289.             tbit=on
  290.             fi
  291.             if [ "$MOVOLD" = yes ]
  292.             then
  293.             old=`echo $PUTHERE | sed -e "s/\/[^\/]*$//"`
  294.             mv -f $PUTHERE $old/OLD$FILE
  295.             cp $old/OLD$FILE $PUTHERE
  296.             if [ $? = 0 ]
  297.             then
  298.                     $ECHO "old $FILE moved to $old/OLD$FILE"
  299.             else
  300.                    echo "install: cp $direct/OLD$FILE $direct/$FILE failed"
  301.                     exit 2
  302.             fi
  303.             fi
  304.             FOUND=y
  305.             if cp $FILEP $PUTHERE
  306.             then
  307.             chgrp $GRP $PUTHERE
  308.             chown $OWN $PUTHERE
  309.  
  310.             if [ "$GFLAG" = on ]
  311.             then    
  312.                 chgrp $GROUP $PUTHERE
  313.             fi
  314.             if [ "$MFLAG" = on ]
  315.             then
  316.                 chmod $MODE $PUTHERE
  317.             fi
  318.             if [ "$UFLAG" = on ]
  319.             then
  320.                 chown $OWNER $PUTHERE
  321.             fi
  322.  
  323.             if [ "$tbit" = on ]
  324.             then
  325.                 chmod +t $PUTHERE
  326.             fi
  327.             $ECHO "$FILEP installed as $PUTHERE"
  328.             break
  329.             else
  330.             exit 2
  331.             fi
  332. fi
  333.  
  334. case $FOUND in
  335.     "") echo "install: $FILE was not found anywhere!"
  336.         exit 2;;
  337.      y) :    ;;
  338.      n) cp $FILEP $LASTRES/$FILE
  339.         if [ $? = 0 ]
  340.         then
  341.         $ECHO "$FILEP installed as $LASTRES/$FILE by default!"
  342.         cd $LASTRES
  343.         chgrp $GROUP $FILE
  344.         chown $OWNER $FILE
  345.         chmod $MODE $FILE
  346.         else
  347.         echo "install: cp $FILEP $LASTRES/$FILE failed"
  348.         exit 2
  349.         fi;;
  350. esac
  351.