Pastebin launched a little side project called VERYVIRAL.com, check it out ;-) Want more features on Pastebin? Sign Up, it's FREE!
Guest

package.sh

By: a guest on Apr 3rd, 2011  |  syntax: Bash  |  size: 0.97 KB  |  views: 450  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. #!/bin/sh
  2.  
  3. if [ $# -ne 6 ]; then
  4.         echo "Usage: $0 -t type -d deviceCode input.tar.gz output.bin"
  5.         exit 1
  6. fi
  7.  
  8. DEVICE=$4
  9. TYPE=$2
  10. INPUT=$5
  11. OUTPUT=$6
  12.  
  13. HEADER_SIZE=48
  14. BLOCK_SIZE=64
  15. if [ "${TYPE}" == "FB02" -o "${TYPE}" == "FB01" ]; then
  16.         BLOCK_SIZE=131072
  17. fi
  18.  
  19. MD=`pwd`/md
  20.  
  21. echo 'Checking parameters...'
  22. if [ ${#DEVICE} -ne 2 ]; then
  23.         echo 'deviceCode must be a two digit number. ex: 02'
  24.         exit 1
  25. fi
  26. TYPE=`echo "${TYPE}" | tr "[a-z]" "[A-Z]"`
  27. if [ ${#TYPE} -ne 4 ]; then
  28.         echo 'type must be 4 characters long. ex: FC02'
  29.         exit 1
  30. fi
  31. if [ ! -f ${INPUT} ]; then
  32.         echo 'cannot find input'
  33.         exit 1
  34. fi
  35.  
  36. echo 'Making bin file...'
  37.  
  38. echo -e "${TYPE}\x00\x00\x00\x00\xFF\xFF\xFF\x7F\x${DEVICE}\x00\x00" > ${OUTPUT}
  39. md5sum ${INPUT} | ${MD} >> ${OUTPUT}
  40.  
  41. COUNT=`expr ${BLOCK_SIZE} - ${HEADER_SIZE}`
  42. while [ ${COUNT} -ne 0 ]; do
  43.         printf "\0" >> ${OUTPUT}
  44.         COUNT=`expr $COUNT - 1`
  45. done
  46.  
  47. echo 'Adding tar...'
  48. cat ${INPUT} | ${MD} >> ${OUTPUT}
  49.  
  50. echo 'Done.'
  51.  
  52. exit 0