#!/system/xbin/ash

#check for any untarred files in /data/logsave/kmessage
#folder and move them to /data/logsave/klog folder
#Also, check for the number of files in klog folder and
#make sure the max number of files are ten

KLOG_DIR=/data/logsave/kmessage
KLOG_ORP_DIR=/data/logsave/klog

#include sarch functions
source /system/bin/sarchfunc

max=10
#file count of $1
file_count () {
   if [ "$1" ];then
          return `busybox ls -l $1 | busybox wc -l`;
   else
      echo file_count error path
      exit 50
   fi
}

#check for any untarred files in /data/logsave/kmessage
#folder and move them to /data/logsave/klog folder

file_count $KLOG_DIR/kmessage.*
fc=$?
if [ $fc -ne 0 ];then
mv $KLOG_DIR/kmessage.* $KLOG_ORP_DIR
fi

#check for the number of files in klog folder and
#make sure the max number of files are ten
remove_until_dircount_is $max $KLOG_ORP_DIR

