GFlashKey.sh 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. #!/bin/bash
  2. end="\033[0m"
  3. red='\e[0;31m'
  4. white='\e[0;37m'
  5. lightgreen='\e[0;32m'
  6. ###############################################################################################
  7. #Here you should write your outcome, which will happen if the device is disconnected
  8. #For convenience, the function has been put at the very beginning of the code, to make it easier to find and write your actions in general
  9. ###############################################################################################
  10. main_menu() {
  11. clear
  12. echo -e "${lightgreen}Welcome to GreyHat Flash Key software"
  13. echo -e "Press [ENTER] to start${end}"
  14. read go #Just for hold the strings, nevermind
  15. select_device
  16. checkflash
  17. }
  18. select_device() {
  19. clear
  20. echo -e "${lightgreen}Device's list: ${end}"
  21. lsusb | grep ID #Show list of all connected USB-devices
  22. echo -e "${lightgreen}Enter the device's ID in format (1a1b:1234): ${end}"
  23. read -rp "> " whichdevice
  24. checkex="$(lsusb | grep $whichdevice)" #Checking for user-entered device exists..
  25. if [ "$checkex" != "" ];then
  26. id=$whichdevice
  27. else
  28. echo "Looks like you've typed wrong device"
  29. echo "Select a correct device!"
  30. echo "Press [Enter] and try again"
  31. read asdasdad #Just for hold the strings, nevermind
  32. clear
  33. select_device
  34. fi
  35. clear
  36. }
  37. things() {
  38. source things.txt
  39. }
  40. checkflash() {
  41. while sleep 0.1
  42. do
  43. dev="$(lsusb | grep "$id")" #Checking if device connected
  44. if [ "$dev" != "" ];then
  45. clear
  46. echo -e "${lightgreen}It works!${end}"
  47. echo ""
  48. echo -e "${white}GFLashkEy now monitors the presence of the device with ID '$id'."
  49. echo -e "You can minimize this window and go about your business."
  50. echo -e "As soon as the device is removed, the script will perform your action. Have a nice day!${end}"
  51. else #If device disconnected, do things
  52. clear
  53. echo -e "${red}Device disconnection detected. Performing actions.${end}"
  54. things > /dev/null 2>&1
  55. clear
  56. echo -e "${white}Things done. Have a nice day!${end}"
  57. exit 0
  58. fi
  59. done
  60. }
  61. check_root() {
  62. if (( "$EUID" == 0 ));then #Checking if user is root
  63. main_menu
  64. else
  65. echo "Sorry, I need root to do things!"
  66. echo "Without root, probably, I couldn't do some things which requies root access"
  67. echo "Are you sure you want to continue?(y/n)"
  68. read -rp ">>> " con
  69. case $con in
  70. y)
  71. main_menu
  72. ;;
  73. n)
  74. exit 0
  75. ;;
  76. *)
  77. check_root
  78. ;;
  79. esac
  80. fi
  81. }
  82. case $1 in
  83. -h | --help)
  84. clear
  85. echo "Welcome to GFLashkEy!"
  86. echo "GFLashkEy - is a simple bash script which will monitor the presence of the specified device (usb flash drive, mouse, etc.) in the computer. "
  87. echo "When the selected device is disconnected, the script will perform the actions you specify. Initially, this action unmounts all mounted veracrypt volumes."
  88. echo "In order to do something like the standard GFLashkEy, you need root access, but it's still really to run without root"
  89. echo ""
  90. echo "Usage : First, set manually the actions to be performed (type them in the things() function)."
  91. echo "Next, run the script and select the device which will be monitored. To do this, specify its ID, it can be found in the list of devices, which will give you GFLashkEy."
  92. echo "The ID consists of 4 characters and 4 digits (it is enough to specify any one). The ID is unique for each device."
  93. echo "Then, GFLashkEy will cycle through checking for it, you can see the corresponding inscription in the terminal window."
  94. echo "As soon as the device is removed from the computer, GFLashkEy will immediately begin to perform the specified actions. When they are done, you will see a message saying that they are done."
  95. echo ""
  96. echo "Special use : do not start the terminal in the same partition which will be unmounted (if you are going to unmount it with GFLashkEy), because the partition cannot be unmounted if it is 'busy'."
  97. echo "If you close the terminal to 'release' the partition, the script will close and will not perform the specified actions."
  98. echo "Also, specify a kill for each running process in the partition, otherwise you will not be able to unmount it."
  99. echo "Consider every feature and situation to ensure that the script works 100% correctly."
  100. ;;
  101. "")
  102. check_root
  103. ;;
  104. *)
  105. echo "Usage : ./GFLashkEy"
  106. echo ""
  107. echo "Type --help/-h to print help banner"
  108. esac