From 095e92fbd2eefd1bc620c4373023e93e5853bace Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Rainho?= Date: Thu, 5 Jan 2023 00:02:13 +0000 Subject: [PATCH 1/3] fix get_current_service function When using multiple "USB to LAN" interfaces with name such as "USB 10/100/1000 LAN (enX)" the method `get_current_service`does not detect the "Hardware Port" (aka service name) correctly. Also changed the while loop so that the `currentservice` global variable can be defined properly. --- dnscrypt-proxy-switcher.10s.sh | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/dnscrypt-proxy-switcher.10s.sh b/dnscrypt-proxy-switcher.10s.sh index 73ba2ac..dae2788 100755 --- a/dnscrypt-proxy-switcher.10s.sh +++ b/dnscrypt-proxy-switcher.10s.sh @@ -54,17 +54,22 @@ ospatch=$(echo "$osversion" | awk -F. '{print $3}') get_current_service() { services=$(networksetup -listnetworkserviceorder | grep -F 'Hardware Port') - echo "$services" | while read -r line; do + while read -r line; do sname=$(echo "$line" | awk -F "(, )|(: )|[)]" '{print $2}') sdev=$(echo "$line" | awk -F "(, )|(: )|[)]" '{print $4}') if [ -n "$sdev" ]; then ifout="$(ifconfig "$sdev" 2>/dev/null)" if echo "$ifout" | grep -Fq 'status: active'; then - currentservice="$sname" - break + if [ "${sname}" == 'USB 10/100/1000 LAN' ]; then + currentservice="$sname ($sdev)" + break + else + currentservice="$sname" + break + fi fi fi - done + done <<<$(echo "$services") if [ -n "$currentservice" ]; then echo "$currentservice" From 0565056d48c993180e4dcfb63c67540dc647144a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Rainho?= Date: Thu, 5 Jan 2023 00:22:56 +0000 Subject: [PATCH 2/3] Quotes and braces to prevent issues --- dnscrypt-proxy-switcher.10s.sh | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/dnscrypt-proxy-switcher.10s.sh b/dnscrypt-proxy-switcher.10s.sh index dae2788..5a7b862 100755 --- a/dnscrypt-proxy-switcher.10s.sh +++ b/dnscrypt-proxy-switcher.10s.sh @@ -60,8 +60,8 @@ get_current_service() { if [ -n "$sdev" ]; then ifout="$(ifconfig "$sdev" 2>/dev/null)" if echo "$ifout" | grep -Fq 'status: active'; then - if [ "${sname}" == 'USB 10/100/1000 LAN' ]; then - currentservice="$sname ($sdev)" + if [ "$sname" == 'USB 10/100/1000 LAN' ]; then + currentservice="${sname} ($sdev)" break else currentservice="$sname" @@ -69,7 +69,7 @@ get_current_service() { fi fi fi - done <<<$(echo "$services") + done <<<"$(echo "${services}")" if [ -n "$currentservice" ]; then echo "$currentservice" From 2bcd7d15e2fbce10527269097d8562ce83c247bd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Rainho?= Date: Thu, 5 Jan 2023 00:28:07 +0000 Subject: [PATCH 3/3] fix SC2116 --- dnscrypt-proxy-switcher.10s.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dnscrypt-proxy-switcher.10s.sh b/dnscrypt-proxy-switcher.10s.sh index 5a7b862..8f70931 100755 --- a/dnscrypt-proxy-switcher.10s.sh +++ b/dnscrypt-proxy-switcher.10s.sh @@ -69,7 +69,7 @@ get_current_service() { fi fi fi - done <<<"$(echo "${services}")" + done <<<"${services}" if [ -n "$currentservice" ]; then echo "$currentservice"