home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 15 / 15.iso / s / s053 / 11.ddi / usr / sbin / install < prev    next >
Encoding:
Text File  |  1990-12-08  |  6.7 KB  |  346 lines

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