#!/bin/bash
TMPFILE=/tmp/orphan.result
MYTHCONFDIR=/usr/share/mythtv /usr/LH/bin/find_orphans.py --printonly > $TMPFILE

COLUMN=orphan    # Name of the column
COLOR=green      # By default, everything is OK

MSG="No Orphans Found."

#yellow
for i in "Orphaned video files" "Orphaned snapshots" "Database backups" "Other files" "Recordings with missing files" "Zero byte recordings"
do
   grep -q  "$i" $TMPFILE
   status=$?
   if [[ $status -eq 0 ]] && [[ $i == "Database backups" ]]
   then
       MSG="$i"
   elif [ $status -eq 0 ]
   then
       COLOR="yellow"
       MSG="Problems with"
   fi
done

if [[ $MSG == "Database backups" ]]
then
MSG="
`cat $TMPFILE`
"
elif [[ $MSG != "No Orphans Found." ]]
then
MSG="
${MSG} `cat $TMPFILE`

<b>From <a href="/shell/" target="_blank">System >> Terminal</a> run find_orphans.py to clean up these issues.</b>
"
fi

# Tell Hobbit about it
$BB $BBDISP "status $MACHINE.$COLUMN $COLOR Results from find_orphans.py
    ${MSG}
    "
exit 0
