summaryrefslogtreecommitdiff
path: root/bin/extra/usbtoggle
blob: 7adb2a2c6037f533a6f412aeb5ce3e7d7ad83482 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
#!/bin/sh

# toggle an usb device

# dependencies
# - lsusb (to list usb devices)
# - commander (menu command)
# - doas (to run as root)

device="$(lsusb | fzf)"
[ "$device" ] || exit 1
# get vendor id
d=${device#*: * }
v=${d%%:*}
# get product id
d=${device#*:*:}
p=${d%% *}

# find path by uzing vendor and product IDs
file="$(grep -l "$p" $(grep -l "$v" /sys/bus/usb/devices/*/idVendor |
    sed 's/idVendor/idProduct/') |
    sed 's/idProduct$/authorized/')"

echo 0 | doas tee "$file"
echo 1 | doas tee "$file"