Guest User

Untitled

a guest
Nov 22nd, 2017
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.20 KB | None | 0 0
  1. #!/bin/bash
  2.  
  3. # recognize destination of this script
  4. script_path=$(dirname "$(readlink -f "$0")")
  5.  
  6. # set default path to user's desktop
  7. #root_path="/home/$(whoami)/Desktop/"
  8.  
  9. # set default path to user's downloads folder
  10. root_path="/home/$(whoami)/Downloads/"
  11.  
  12. stm_upload() {
  13.  
  14. sleep 1;
  15.  
  16. echo
  17.  
  18. file_to_upload=$1
  19.  
  20. if [ -f $file_to_upload ]; then
  21. st-flash --reset write $file_to_upload 0x8000000
  22. rm $file_to_upload
  23. fi
  24. }
  25.  
  26. dfu_upload() {
  27.  
  28. sleep 1;
  29.  
  30. echo
  31.  
  32. file_to_upload=$1
  33.  
  34. if [ -f $file_to_upload ]; then
  35. dfu-util -a 0 -s 0x08000000:leave -D $file_to_upload
  36. rm $file_to_upload
  37. fi
  38. }
  39.  
  40. inotifywait --format '%w%f' -m -r -e close_write $root_path | while IFS= read -r file; do
  41.  
  42. # remove path to obtain relative path to $root_path
  43. path=$(realpath --relative-to="$root_path" $file)
  44.  
  45. # does the file contain string "_NUCLEO_" in name
  46. if [[ $file == *"_NUCLEO_"* ]]; then
  47. # do not upload uncomplete file
  48. if [[ $file != *".crdownload"* ]]; then
  49. if [[ $file == *".bin"* ]]; then
  50.  
  51. echo "file ready for upload: $path"
  52. sleep 0.1
  53.  
  54. # is device supporting DFU?
  55. if [[ $file == *"NUCLEO_F042K6"* ]]; then
  56. dfu_upload $root_path/$path
  57. else
  58. stm_upload $root_path/$path
  59. fi
  60. fi
  61. fi
  62. fi
  63. done
Add Comment
Please, Sign In to add comment