#!/bin/bash
  
  clear
  echo -e
  echo -en "\E[32;1m Building flash ROM... \E[32;0m"
  echo -e
  echo -e
  echo -en "\033[1m Input flash file <name>: \033[0m"
  read INPUT
  echo -e
  echo -e
  echo -e
  find STOCK/ -maxdepth 1 -regex '.*\(.img\|.bin\)' -type f -exec mv -inv {} PROJECT/ \;
  
  find STOCK/ -maxdepth 1 -regex '.*\(.ext4\|.mbn\)' -type f -exec mv -inv {} PROJECT/ \;
  
  find STOCK/ -maxdepth 1 -regex '.*\(.rfs\|.zImage\)' -type f -exec mv -inv {} PROJECT/ \;
  echo -e
  echo -e
  echo -e
  cd PROJECT
  echo -e "Available parts from PROJECT:"
  echo -e
  find . -maxdepth 1 -regex '.*\(.img\|.bin\)' -type f -exec ls {} \;
  
  find . -maxdepth 1 -regex '.*\(.ext4\|.mbn\)' -type f -exec ls {} \;
  
  find . -maxdepth 1 -regex '.*\(.rfs\|.zImage\)' -type f -exec ls {} \;
  
  echo -e
  echo -en "\033[1m Input parts <names>: \033[0m"
  read PARTS
  echo -e
  echo -e
  tar -cv $PARTS >> "$INPUT".tar
  echo -e
  tar -tvf "$INPUT".tar
  echo -e
  md5sum -t "$INPUT".tar >> "$INPUT".tar
  echo -e
  mv -v "$INPUT".tar ../"$INPUT".tar.md5
  echo -e
  md5sum -t ../"$INPUT".tar.md5
  cd ..
  echo -e
  
  echo -e
  echo -en "\033[1m Finished \033[0m"
  echo -e
  tput sgr0
  echo -e
  echo "Press Enter to continue"
  read enterKey
