home *** CD-ROM | disk | FTP | other *** search
/ The Fred Fish Collection 1.5 / ffcollection-1-5-1992-11.iso / ff_disks / 300-399 / ff319.lzh / CNewsSrc / cnews.orig.lzh / conf / spacefor.proto < prev    next >
Text File  |  1989-06-27  |  2KB  |  63 lines

  1. #! /bin/sh
  2. # spacefor - determine available disk space
  3. # About how many things of $1 bytes will fit in the available space for
  4. # stuff of type $2 ("incoming", "articles", "control", "outbound $3",
  5. # or "archive") without cramping things too badly?
  6. #
  7. # You'll have to change this -- your blocksize, minimum-free-desired amounts,
  8. # and df output format will probably differ, and you may need to name
  9. # your filesystems explicitly.
  10.  
  11. # =()<. ${NEWSCONFIG-@<NEWSCONFIG>@}>()=
  12. . ${NEWSCONFIG-/usr/lib/news/bin/config}
  13.  
  14. PATH=$NEWSCTL/bin:$NEWSBIN:$NEWSPATH ; export PATH
  15. umask $NEWSUMASK
  16.  
  17. # punt to server if necessary
  18. if test -r $NEWSCTL/server
  19. then
  20.     server="`cat $NEWSCTL/server`"
  21.     me="`hostname`"
  22.     if test " $server" != " $me"
  23.     then
  24.         exec rsh $server "PATH=$PATH `basename $0` $*"
  25.         # does not return
  26.     fi
  27. fi
  28.  
  29. # head off special case
  30. case "$1" in
  31. 0)    echo 10000 ; exit 0 ;;
  32. esac
  33.  
  34. # argument to df, df units, and free space desired (in df units)
  35. dfunit=1024            # default unit (bytes)
  36. case "$2" in
  37. incoming)    arg="$NEWSARTS/in.coming" ; desire=5000 ;;
  38. articles)    arg="$NEWSARTS" ; desire=5000 ;;
  39. control)    arg="$NEWSCTL" ; desire=3000 ;;
  40. outbound)    arg="/usr/spool/uucp" ; desire=10000 ;;    # ignore $3
  41. archive)    arg="$NEWSARTS" ; desire=1 ;;        # system-specific
  42. *)        echo "$0: bad type argument \`$2'!!" >&2
  43.         exit 2 ;;
  44. esac
  45.  
  46. # this is set up for the stupid 4BSD df
  47. df $arg | awk "BEGIN { nf = 4 ; nr = 2 }
  48.     NR == nr && NF >= nf {
  49.         nb = (\$nf - $desire) * $dfunit / $1
  50.         if (nb > 10000)
  51.             nb = 10000    # ensure representable as integer
  52.         nb = int(nb)
  53.         if (nb <= 0)
  54.             print 0
  55.         else
  56.             print nb
  57.         exit
  58.     }
  59.     NR == nr && NF < nf {        # idiotic Berkeley continuation
  60.         nr += 1
  61.         nf -= 1
  62.     }"
  63.