home *** CD-ROM | disk | FTP | other *** search
/ OpenStep 4.2 / Openstep-4.2-Intel-User.iso / usr / bin / install < prev    next >
Text File  |  1997-03-27  |  4KB  |  225 lines

  1. #!/bin/csh -f
  2. umask 022
  3. set path=($path /etc)
  4. set cmd="cp -p"
  5. set links
  6. set quick
  7. set symlink
  8. set link="ln"
  9. while (1)
  10.     switch ($1)
  11.     case -s:
  12.         set strip="strip -arch all"
  13.         shift
  14.         breaksw
  15.     case -sX:
  16.         set strip="strip -arch all -X"
  17.         shift
  18.         breaksw
  19.     case -sx:
  20.         set strip="strip -arch all -x"
  21.         shift
  22.         breaksw
  23.     case -sA:
  24.         set strip="strip -arch all -A"
  25.         shift
  26.         breaksw
  27.     case -sS:
  28.         set strip="strip -arch all -S"
  29.         shift
  30.         breaksw
  31.     case -sSd:
  32.         set strip="strip -arch all -S -d $2"
  33.         shift
  34.         shift
  35.         breaksw
  36.     case -sgg:
  37.         set strip="strip -arch all -gg"
  38.         shift
  39.         breaksw
  40.     case -sAn:
  41.         set strip="strip -arch all -A -n"
  42.         shift
  43.         breaksw
  44.     case -r:
  45.         set ranlib="ranlib"
  46.         shift
  47.         breaksw
  48.     case -q:
  49.         set quick="quick"
  50.         shift
  51.         breaksw
  52.     case -c:
  53.         set cmd="cp -p"
  54.         shift
  55.         breaksw
  56.     case -d:
  57.         set cmp="cmp"
  58.         shift
  59.         breaksw
  60.     case -v:
  61.         set vecho="echo"
  62.         shift
  63.         breaksw
  64.     case -m:
  65.         set chmod="chmod $2"
  66.         shift
  67.         shift
  68.         breaksw
  69.     case -o:
  70.         set chown="chown -f $2"
  71.         shift
  72.         shift
  73.         breaksw
  74.     case -g:
  75.         set chgrp="chgrp -f $2"
  76.         shift
  77.         shift
  78.         breaksw
  79.     case -xc:
  80.         set cmd="sed"
  81.         set comments='/^[     ]*#/d'
  82.         shift
  83.         breaksw
  84.     case -xs:
  85.         set cmd="sed"
  86.         set comments='/^[     ]*[#:]/d'
  87.         shift
  88.         breaksw
  89.     case -l:
  90.         set links="$links $2"
  91.         shift
  92.         shift
  93.         breaksw
  94.     case -u:
  95.         set unlink="rm -f"
  96.         shift
  97.         breaksw
  98.     case -V:    
  99.         set stamp="vers_string -f"
  100.         set link="symlink -r -f"
  101.         shift
  102.         breaksw
  103.     case -S:
  104.         set save=1
  105.         shift
  106.         breaksw
  107.     default:
  108.         break
  109.         breaksw
  110.     endsw
  111. end
  112. if ( $#argv < 2 ) then
  113.     echo "install: no destination specified"
  114.     exit(1)
  115. endif
  116. set dest=$argv[$#argv]
  117. if ( $#argv > 2 ) then
  118.     if ( ! -d $dest ) then
  119.         echo "usage: install f1 f2 or f1 f2 ... dir"
  120.         exit(1)
  121.     endif
  122. endif
  123. foreach j ($argv)
  124.     if ( $j == $dest) break
  125.     if ( ! -f $j ) then
  126.         echo "install: can't open $j"
  127.         exit(1)
  128.     endif
  129.     if ( -d $dest ) then
  130.         set file=$dest/${j:t}
  131.     else
  132.         set file=$dest
  133.     endif
  134.     if ( -f $file ) then
  135.         if ( `ls -i $file | awk '{print $1}'` == \
  136.              `ls -i $j | awk '{print $1}'` ) then
  137.             echo "install: can't move $j onto itself"
  138.             exit(1)
  139.         endif
  140.     endif
  141.     if ( $?stamp ) then
  142.         set symlink=$file
  143.         set file=`$stamp $file`
  144.     endif
  145.     if ( "$cmd" == "sed" ) then
  146.         if ( -e $file && $?save ) then
  147.             rm -f $file.old
  148.             if ( ! { mv $file $file.old } ) exit(1)
  149.         endif
  150.         if ( $?unlink ) then
  151.             $unlink $file
  152.         endif
  153.         if ($?vecho) then
  154.             echo sed -e '<strip comments>' $j ">$file"
  155.         endif
  156.         sed -e '1s;^#\!;&;p' -e '2s;^#(@)PROG;&;p' \
  157.             -e '2s;^#PROG;&;p' -e "$comments" $j >$file
  158.     else if ( $?cmp ) then
  159.         echo -n CMP $j $file
  160.         if ( { cmp -s $j $file } ) then
  161.             echo ';'
  162.         else
  163.             if ( -e $file && $?save ) then
  164.                 rm -f $file.old
  165.                 if ( ! { mv $file $file.old } ) exit(1)
  166.             endif
  167.             if ( $?unlink ) then
  168.                 $unlink $file
  169.             endif
  170.             echo " THEN" $cmd
  171.             if ( ! { $cmd $j $file } ) exit(1)
  172.         endif
  173.     else
  174.         if ( -e $file && $?save ) then
  175.             rm -f $file.old
  176.             if ( ! { mv $file $file.old } ) exit(1)
  177.         endif
  178.         if ( $?unlink ) then
  179.             $unlink $file
  180.         endif
  181.         if ($?vecho) then
  182.             echo $cmd $j $file
  183.         endif
  184.         if ( ! { $cmd $j $file } ) exit(1)
  185.     endif
  186.     if ( $?strip ) then
  187.         if ($?vecho) then
  188.             echo $strip $file
  189.         endif
  190.         if ( ! { $strip $file } ) exit(1)
  191.     endif
  192.     if ( $?ranlib ) then
  193.         if ($?vecho) then
  194.             echo $ranlib $file
  195.         endif
  196.         if ( ! { $ranlib $file } ) exit(1)
  197.     endif
  198.     if ( $?chmod ) then
  199.         if ($?vecho) then
  200.             echo $chmod $file
  201.         endif
  202.         if ( ! { $chmod $file } ) exit(1)
  203.     endif
  204.     if ( $?chown ) then
  205.         if ($?vecho) then
  206.             echo $chown $file
  207.         endif
  208.         if ( ! { $chown $file } ) exit(1)
  209.     endif
  210.     if ( $?chgrp ) then
  211.         if ($?vecho) then
  212.             echo $chgrp $file
  213.         endif
  214.         if ( ! { $chgrp $file } ) exit(1)
  215.     endif
  216. end
  217. foreach i ( $symlink $links )
  218.     if ($?vecho) then
  219.         echo $link $file $i
  220.     endif
  221.     rm -f $i
  222.     if ( ! { $link $file $i } ) exit(1)
  223. end
  224. exit(0)
  225.