Skip to content

Instantly share code, notes, and snippets.

@gornostal
Last active October 30, 2015 10:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gornostal/0f865b56baf250a87bdb to your computer and use it in GitHub Desktop.
Save gornostal/0f865b56baf250a87bdb to your computer and use it in GitHub Desktop.
Upload files via serial port to a device
#!/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