mynode/rootfs/standard/usr/bin/mynode_usb_driver_check.sh
2022-04-20 23:03:51 -05:00

61 lines
2.1 KiB
Bash
Executable File

#!/bin/bash
set -x
source /usr/share/mynode/mynode_config.sh
# Allow UAS
if [ -f /mnt/hdd/mynode/settings/.uas_usb_enabled ] || [ -f /home/bitcoin/.mynode/.uas_usb_enabled ]; then
cat /boot/cmdline.txt | grep "usb-storage.quirks="
if [ $? -eq 0 ]; then
cat /boot/cmdline.txt | grep "usb-storage.quirks=none"
if [ $? -eq 0 ]; then
exit 0
else
sed -i "s/usb-storage.quirks=.*/usb-storage.quirks=none/g" /boot/cmdline.txt
sync
/usr/bin/mynode-reboot
fi
fi
exit 0
else
# Disable UAS
lsusb -t | grep "Driver=uas"
if [ $? -eq 0 ]; then
echo "UAS FOUND"
USBINFO=$(lsusb | grep "SATA 6Gb/s bridge")
DEVID=$(egrep -o '[0-9a-f]+:[0-9a-f]+' <<< $USBINFO)
echo "UAS IN USE ON $DEVID"
if [ $IS_RASPI -eq 1 ]; then
echo "IS RASPBERRY PI"
if [ -f /boot/cmdline.txt ]; then
QUIRK="${DEVID}:u"
CMDLINE=$(head -n 1 /boot/cmdline.txt)
cat /boot/cmdline.txt | grep "usb-storage.quirks"
if [ $? -eq 0 ]; then
cat /boot/cmdline.txt | grep "usb-storage.quirks=${QUIRK}"
if [ $? -eq 0 ]; then
# Quirk already added, exit 0
echo "QUIRK ALREADY EXISTS, EXITING"
exit 0
else
# Different quirk exists, update and reboot
echo "DIFFERENT QUIRK FOUND, UPDATING AND REBOOTING"
sed -i "s/usb-storage.quirks=.*/usb-storage.quirks=${QUIRK}/g" /boot/cmdline.txt
fi
else
# No quirk found, add it and reboot
echo "NO QUIRK FOUND, ADDING AND REBOOTING"
echo "${CMDLINE} usb-storage.quirks=${QUIRK}" > /boot/cmdline.txt
fi
sync
sleep 5s
/usr/bin/mynode-reboot
fi
fi
else
echo "No UAS devices found"
fi
fi