From fe98b3821fe2df28ae0081df05041cb59e9cd14c Mon Sep 17 00:00:00 2001 From: Henry Gabryjelski Date: Sat, 18 Feb 2023 23:48:08 -0800 Subject: [PATCH 1/2] Prevent double-enumeration under WSL2 --- pm3 | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/pm3 b/pm3 index 79ea38768..a3df5717b 100755 --- a/pm3 +++ b/pm3 @@ -68,11 +68,12 @@ function get_pm3_list_Linux { fi fi # WSL2 with usbipd detection - doesn't report same things as WSL1 - if grep -q "proxmark.org" "/sys/class/tty/${DEV#/dev/}/../../../manufacturer" 2>/dev/null; then - PM3LIST+=("$DEV") - if [ ${#PM3LIST[*]} -ge "$N" ]; then - return + if !( echo "${PM3LIST[*]}" | grep -q "${DEV}" ); then + PM3LIST+=("$DEV") + if [ ${#PM3LIST[*]} -ge "$N" ]; then + return + fi fi fi done @@ -474,7 +475,7 @@ fi HOSTOS=$(uname | awk '{print toupper($0)}') if [ "$HOSTOS" = "LINUX" ]; then - if uname -a|grep -qi Microsoft; then + if uname -a|grep -q Microsoft; then # First try finding it using the PATH environment variable PSHEXE=$(command -v powershell.exe 2>/dev/null) From ce85fe0099ef2e1b72e236de8761a44b3d813b60 Mon Sep 17 00:00:00 2001 From: Henry Gabryjelski Date: Sun, 19 Feb 2023 01:44:15 -0800 Subject: [PATCH 2/2] allow case-insensitive match of WSL strings --- pm3 | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/pm3 b/pm3 index a3df5717b..7c1d0e289 100755 --- a/pm3 +++ b/pm3 @@ -69,7 +69,7 @@ function get_pm3_list_Linux { fi # WSL2 with usbipd detection - doesn't report same things as WSL1 if grep -q "proxmark.org" "/sys/class/tty/${DEV#/dev/}/../../../manufacturer" 2>/dev/null; then - if !( echo "${PM3LIST[*]}" | grep -q "${DEV}" ); then + if echo "${PM3LIST[*]}" | grep -qv "${DEV}"; then PM3LIST+=("$DEV") if [ ${#PM3LIST[*]} -ge "$N" ]; then return @@ -475,7 +475,8 @@ fi HOSTOS=$(uname | awk '{print toupper($0)}') if [ "$HOSTOS" = "LINUX" ]; then - if uname -a|grep -q Microsoft; then + # Detect when running under WSL1 (but exclude WSL2) + if uname -a | grep -qi Microsoft && uname -a | grep -qvi WSL2; then # First try finding it using the PATH environment variable PSHEXE=$(command -v powershell.exe 2>/dev/null)