-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathswitch-camera.sh
More file actions
executable file
·65 lines (56 loc) · 1.5 KB
/
switch-camera.sh
File metadata and controls
executable file
·65 lines (56 loc) · 1.5 KB
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#!/bin/bash
# Script to enable or disable internal laptop camera via udev rule
# It aims to solve a personal problem i have of apps opening by default my
# laptop webcam when I have a better one on USB
# Usage: ./toggle_internal_camera.sh block|unblock
set -e
# Replace with actual vendor/product IDs of your internal camera
ID_VENDOR="2232"
ID_PRODUCT="1080"
# Path to the udev rule
UDEV_RULE="/etc/udev/rules.d/99-disable-internal-camera.rules"
# Function to reload udev
reload_udev() {
echo "Reloading udev rules..."
sudo udevadm control --reload-rules
sudo udevadm trigger
echo "Done."
}
# Function to block internal camera
block_camera() {
echo "Blocking internal camera..."
sudo bash -c "cat > $UDEV_RULE" <<EOF
# Disable internal laptop camera by ignoring the device
ATTR{idVendor}=="$ID_VENDOR", ATTR{idProduct}=="$ID_PRODUCT", ATTR{authorized}="0"
EOF
reload_udev
echo "Internal camera blocked."
}
# Function to unblock internal camera
unblock_camera() {
echo "Unblocking internal camera..."
if [ -f "$UDEV_RULE" ]; then
sudo rm "$UDEV_RULE"
reload_udev
echo "Internal camera unblocked."
else
echo "No udev rule found. Internal camera was not blocked."
fi
}
# Main logic
if [ "$EUID" -ne 0 ]; then
echo "Please run as root or with sudo."
exit 1
fi
case "$1" in
block)
block_camera
;;
unblock)
unblock_camera
;;
*)
echo "Usage: $0 block|unblock"
exit 1
;;
esac