-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathusbguard-interactive
More file actions
executable file
·43 lines (39 loc) · 1007 Bytes
/
usbguard-interactive
File metadata and controls
executable file
·43 lines (39 loc) · 1007 Bytes
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
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#!/usr/bin/env bash
# run usbguard interactively to avoid typing two commands lol
check_root() {
if (("$(id -u)" != 0)) || ! hash usbguard 2>/dev/null; then
print_error "Make sure 'usbguard' is installed and run this program as root."
fi
}
print_error() {
tput setaf 1
printf -- '[ERR] %s\n' "$1" >&2
tput sgr0
exit 1
}
# TODO: (jam) add option to operate on multiple devices
main() {
check_root
printf -- 'USB Devices:\n\n'
usbguard list-devices | cut -d'"' -f1-5 | sed 's/hash//'
printf -- '\n'
read -rp "Which device would you like to operate on? " device
read -rp "[a]llow, [b]lock, or [r]eject device? " operation
case "$operation" in
a | A | allow | Allow)
operation="allow-device"
;;
b | B | block | Block)
operation="block-device"
;;
r | R | reject | Reject)
operation="reject-device"
;;
*)
print_error "Please select an option between: [a]llow [b]lock [r]eject"
;;
esac
usbguard "${operation}" "${device}"
}
main
exit 0