summaryrefslogtreecommitdiff
path: root/bin/extra/usbtoggle
blob: d459ffd92d26e5de83960afbca2034ef959a831e (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)
# - fzf (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/')"

printf '%s\n' 0 | doas tee "$file"
printf '%s\n' 1 | doas tee "$file"