#!/bin/bash
# Exibe o relatrio de gravaes do sistema

source /etc/cdcontrolrc

if ! ls -F ${LOG_DIR}|grep -v '/'|grep '[a-zA-Z]';then
 echo "No one report was found"
 exit 1
fi

# Cria o arquivo temporrio que ser usado para armazenar o valor de retorno
# dos menus
L_TMPFILE=`mktemp /tmp/fileXXXXXX`


while true;do
 dialog --backtitle "CDcontrol v${CDC_VERSION}" --clear \
        --title "Show a report" \
        --menu "Use the arrow keys and press <Enter>.\n\
Press <Esc> ou select 'Cancel' to exit:" 20 60 10 \
`ls -F ${LOG_DIR} | grep -v '/' | sed -e s/"^"/"\""/ | \
  sed -e s/"$"/'\" \"\" \\ '/` 2>${L_TMPFILE}

 L_RETVAL=$?
 L_REL_NAME=`cat ${L_TMPFILE}`

 case ${L_RETVAL} in
   0)
    L_REL_NAME=`echo ${L_REL_NAME}|sed -e s/"\""//g`
    clear
    ${PAGER-more} ${LOG_DIR}/${L_REL_NAME}
    echo "Press ENTER to continue";read
   ;;
   1)
     rm -f ${L_TMPFILE}
     exit 1
     ;;
   255)
     rm -f ${L_TMPFILE}
     exit 1
     ;;
 esac
done
rm -f ${L_TMPFILE}
