Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- # recognize destination of this script
- script_path=$(dirname "$(readlink -f "$0")")
- # set default path to user's desktop
- #root_path="/home/$(whoami)/Desktop/"
- # set default path to user's downloads folder
- root_path="/home/$(whoami)/Downloads/"
- stm_upload() {
- sleep 1;
- echo
- file_to_upload=$1
- if [ -f $file_to_upload ]; then
- st-flash --reset write $file_to_upload 0x8000000
- rm $file_to_upload
- fi
- }
- dfu_upload() {
- sleep 1;
- echo
- file_to_upload=$1
- if [ -f $file_to_upload ]; then
- dfu-util -a 0 -s 0x08000000:leave -D $file_to_upload
- rm $file_to_upload
- fi
- }
- inotifywait --format '%w%f' -m -r -e close_write $root_path | while IFS= read -r file; do
- # remove path to obtain relative path to $root_path
- path=$(realpath --relative-to="$root_path" $file)
- # does the file contain string "_NUCLEO_" in name
- if [[ $file == *"_NUCLEO_"* ]]; then
- # do not upload uncomplete file
- if [[ $file != *".crdownload"* ]]; then
- if [[ $file == *".bin"* ]]; then
- echo "file ready for upload: $path"
- sleep 0.1
- # is device supporting DFU?
- if [[ $file == *"NUCLEO_F042K6"* ]]; then
- dfu_upload $root_path/$path
- else
- stm_upload $root_path/$path
- fi
- fi
- fi
- fi
- done
Add Comment
Please, Sign In to add comment