#!/bin/bash

###
### GETIDTYPE - Figure out if this I-D is active or expired
###
### Version 2.0.1
###
### Written in 2005-2007 by Jari Arkko
### Donated to the public domain.
###

for f in $*
do
  #echo 0
  if [ -s $f ]
  then
    i=/tmp/$$.tmp
    rm -f $i
    head -30 $f > $i
    #echo 1
    if fgrep 'Internet-Drafts are not archival documents' $i > /dev/null
    then
      type=expired
    else
      #echo 2
      if fgrep 'Internet-Drafts are not an archival document series' $i > /dev/null
      then
        type=expired
      else
        #echo 3
        if fgrep 'This Internet-Draft was published as a' $i > /dev/null
        then
          type=published
        else
          #echo 4
          if fgrep ', was published as' $i > /dev/null
          then
            type=published
          else
            #echo 5
            if fgrep 'A new Request for Comments is now available' $i > /dev/null
            then
              type=published
            else
              if egrep '^was published as' $i > /dev/null
              then
                type=published
              else 
                type=exists
              fi
            fi
          fi
        fi
      fi
    fi
    rm -f $i
  else
    #echo 6
    type=empty
  fi
  echo $f:$type
done
