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

found_working=`ls | grep "^WORKING_"` 

if [ "$found_working" != "" ]
then

  echo
  echo "Before you proceed:"
  echo "The existing working folders under the main folder can be backed up"
  echo "to the folder 'original_update' for later use; otherwise they will be"
  echo "deleted."

  echo
  echo "Found the following:"
  echo $found_working
  echo
  echo -n "Move to original_update? (default: y): "

  read do_backup
  echo

  if [ "$do_backup" == "n" ]
  then
    echo "Removing ..."
    rm -rf WORKING_* 2>/dev/null

    if [ "$?" == "1" ]
    then
      exit 1
    fi

  else

    # Grab this value again, in case the user manually deleted the
    # folder after he/she was prompted
    found_working=`ls | grep -m 1 WORKING_` 

    if [ "$found_working" != "" ]
    then

      #
      # Make backup 
      #

      echo "Moving old working folders to original_update ..."
      mv WORKING_* original_update 2>/dev/null

      if [ "$?" == "1" ]
      then
        exit 1
      fi
    fi
  fi

  echo

fi

