############################################################################
#
# Copyright (c) 2013 - dsixda (dislam@rocketmail.com)
#
# Android Kitchen is 100% free.  This script file is intended for personal
# and/or educational use only.  It may not be duplicated for monetary
# benefit or any other purpose without the permission of the developer.
#
############################################################################

clear

if [ -d WORKING_* ]
then

  cd WORKING_*
  
  if [ ! -e META-INF/com/google/android/update-script ]
  then
    echo "Error: update-script not found, cannot continue"
    cd ..
    exit 0
  fi

  if [ ! -e system/build.prop ]
  then
    echo "Error: build.prop not found, cannot continue"
    cd ..
    exit 0
  fi

  cd ..

else
  echo "No working folder found!"
  exit 0
fi

echo
echo -n "Please wait "

#
# Get version of kitchen
#

echo -n "."
kitchen_ver=`scripts/get_kitchen_ver`


#
# Check if Samsung Galaxy S/S2
#

echo -n "."
scripts/check_galaxy_s_and_s2
is_galaxy_ss2=$?

echo -n "."
if [ "$is_galaxy_ss2" == "1" ]
then
  scripts/extract_initramfs
else
  scripts/ensure_boot_extracted
fi


if [ ! -d BOOT-EXTRACTED ] 
then
  echo "Warning: BOOT-EXTRACTED folder not found"
fi


clear
echo
echo -n "Please wait "

echo -n "."
scripts/check_galaxies
is_galaxies=$?
echo -n "."
scripts/check_galaxy_s3_exynos
is_galaxy_s3_exynos=$?
echo -n "."
scripts/check_gnote2_common
is_gnote2_common=$?
scripts/check_galaxy_s4_common
is_galaxy_s4_common=$?


#
# Check Android OS version
#

echo -n "."
android_os=`scripts/get_build_prop_val ro.build.version.release`



#
# Check Build Number
#

echo -n "."
cd WORKING_*
cd system

if [ `grep -c ro.product.version build.prop` == 0 ]
then
  id_var=ro.build.display.id
else
  id_var=ro.product.version
fi

cd ../..

rom_name=`scripts/get_build_prop_val $id_var`



#
# Check Device
#

echo -n "."
device_name=`scripts/get_device_name`


#
# Check Model
#

echo -n "."
model=`scripts/get_product_model`



#
# Check root
#

echo -n "."
cd WORKING_*

if [ "`find . -name su`" == "" ] 
then
  su_status=NO
elif [ "`find . -iname Superuser.apk`" == "" ] && [ "`find . -iname SuperSU.apk`" == "" ]
then
  su_status=NO
else
  su_status=YES
fi

cd ..

if [ ! -e BOOT-EXTRACTED/boot.img-ramdisk/default.prop ]
then
  unsecure_status=UNKNOWN
else
  grep_root=`grep -m 1 ro.secure BOOT-EXTRACTED/boot.img-ramdisk/default.prop`

  if [ "$grep_root" == "ro.secure=1" ] 
  then
    unsecure_status=NO
  elif [ "$grep_root" == "ro.secure=0" ]
  then
    unsecure_status=YES
  else
    unsecure_status=UNKNOWN
  fi
fi



#
# Check busybox
#

echo -n "."
cd WORKING_*

if [ "`find . -name busybox`" == "" ] 
then
  bb_status=NO
else
  bb_status=YES
fi

cd ..



#
# Check apps2sd
#

echo -n "."
scripts/a2sd_exists

if [ "$?" == "1" ]
then
  apps2sd_status=YES
else
  apps2sd_status=NO
fi



#
# Check wireless tethering
#

echo -n "."
scripts/pre_froyo_check
is_old=$?

if [ "$is_old" == "1" ] 
then

  cd WORKING_*

  tether_list=( wireless_tether* android.tether* )

  if [ "$su_status" == "YES" ] 
  then
    tether_status=NO*
  else
    tether_status=NO
  fi

  for find_tether in ${tether_list[@]}
  do
    
    res=`find . -name $find_tether`
    if [ "$res" != "" ]
    then
      tether_status=YES
      break
    fi

  done
  cd ..
fi


#
# Check /data/app
#

echo -n "."
scripts/data_app_exists

if [ "$?" == "1" ]
then
  data_app_status=YES
else
  data_app_status=NO
fi


#
# Check /data/local
#

echo -n "."
cd WORKING_*
cd META-INF/com/google/android
grep_data_local=`grep -c "0771 DATA:local" update-script`

if [ "$grep_data_local" == "1" ]
then
  custom_anim_status=YES
else
  custom_anim_status=NO
fi

cd ../../../../..


#
# Check if ROM contains Nano
#

echo -n "."
scripts/nano_exists
res=$?
if [ "$res" = "0" ] 
then
  nano_status=NO
else
  nano_status=YES
fi




#
# Check if ROM contains Bash
#

echo -n "."
cd WORKING_*

if [ "`find . -name bash`" == "" ]
then
  bash_status=NO
else
  bash_status=YES
fi

cd ..




#
# Check for CSC version
#

echo -n "."
cd WORKING_*

show_csc=no

if [ -e system/CSCVersion.txt ] || [ "$device_name" == "GT-I9001" ] || [ "$device_name" == "GT-I9070" ] || [ "$is_galaxies" == "1" ]
then

  show_csc=yes

  if [ -e system/CSCVersion.txt ]
  then
    csc_version=`more system/CSCVersion.txt | sed 's/[ ]*$//g'`
  else
    csc_version=UNKNOWN
  fi

fi

cd ..




if [ "$is_galaxy_ss2" == "1" ] || [ "$is_galaxy_s3_exynos" == "1" ] || \
     [ "$is_gnote2_common" == "1" ] || [ "$is_galaxy_s4_common" == "1" ]
then

  #
  # Check if ROM contains modem.bin
  #

  echo -n "."
  cd WORKING_*

  if [ -e modem.bin ]
  then
    modem_status=YES
  else
    modem_status=NO
  fi

  cd ..

else

  #
  # Check if ROM contains radio.img
  #

  echo -n "."
  cd WORKING_*

  if [ -e radio.img ]
  then
    radio_status=YES
  else
    radio_status=NO
  fi

  cd ..

fi




#
# Check if ROM is deodexed
#

echo -n "."
cd WORKING_*

if [ ! -d system/framework ]
then
  deodex_fr_status="NO FOLDER"
else
  if [ "`find system/framework -name *.odex`" == "" ]
  then
    deodex_fr_status=YES
  else
    deodex_fr_status=NO
  fi
fi

if [ ! -d system/app ]
then
  deodex_app_status="NO FOLDER"
else
  if [ "`find system/app -name *.odex`" == "" ]
  then
    deodex_app_status=YES
  else
    deodex_app_status=NO
  fi
fi

cd ..




#
# Check if ROM does a wipe
#

echo -n "."
cd WORKING_*

cd META-INF/com/google/android
grep_wipe=`grep -c "format .*DATA:" update-script`
  
if [ "$grep_wipe" == "0" ]
then
  wipe_status=NO  
else
  wipe_status=YES
fi

cd ../../../../..


#
# Check for BusyBox run-parts method
#

echo -n "."

if [ -e BOOT-EXTRACTED/boot.img-ramdisk ]
then
  cd BOOT-EXTRACTED/boot.img-ramdisk

  test_start=`grep -c "start sysinit" init.rc`
  test_service=`grep -c "service sysinit" init.rc`

  if [[ "$test_start" == "0" || "$test_service" == "0" ]] 
  then
    runparts_status=NO
  else
    runparts_status=YES
  fi

  cd ../..
else
  runparts_status=UNKNOWN
fi


clear

echo
echo "Working folder information (v$kitchen_ver)"
echo
echo " Android OS version             : $android_os"
echo " Device                         : $device_name"
echo " Model                          : $model"
echo " ROM Name                       : $rom_name"

if [ "$show_csc" == "yes" ]
then
  echo " CSC version                    : $csc_version"
fi

echo " Rooted (Superuser app + su)    : $su_status"
echo " Rooted (unsecured boot.img)    : $unsecure_status"                                         
echo " BusyBox installed              : $bb_status"
echo " BusyBox run-parts support      : $runparts_status"
echo " Apps2SD (Apps to EXT) enabled  : $apps2sd_status" 

if [ "$is_old" == "1" ]; then
echo " Wireless tethering installed   : $tether_status"
fi

echo " /data/app enabled              : $data_app_status"
echo " Custom boot animation allowed  : $custom_anim_status"                                                         
echo " Nano text editor installed     : $nano_status"
echo " Bash shell support             : $bash_status"
echo " /system/framework is deodexed  : $deodex_fr_status"
echo " /system/app is deodexed        : $deodex_app_status"

if [ "$is_galaxy_ss2" == "1" ] || [ "$is_galaxy_s3_exynos" == "1" ] || \
     [ "$is_gnote2_common" == "1" ] || [ "$is_galaxy_s4_common" == "1" ]
then
  echo " modem.bin found                : $modem_status"
elif [ "$is_galaxies" != "1" ]
then
  echo " radio.img found                : $radio_status"
fi

echo " ROM will wipe all data         : $wipe_status"
echo

if [ "$is_old" == "1" ]
then
  if [ "$tether_status" == "NO*" ]
  then
    echo -n " * - No "
    
    for find_tether in ${tether_list[@]}
    do
      echo -n "$find_tether " 
    done

    echo
  fi 
fi

rm -rf BOOT-EXTRACTED


