Skip to content

Instantly share code, notes, and snippets.

@tychop
Last active May 22, 2017 16:42
Show Gist options
  • Save tychop/29bd4af2b5492d55623b2754a2f37208 to your computer and use it in GitHub Desktop.
Save tychop/29bd4af2b5492d55623b2754a2f37208 to your computer and use it in GitHub Desktop.
Ampy script to mirror current directory to a microcontroller
#!/bin/sh
#
# Ampy script to mirror current directory to a microcontroller
export AMPY_PORT=/dev/tty.SLAB_USBtoUART
export AMPY_BAUD=115200
function log() {
echo "$*" >&2
}
function fail() {
echo "Error: $*" >&2; exit 1
}
function copyFiles() {
log "\nCopying..."
for dirEntry in `ls`; do
ampy put "$dirEntry" && log "$dirEntry copied" || fail "Unable to copy '$dirEntry' to the MC. Aborting..."
done
}
function clean() {
log "\nCleaning..."
for dirEntry in `ampy ls`; do
log "Removing '$dirEntry' ..."
ampy rm "$dirEntry" &>/dev/null && continue
ampy rmdir "$dirEntry" &>/dev/null && continue
done
}
if [[ "$1" == "-c" ]]; then
log "Clean & Copy"
clean
copyFiles
elif [[ "$1" == "-co" ]]; then
log "Clean only"
clean
else
log "Copy"
copyFiles
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment