#!/usr/bin/bash

if [ $# -ne 1 ]
then
  echo "Usage: $0 <top_section>"
  echo "Dumps the PDR recursively starting at the specified top section."
  echo "To start at the very top, specify \"\"."
  echo "If it includes spaces, you must enclose the section in double quotes."
  echo "Example: $0 \"Voip Gateway H323\""
  exit
fi

top_section="$1";
#echo dump $1.

IFS=$'\t\n'

for section in `/nn/bin/pdrcmd dir "$1"`
do
  # ignore the Sections: or Entries: headings
  if [ x$section == "xSection Listing Failed" ]
  then
    echo "Section Listing Failed."
    echo "Check that the Pdrd is running."
    echo "Check for "Self Test Failed" in the nnulogfile.  Reboot if necessary."
    exit
  elif [ x$section == "xSections:" ]
  then
    doingSections=1;
    doingEntries=0;
  elif [ x$section == "xEntries:" ]
  then
    doingEntries=1;
    doingSections=0;
  elif [ $doingSections -eq 1 ] 
  then
    #echo section $section
    if [ x$1 != x ]
    then
      top_section="$1\\$section"
    else
      top_section="$section"
    fi
    #echo top_section = $top_section
    echo
    $0 "$top_section"
  elif [ $doingEntries -eq 1 ]
  then
    entry=$1\\$section
    #echo entry $entry
    value=`/nn/bin/pdrcmd get "$entry"`
    echo "$1\\$section:   $value"
  fi
  done

echo
#echo done $1
