Last active
October 30, 2015 10:33
-
-
Save gornostal/0f865b56baf250a87bdb to your computer and use it in GitHub Desktop.
Upload files via serial port to a device
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
target="$1" | |
remotePath="$2" | |
device="${3:-/dev/ttyUSB0}" | |
# compress target files using tar | encode data to base64 string | remove \n | |
compress="tar -C `dirname $target` -cjvf - `basename $target` | base64 | tr -d '\n'" | |
# decode base64 string using python (using python because my device doesn't have base64) | |
base64decode="import base64, sys; sys.stdout.write(base64.b64decode(sys.stdin.read()))" | |
# decode base64 string | un-tar file to remotePath | |
decompress="python -c '$base64decode' | tar -C $remotePath -xjvf -" | |
# echo "echo -e" + base64 string to the device | run decompress command on the device | |
echo -e "echo -e `eval $compress` | $decompress" > $device |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment