#!/bin/bash #----------------------------------------------- # Lists matching I-Ds in the I-D directory. #----------------------------------------------- # # Version 1.5 # May 17, 2007 # Randall Gellens #----------------------------------------------- ID_DIR="$HOME/IETF/Internet_Drafts" #----------------------------------------------- # Verbose messages #----------------------------------------------- function say () { if [ "${opt_verbose}" = "y" ]; then echo "$1" fi } function vsay () { if [ "${opt_super_verbose}" = "y" ]; then echo "$1" fi } #----------------------------------------------- # Start of main script #----------------------------------------------- cd $ID_DIR if [ $# -eq 0 ]; then X=`basename $0` echo "usage: $X [flags] "; echo "Flags: -c Check for updated draft in background" echo " -u Show unread drafts only" echo " -v Verbose mode" echo " -V Verbose mode" echo " -m (passed to get_id if called)" echo " -n (passed to get_id if called)" exit; fi get_id_opt_str="" opt_check="n" opt_unread="n" opt_super_verbose="n" while getopts ":cnvVmu" opt do case $opt in c) echo "will check for updates in background" opt_check="y" ;; n) ;; v) get_id_opt_str="${get_id_opt_str}v" echo "verbose mode" opt_super_verbose="y" ;; m) get_id_opt_str="${get_id_opt_str}m" ;; u) echo "showing unread only" opt_unread="y" ;; V) get_id_opt_str="${get_id_opt_str}V" echo "verbose mode" opt_super_verbose="y" ;; *) echo "Unrecognized option: ${opt}" exit ;; esac done if [ "${get_id_opt_str}X" != "X" ]; then get_id_opt_str="-${get_id_opt_str}" fi shift $(($OPTIND - 1)) for idx do # make sure to use lowercase idx=`echo "${idx}" | tr "[:upper:]" "[:lower:]"` vsay "Looking for ${idx}..." id="${idx}" filen="" if [ -f ${id} ]; then filen=${id}; vsay "...found $filen" MATCHES=${filen} elif [ -f ${id}.txt ]; then filen=${id}.txt; vsay "...found $filen" MATCHES=${filen} else # # Use ls to get list of matching files, sorted by name. # Break after first element in list, which we assume is # latest file (since we use '-r' with 'ls' to sort by # reverse alphabetic order, meaning '-02' comes before # '-01'). # RSLT=`ls -r *${id}* 2>/dev/null | grep "[0-9]*\.txt"` lastx="" for fx in $RSLT do vsay "file: $fx" draftx=`expr "$fx" : '\(.*\)\-[0-9][0-9]\.txt'` vsay "expr returned $draftx" if [ "$draftx" != "$lastx" ]; then MATCHES="$MATCHES $fx" if [ "$opt_check" = "y" ]; then vsay "Calling get_id ${get_id_opt_str} ${draftx} &" get_id ${get_id_opt_str} ${draftx} & fi vsay "...added" else vsay "...skipped" fi lastx=$draftx vsay "lastx now $lastx" done fi if [ "$opt_unread" = "y" ]; then for fx in $MATCHES do eval $(/usr/bin/stat -s $ID_DIR/$fx) if [ $st_atime -gt $st_mtime ]; then str=`stat -f "accessed %Sa" $ID_DIR/$fx` vsay "considered read: $fx ($str)" else UNREAD="$UNREAD $fx" fi done MATCHES="$UNREAD" fi vsay "Matching files: " for fx in $MATCHES do echo "$fx" done done