From 902e413f6fe6f3625c1380268f2064dd503cd7c4 Mon Sep 17 00:00:00 2001 From: Manuel Thalmann Date: Fri, 12 Jan 2024 12:19:51 +0100 Subject: [PATCH] Install tool for nuking USB controllers --- scripts/Arch/Collections/personal.sh | 2 ++ scripts/Common/Software/nuke-usb/install.sh | 4 +++ scripts/Common/Software/nuke-usb/nuke-usb.sh | 28 ++++++++++++++++++++ 3 files changed, 34 insertions(+) create mode 100644 scripts/Common/Software/nuke-usb/install.sh create mode 100755 scripts/Common/Software/nuke-usb/nuke-usb.sh diff --git a/scripts/Arch/Collections/personal.sh b/scripts/Arch/Collections/personal.sh index b382780c..62a8c6eb 100755 --- a/scripts/Arch/Collections/personal.sh +++ b/scripts/Arch/Collections/personal.sh @@ -121,6 +121,8 @@ yay --noconfirm -Syu \ discord \ openasar-git; +. "../../Common/Software/nuke-usb/install.sh"; + # Python yay --noconfirm -Syu \ python \ diff --git a/scripts/Common/Software/nuke-usb/install.sh b/scripts/Common/Software/nuke-usb/install.sh new file mode 100644 index 00000000..720aaa3e --- /dev/null +++ b/scripts/Common/Software/nuke-usb/install.sh @@ -0,0 +1,4 @@ +#!/bin/bash +pushd "${BASH_SOURCE%/*}" > /dev/null; +sudo install -m 755 ./nuke-usb.sh /usr/local/bin/nuke-usb; +popd > /dev/null; diff --git a/scripts/Common/Software/nuke-usb/nuke-usb.sh b/scripts/Common/Software/nuke-usb/nuke-usb.sh new file mode 100755 index 00000000..148e121f --- /dev/null +++ b/scripts/Common/Software/nuke-usb/nuke-usb.sh @@ -0,0 +1,28 @@ +#!/usr/bin/env bash +# Resets all USB host controllers of the system. +# This is useful in case one stopped working +# due to a faulty device having been connected to it. + +base="/sys/bus/pci/drivers" +sleep_secs="1" + +# This might find a sub-set of these: +# * 'ohci_hcd' - USB 3.0 +# * 'ehci-pci' - USB 2.0 +# * 'xhci_hcd' - USB 3.0 +echo "Looking for USB standards ..." +for usb_std in "$base/"?hci[-_]?c* +do + echo "* USB standard '$usb_std' ..." + for dev_path in "$usb_std/"*:* + do + dev="$(basename "$dev_path")" + echo " - Resetting device '$dev' ..." + printf '%s' "$dev" | sudo tee "$usb_std/unbind" > /dev/null + sleep "$sleep_secs" + printf '%s' "$dev" | sudo tee "$usb_std/bind" > /dev/null + echo " done." + done + echo " done." +done +echo "done."