#!/bin/bash #----------------------------------------------- # Fetches an RFC, puts it in the RFCs directory, # and, on MacOS, sets it to open using configured # editor (default is BBEdit). # # Normally, input is desired RFC number(s). Additionally, # two special strings are recognized: # 'index' fetches the text RFC index file. # 'biblio' fetches the xml2rfc RFC citation library. #----------------------------------------------- # Version 1.9 # January 4, 2008 # Randall Gellens #----------------------------------------------- #----------------------------------------------- # Timestamped messages #----------------------------------------------- function msg () { ts=`date +"%Y-%m-%d %H:%M:%S"` echo "$ts $1" } #----------------------------------------------- # Set MacOS X creator code #----------------------------------------------- function set_creator_code () { if [ -x $SETFILE ]; then $SETFILE -c $EDITOR_CREATOR_CODE $1 #else #echo "$SETFILE doesn't exist or not executable" fi } #----------------------------------------------- RFC_DIR="$HOME/IETF/RFCs" INDEX="rfc-index.txt" INDEX_DIR="$HOME/IETF" BIBLIO_URL="http://xml.resource.org/public/rfc/bibxml/" BIBLIO_DIR="$HOME/IETF/bibxml/rfc" FTP_HOST="ftp.ietf.org" FTP_DIR="rfc" EDITOR_CREATOR_CODE="R*ch" SETFILE="/Developer/Tools/SetFile" # make sure locally-installed utilities are available PATH=$PATH:/usr/local/bin:/usr/local/sbin:/usr/bin:/usr/sbin export PATH # # ftp.ietf.org now works with IPv4 # if false then # # ftp.ietf.org is broken when using IPv4 (it works fine with IPv6) # if ping6 -c2 "$FTP_HOST" >/dev/null 2>&1 then # echo "can reach $FTP_HOST via IPv6"; IPv6="true" else # echo "unable to reach $FTP_HOST via IPv6"; FTP_HOST="ftp.isi.edu" FTP_DIR="in-notes" IPv6="false" fi fi if [ $# -eq 0 ]; then X=`basename $0` echo "usage: $X | \"index\" | \"biblio\""; exit; fi # temp file for FTP output messages rm /tmp/TEMP_FTP_RFC > /dev/null 2>&1 cd $RFC_DIR for rfcx do rfc="rfc${rfcx}.txt" # Special case 'index' and 'biblio' if [ "$rfcx" == "index" ]; then msg "Getting $INDEX"; cd $INDEX_DIR if ftp -t -v ${FTP_HOST}:/$FTP_DIR/$INDEX > /tmp/TEMP_FTP_RFC 2>&1 then set_creator_code $INDEX; chmod a-w $INDEX; else msg "Unable to fetch $INDEX; FTP returned false"; MSGS=`cat /tmp/TEMP_FTP_RFC` msg "$MSGS" fi cd $RFC_DIR continue; fi if [ "$rfcx" == "biblio" ]; then msg "Getting xml2rfc RFC citation library"; cd $BIBLIO_DIR if wget -r -l 1 -A .xml -nd -nc $BIBLIO_URL > /tmp/TEMP_FTP_RFC 2>&1 then msg "successfully retreived RFC citation library" else msg "Unable to fetch RFC citation library; wget returned false"; MSGS=`cat /tmp/TEMP_FTP_RFC` msg "$MSGS" fi cd $RFC_DIR continue; fi if [ -f $rfc ]; then msg "RFC $rfcx already exists"; continue; fi msg "Getting RFC $rfcx"; if ftp -v ${FTP_HOST}:/$FTP_DIR/$rfc > /tmp/TEMP_FTP_RFC 2>&1 ; then set_creator_code $rfc; chmod a-w $rfc; else msg "No such RFC: $rfc; FTP returned false"; MSGS=`cat /tmp/TEMP_FTP_RFC` msg "$MSGS" fi done