From 3165cbca33d115ca888142cf26fabfe84060c475 Mon Sep 17 00:00:00 2001 From: Yusuke Tsutsumi Date: Wed, 5 Aug 2020 22:05:47 -0700 Subject: [PATCH 1/2] Adding more restrictive eGPU detection Fixes #48 Most GPUs register as "VGA compatible controller" in lspci. Adding this string to the regex search eliminates false positives for other devices that use the same PCI-E BusID, such as non-VGA devices connected via non-eGPU docks. --- egpu-switcher | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/egpu-switcher b/egpu-switcher index e3a9072..bc6df36 100755 --- a/egpu-switcher +++ b/egpu-switcher @@ -144,7 +144,7 @@ function is_egpu_connected() { declare bus2h=$(printf "%02x" $bus2d) declare bus3h=$(printf "%01x" $bus3d) - if [ $(lspci | grep -iEc "$bus1h:$bus2h.$bus3h") -eq 1 ]; then + if [ $(lspci | grep -iEc "$bus1h:$bus2h.$bus3h.*VGA compatible controller.*") -eq 1 ]; then print_info "EGPU is ${green}connected${blank}." gpu_connected=1 hex_id=$bus1h:$bus2h.$bus3h From c3ec3b337564e0ec5c2f45d39abc83d51b3ce2e6 Mon Sep 17 00:00:00 2001 From: Yusuke Tsutsumi Date: Thu, 6 Aug 2020 22:52:18 -0700 Subject: [PATCH 2/2] addressing feedback using lspci filters vs regex match for VGA controller string, as the filters are more robust. --- egpu-switcher | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/egpu-switcher b/egpu-switcher index bc6df36..07b6d59 100755 --- a/egpu-switcher +++ b/egpu-switcher @@ -144,7 +144,7 @@ function is_egpu_connected() { declare bus2h=$(printf "%02x" $bus2d) declare bus3h=$(printf "%01x" $bus3d) - if [ $(lspci | grep -iEc "$bus1h:$bus2h.$bus3h.*VGA compatible controller.*") -eq 1 ]; then + if [ $( (lspci -d ::0300 && lspci -d ::0302) | grep -iEc "$bus1h:$bus2h.$bus3h") -eq 1 ]; then print_info "EGPU is ${green}connected${blank}." gpu_connected=1 hex_id=$bus1h:$bus2h.$bus3h