home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 January / usenetsourcesnewsgroupsinfomagicjanuary1994.iso / sources / unix / volume26 / xc-4.1 / part01 / bsdinst.sh < prev    next >
Encoding:
Linux/UNIX/POSIX Shell Script  |  1993-04-13  |  1.6 KB  |  126 lines

  1. #! /bin/sh
  2. #
  3. # This accepts bsd-style install arguments and executes them
  4. #
  5.  
  6. die()
  7. {
  8.     echo "$*" 1>&2
  9.     exit 1
  10. }
  11.  
  12. dest=""
  13. src=""
  14. strip="false"
  15. owner=""
  16. group=""
  17. mode="755"
  18.  
  19. while [ -n "$1" ]
  20. do
  21.     case $1 in 
  22.     -c)    ;;
  23.  
  24.     -m)    mode="$2"
  25.         shift
  26.         ;;
  27.  
  28.     -o) owner="$2"
  29.         shift
  30.         ;;
  31.  
  32.     -g) group="$2"
  33.         shift
  34.         ;;
  35.  
  36.     -s) strip="true"
  37.         ;;
  38.  
  39.     -*)    die "Illegal option"
  40.         ;;
  41.  
  42.     *)    if [ -z "$2" ]
  43.         then
  44.             dest="$1"
  45.             break
  46.         fi
  47.  
  48.         src="$src $1"
  49.  
  50.         if [ ! -f "$1" -o ! -r "$1" ]
  51.         then
  52.             die "$1: file does not exist or is not readable"
  53.         fi
  54.     ;;
  55.     esac
  56.  
  57.     shift
  58. done
  59.  
  60. [ -n "$dest" ] || die "No destination specified"
  61.  
  62. [ -n "$src" ] || die "No file specified"
  63.  
  64. if [ ! -d "$dest" ]
  65. then
  66.     count=0
  67.     for i in $src
  68.     do
  69.         count=`expr $count + 1`
  70.     done
  71.  
  72.     if [ "$count" -eq 1 ]
  73.     then
  74.         parent=`dirname $dest`
  75.         if [ -d "$parent" ]
  76.         then
  77.             newname=`basename $dest`
  78.             dest=$parent
  79.         fi
  80.     fi
  81.  
  82.     [ -n "$newname" ] || die "$dest: No such directory"
  83. fi
  84.  
  85. # Here's where the real work happens.  Note that on some systems, chown
  86. # clears SUID and SGID bits for non-superusers.  Thus, the chmod has to
  87. # follow chown.  However, under System V, you can not chmod SUID or SGID
  88. # permissions unless you are the owner or superuser.
  89. # If you are in doubt, "su" first!
  90.  
  91. for i in $src
  92. do
  93.     set -e
  94.  
  95.     ofile=$dest/${newname:-$i}
  96.  
  97.     rm -f $ofile
  98.  
  99.     cp $i $ofile
  100.  
  101.     if $strip
  102.     then
  103.         strip $ofile
  104.         if i386
  105.         then
  106.             mcs -d $ofile
  107.         fi
  108.     fi
  109.  
  110.     if [ -n "$group" ]
  111.     then
  112.         chgrp $group $ofile
  113.     fi
  114.  
  115.     if [ -n "$owner" ]
  116.     then
  117.         chown $owner $ofile
  118.     fi
  119.  
  120.     chmod $mode $ofile
  121.  
  122.     set +e
  123. done
  124.  
  125. exit 0
  126.