Skip to content
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
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.
  • Loading branch information
arainho authored Jan 5, 2023
commit 095e92fbd2eefd1bc620c4373023e93e5853bace
13 changes: 9 additions & 4 deletions dnscrypt-proxy-switcher.10s.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down