test if MyGadget already exists

This commit is contained in:
2026-07-02 10:29:54 +00:00
parent cc0b37af8b
commit 3ef2ca02a6
+8 -3
View File
@@ -4,17 +4,22 @@
# https://pip-assets.raspberrypi.com/categories/685-app-notes-guides-whitepapers/documents/RP-009276-WP/Using-OTG-mode-on-Raspberry-Pi-SBCs # https://pip-assets.raspberrypi.com/categories/685-app-notes-guides-whitepapers/documents/RP-009276-WP/Using-OTG-mode-on-Raspberry-Pi-SBCs
# Is the dwc2 overlay installed? Nothing will work if it isn't. # Is the dwc2 overlay installed? Nothing will work if it isn't.
LOGGER="systemd-cat -t gadget.sh"
if lsmod | grep -q "dwc2"; then if lsmod | grep -q "dwc2"; then
$LOGGER -p info "DWC2 module loaded, setting up OTG gadget serial and ethernet" systemd-cat -t gadget.sh -p info echo "DWC2 module loaded, setting up OTG gadget serial and ethernet"
else else
$LOGGER -p warning "DWC2 module missing. Aborting OTG setup" systemd-cat -t gadget.sh -p warning echo "DWC2 module missing. Aborting OTG setup."
exit 1 exit 1
fi fi
sudo modprobe libcomposite sudo modprobe libcomposite
cd /sys/kernel/config/usb_gadget cd /sys/kernel/config/usb_gadget
# Was the script already run?
if [ -d "MyGadget" ]; then
systemd-cat -t gadget.sh -p warning echo "MyGadget already exists. Aborting OTG setup."
exit 1
fi
# Create our new gadget # Create our new gadget
sudo mkdir MyGadget sudo mkdir MyGadget
cd MyGadget cd MyGadget