#!/bin/bash

echo -e "[ \033[34mSYSTEMEC\033[0m ] Disabling USB devices..." | tee /dev/console

for dev in /sys/bus/usb/devices/*; do
    # Only match main device entries (no colon)
    if [[ $(basename "$dev") =~ ^[0-9]+-[0-9]+$ ]]; then
        if [ -e "$dev/driver" ]; then
            echo "-----"
            echo "Device path: $dev"
            dev_name=$(basename "$dev")
            echo "Unbinding: $dev_name"
            echo "$dev_name" > /sys/bus/usb/drivers/usb/unbind
        else
            echo "Skipping: $dev"
        fi
    fi
done

echo -e "[ \033[34mSYSTEMEC\033[0m ] Disabled the USB devices at kernel level." | tee /dev/console