#!/bin/bash
  
  TOOLDIR=tools/android_img_repack_tools
  
  clear
  
  echo -e
  echo -en "\E[32;1m Building new image EXT4FS... \E[32;0m"
  echo -e
  echo -e
  echo -en "\033[1m Input building image <name> *****.img: \033[0m"
  tput sgr0
  
  read INPUT
  
  echo -e
  echo -en "\033[1m  Input <partition size> b/Mb: \033[0m"
  tput sgr0
  
  read SIZE
  
  echo -e
  echo -en "\033[1m  Input partition <hiader size> 28/32 bytes: \033[0m"
  tput sgr0
  
  read HSIZE
    
  sudo $TOOLDIR/make_ext4fs_def -s -l $SIZE PROJECT/$INPUT PROJECT/$INPUT.mnt
  
  if [ `echo $HSIZE | grep 32` ]
  
      then
      
      mv -v PROJECT/$INPUT PROJECT/$INPUT.tmp
      
      $TOOLDIR/sgs4ext4fs --bloat PROJECT/$INPUT.tmp PROJECT/$INPUT
      
      rm -f PROJECT/$INPUT.tmp
      
      chmod 0644 PROJECT/$INPUT
      
  fi
  
  if [ `ls PROJECT | grep recovery` ]
  
      then
      
      rm -r PROJECT/recovery
  fi
  
  if [ `uname | grep Linux` ]
  
      then
      
      sudo chown 1000.1000  PROJECT/$INPUT
      
  fi
  
  echo -e
  echo -en "\033[1m Finished \033[0m"
  echo -e
  tput sgr0
  echo -e
  echo "Press Enter to continue"
  read enterKey
