#!/bin/bash

file="/sdcard/panic.txt"
dir="/sdcard/logs/backup/"
info=""
if [ ! -f $file ]
then
  exit 1
fi
info3=`strings -n 15 $file | grep "Panic key is pressed" | wc -l`
info4=`strings -n 15 $file | grep "reset_keys_dump" | wc -l`
if [ $info3 -ne 0 -a $info4 -ne 0 ]
then
  echo "Kernel panic is triggered by manual"
else
  info1=`strings -n 15 $file | grep "PC is at"`
  info2=`strings -n 15 $file | grep "LR is at"`
  info=$info1$info2
  if [ "" != "$info" ]
  then
    echo $info
  else
    echo "Kernel panic with unknown reason"
  fi
fi

savepath=$dir$(date +%Y%m%d%H%M%S)
mkdir -p $savepath
strings -n 15 $file > $savepath"/panic.txt"
rm $file
