#!/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