############################################################################
#
# 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.
#
############################################################################

## 
## The unpack-initramfs script does not work with all zImages!!
##

clear

scripts/prompt_remove_boot_extracted

if [ ! -d BOOT-EXTRACTED ]
then

  if [ -d WORKING_* ]
  then
    echo
    echo Working folder found
  else
    echo
    echo Working folder not found, you will need to create one!
    exit 0
  fi

  initramfs_dir=BOOT-EXTRACTED
  mkdir $initramfs_dir

  cd WORKING_*

  if [ -e zImage ]
  then

    cp zImage ../BOOT-EXTRACTED
    cd ..
    cp tools/samsung_files/unpack-initramfs BOOT-EXTRACTED/ 

    cd BOOT-EXTRACTED
    ./unpack-initramfs zImage
        
    if [ ! -e kernel ]
    then
      echo "Error: No kernel found!"
    fi

    if [ ! -d initramfs_root ]
    then
      echo "Error: No initramfs_root folder found!"
    else
      mv -f initramfs_root boot.img-ramdisk
    fi

    rm -f unpack-initramfs zImage
    cd ..
    echo

  else
    echo "Error: zImage not found!"
    echo
    cd ..
    echo "Removing initramfs_dir folder"
    rm -rf $initramfs_dir
    exit 0
  fi      
fi    

