home *** CD-ROM | disk | FTP | other *** search
/ Il CD di internet / CD.iso / SOURCE / N / CNEWS / _CNEWS.TAR / usr / lib / newsbin / expire / upact < prev   
Encoding:
Text File  |  1994-09-02  |  1.5 KB  |  72 lines

  1. #! /bin/sh
  2. # Update 3rd field (minimum art. #) of a 4-field active file.
  3.  
  4. # =()<. ${NEWSCONFIG-@<NEWSCONFIG>@}>()=
  5. . ${NEWSCONFIG-/var/lib/news/bin/config}
  6.  
  7. PATH=$NEWSCTL/bin:$NEWSBIN/expire:$NEWSBIN:$NEWSPATH ; export PATH
  8. umask $NEWSUMASK
  9.  
  10. cd $NEWSCTL || { echo "$0: can't cd to $NEWSCTL" >&2; exit 1; }
  11.  
  12. # check active file format
  13. set ""`sed 1q active`
  14. case $# in
  15. 4)    ;;
  16. *)    echo "$0: active file has other than 4 fields" >&2
  17.     exit 1 ;;
  18. esac
  19.  
  20. rm -f active.tmp
  21. if test -f active.tmp
  22. then
  23.     echo "$0: active.tmp exists and can't be removed; aborting" >&2
  24.     exit 1
  25. fi
  26.  
  27. # lock news system
  28. lock="$NEWSCTL/LOCK"
  29. ltemp="$NEWSCTL/L.$$"
  30. echo $$ >$ltemp
  31. trap "rm -f $ltemp ; exit 0" 0 1 2 15
  32. while true
  33. do
  34.     if newslock $ltemp $lock
  35.     then
  36.         trap "rm -f $ltemp $lock ; exit 0" 0 1 2 15
  37.         break
  38.     fi
  39.     sleep 30
  40. done
  41.  
  42. while read group max min fourth
  43. do
  44.     dir=`echo $group | tr . / `    # map ng name to directory name
  45.     min=
  46.     if test -d $NEWSARTS/$dir
  47.     then
  48.         min=`ls $NEWSARTS/$dir | egrep '^[0-9]+$' | sort -nr | tail -1`
  49.     fi
  50.     case "$min" in        # no files, so use max+1
  51.     "")    min=`awk "END{ print $max + 1 }" /dev/null`    ;;
  52.     esac
  53.     case "$min" in
  54.     [0-9]|[0-9][0-9]|[0-9][0-9][0-9]|[0-9][0-9][0-9][0-9])    # short
  55.         min=`expr 00000$min : '.*\(.....\)$'` ;;
  56.     esac
  57.  
  58.     echo $group $max $min $fourth
  59. done <active >active.tmp
  60.  
  61. # replace active, carefully
  62. if test `wc -l <active.tmp` -lt `wc -l <active`
  63. then
  64.     echo "$0: active.tmp is bad; aborting, leaving active unchanged" >&2
  65.     exit 1
  66. fi
  67. rm -f active.old
  68. ln active active.old
  69. mv active.tmp active
  70.  
  71. exit 0
  72.