Skip to content

Commit

Permalink
Update ether gadget toggle script
Browse files Browse the repository at this point in the history
Signed-off-by: paulober <[email protected]>
  • Loading branch information
paulober committed Sep 25, 2024
1 parent 879e874 commit 04e6378
Showing 1 changed file with 9 additions and 11 deletions.
20 changes: 9 additions & 11 deletions src/extraFiles/rpi-usb-ether-gadget.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,36 +8,34 @@ fi

# check if the script is run on a Raspberry Pi
if ! grep -q "Raspberry Pi" /proc/device-tree/model; then
echo -e "\e[31mThis script is for Raspberry Pi only\e[0m"
echo -e "\e[31mThis script is for Raspberry Pi devices only\e[0m"
exit
fi

FORCE_ON=false
FORCE_OFF=false
# check if command line arguments to force on or to force off are provided if not continue with
# check else force
TURN_ON=true
if [ "$1" == "on" ]; then
FORCE_ON=true
TURN_ON=true
elif [ "$1" == "off" ]; then
FORCE_OFF=true
TURN_ON=false
elif [ "$1" == "toggle" ]; then
: # Do nothing and continue to the code below
if [ -f /etc/modules-load.d/usb-ether-gadget.conf ]; then
TURN_ON=false
fi
elif [ "$1" == "status" ]; then
if [ -f /etc/modules-load.d/usb-ether-gadget.conf ]; then
echo -e "\e[33mUSB Ethernet Gadget is on\e[0m"
else
echo -e "\e[33mUSB Ethernet Gadget is off\e[0m"
fi
exit
else # add else if to make toggling possible without toggle keyword
else
echo "Usage: rpi-usb-ether-gadget [on|off|toggle|status|help]"
exit
fi

#rm /etc/modprobe.d/g_ether.conf

# check if /etc/modules-load.d/usb-ether-gadget.conf exists to know if to turn of or on or the force flags are set
if ([ -f /etc/modules-load.d/usb-ether-gadget.conf ] && [ "$FORCE_ON" = false ]) || [ "$FORCE_OFF" = true ]; then
if [ "$TURN_ON" = false ]; then
echo "Turning \e[31moff\e[0m USB Ethernet Gadget mode"
rm -f /etc/modules-load.d/usb-ether-gadget.conf
sed -i '/dtoverlay=dwc2,dr_mode=peripheral/d' /boot/firmware/config.txt
Expand Down

0 comments on commit 04e6378

Please sign in to comment.