#!/bin/bash SERIAL_PORT="/dev/ttyGS0" stty -F "$SERIAL_PORT" raw while true do if read -r line < "$SERIAL_PORT" then # wait for done message if [ "$line" = "DONE" ] then echo "" > /sys/kernel/config/usb_gadget/g1/UDC exit fi fi sleep 0.5 done