diff options
author | Yves Fischer <yvesf-git@xapek.org> | 2018-08-02 17:21:14 +0200 |
---|---|---|
committer | Yves Fischer <yvesf-git@xapek.org> | 2018-08-02 17:59:06 +0200 |
commit | 74973624deed05d1cc8b297fb1d877cadad50969 (patch) | |
tree | 8304000f99a4dc0e0fad263fc9928d8e5ad6366c /scripts/transfer.sh | |
download | esp8266-74973624deed05d1cc8b297fb1d877cadad50969.tar.gz esp8266-74973624deed05d1cc8b297fb1d877cadad50969.zip |
Diffstat (limited to 'scripts/transfer.sh')
-rwxr-xr-x | scripts/transfer.sh | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/scripts/transfer.sh b/scripts/transfer.sh new file mode 100755 index 0000000..3e73b65 --- /dev/null +++ b/scripts/transfer.sh @@ -0,0 +1,46 @@ +#!/bin/bash +PORT=$1 +lname=$2 +rname=$3 + +cat $PORT & +PRINTER_PID=$! +trap "kill $PRINTER_PID; exit" SIGINT SIGTERM + +# interrupt +echo -e -n "\003" >$PORT +# Enter RAW Repl +echo -e -n "\001" >$PORT +sleep 0.5 + + +fsize=$(du -b $lname | cut -f 1) +echo "Size of $lname $fsize" +blocksize=200 +blocks=$(( $fsize / $blocksize )) +pos=0 +echo -e -n "__fh = open('$rname', 'wb')\n" >$PORT +echo -e -n "written = 0\n\004" >$PORT +sleep 0.1 + +echo -e -n "\003" >$PORT +while [[ $pos -lt $fsize ]]; do + encoded=$(dd if=$lname ibs=1 skip=$pos count=$blocksize 2>/dev/null | python3 -c 'import sys; print(repr(sys.stdin.buffer.read()), end="")') + echo -n "$pos..$(( $pos + $blocksize )) " + echo -n "written += __fh.write(${encoded})" > $PORT + echo -e -n "\n\004" > $PORT + pos=$(( $pos + $blocksize )) + sleep 0.08 +done +echo -e -n "__fh.close()\004" >$PORT +echo -e -n "del(__fh)\004" >$PORT +sleep 0.2 + +echo -e -n "print('\\\\n\\\\n%s bytes written to file $rname\\\\n' % written)\004" >$PORT + +# enter normal repl +echo -e -n "\002" >$PORT + +sleep 0.2 + +kill $PRINTER_PID |