############################################################################
#
# Copyright (c) 2012 - 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.
#
############################################################################

#
# This script has two optional arguments:
#
# $1 = path to working folder (optional)
#


if [ "$1" == "" ]
then
  cd WORKING_*
  working_dir=`pwd`
  cd system
else
  working_dir=$1
  cd $working_dir

  if [ -d system ]
  then
    cd system
  fi
fi

system_dir=`pwd`

if [ -e sec_csc.zip ]
then
  csc_zip=sec_csc.zip
elif [ -e csc.zip ]
then
  csc_zip=csc.zip
else 
  echo "WARNING: CSC ZIP file not found!"
fi

if [ $csc_zip ]
then
  echo "Extracting the required files from $csc_zip ..."
  unzip -q $csc_zip -d temp_csc

  # 
  # Carrier bloatware removal
  #
  if [ -d temp_csc ]
  then

    cd temp_csc
    apk_files=`find . -name *.apk`

    if [ "$apk_files" != "" ]
    then
      echo
      echo "These are the apps found in $csc_zip:"
      echo 
      for apk in $apk_files
      do
        echo $apk
      done

      echo
      echo -n "Copy the apps to your working folder (y/n)? (default: n): "

      read do_copy
      echo

      if [ "$do_copy" != "y" ]
      then
        rm -vf $apk_files
      fi
    fi

    cd ..

    rm -rf temp_csc/META-INF
    cp -rf temp_csc/system/* .
    rm -rf temp_csc
  fi
fi

rm -f $csc_zip 2>/dev/null
if [ "$?" == "1" ]
then
  echo
  echo "WARNING: $csc_zip is in use.  Remove file manually."
  echo
fi

cd ../..


