FakeKitten.sh 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. #!/usr/bin/env bash
  2. if [ -z "$1" ] || [ -z "$2" ] || [[ $2 != "encode" && $2 != "decode" && $2 != "encode_enc" ]]
  3. then echo "launch the script with the desired filename and operation"
  4. echo "./AmazonPrimeWhatever.sh FILENAME OPERATION(encode or decode)"
  5. exit
  6. fi
  7. # check for prerequisites:
  8. if ! [ -x "$(command -v convert)" ]; then
  9. echo 'Error: convert (part of the imagemagick suite) is not installed.' >&2
  10. exit 1
  11. fi
  12. if [ $2 = "encode_enc" ] || [ $(echo $1 | cut -d "_" -f1) = "FakeKittenENC" ]; then
  13. if ! [ -x "$(command -v gpg)" ]; then
  14. echo 'Error: gpg is not installed, it is needed for encryption/decryption' >&2
  15. exit 1
  16. fi
  17. fi
  18. if [ $2 = "encode" ] || [ $2 = "encode_enc" ]; then
  19. imagejpg="random.jpg"
  20. image="random.DNG"
  21. #generate random image:
  22. mx=320;my=256;head -c "$((3*mx*my))" /dev/urandom | convert -depth 8 -size "${mx}x${my}" RGB:- $imagejpg
  23. mv $imagejpg $image
  24. imagesize=$(du -b $image | cut -f1)
  25. if [ $2 = "encode" ]; then
  26. origsha=$(sha1sum $1 | cut -d " " -f1)
  27. destimage="FakeKitten_"$imagesize"_"$1"_"$origsha"_"$image
  28. mv $image $destimage
  29. dd if=$1 bs=1M >> "$destimage"
  30. echo "encode completed in $destimage"
  31. fi
  32. if [ $2 = "encode_enc" ]; then
  33. #
  34. gpg --symmetric --cipher-algo AES256 $1
  35. #
  36. origsha=$(sha1sum $1.gpg | cut -d " " -f1)
  37. destimage="FakeKittenENC_"$imagesize"_"$1.gpg"_"$origsha"_"$image
  38. mv $image $destimage
  39. dd if=$1.gpg bs=1M >> "$destimage"
  40. echo "encode completed in $destimage"
  41. fi
  42. fi
  43. if [ $2 = "decode" ]; then
  44. imageconst=$(echo $1 | cut -d "_" -f1)
  45. imagebs=$(echo $1 | cut -d "_" -f2)
  46. origname=$(echo $1 | cut -d "_" -f3)
  47. origsha=$(echo $1 | cut -d "_" -f4)
  48. origimage=$(echo $1 | cut -d "_" -f5)
  49. dd if=$1 bs=1M skip=$imagebs iflag=skip_bytes > "$origname"
  50. if [ $imageconst = "FakeKittenENC" ]; then
  51. #decrypt the file
  52. orignamenogpg=$(echo "$origname" | sed 's/.gpg//')
  53. gpg --output $orignamenogpg --decrypt $origname
  54. fi
  55. echo "decode completed in $origname, checking file integrity"
  56. echo $origsha" "$origname > $origname".sha1"
  57. shaoutput=$(sha1sum -c $origname".sha1")
  58. echo $shaoutput
  59. if [[ $shaoutput != *"OK"* ]]; then
  60. echo ""
  61. echo "!!! FAILED SHA VERIFICATION!!! EXITING"
  62. echo "!!! DELETING ALL CREATED FILES !!!"
  63. rm $origname
  64. rm $origname".sha1"
  65. exit
  66. fi
  67. if [ $imageconst = "FakeKittenENC" ]; then
  68. #remove the file that contains .gpg at the end
  69. rm $origname
  70. fi
  71. rm $origname".sha1"
  72. fi
  73. echo ""
  74. echo "end of my job"