-
-
Notifications
You must be signed in to change notification settings - Fork 22
/
install_external_keyboard_toggle.sh
69 lines (54 loc) · 2.48 KB
/
install_external_keyboard_toggle.sh
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
66
67
68
69
#!/usr/bin/env bash
source non_sudo_check.sh
# ENV VARS
if [ -z "$INSTALL_DIR_PATH" ]; then
INSTALL_DIR_PATH="/usr/share/asus-numberpad-driver"
fi
if [ -z "$CONFIG_FILE_DIR_PATH" ]; then
CONFIG_FILE_DIR_PATH="$INSTALL_DIR_PATH"
fi
if [ -z "$CONFIG_FILE_NAME" ]; then
CONFIG_FILE_NAME="numberpad_dev"
fi
if [ -z "$INSTALL_UDEV_DIR_PATH" ]; then
INSTALL_UDEV_DIR_PATH="/usr/lib/udev"
fi
CONFIG_FILE_PATH="$CONFIG_FILE_DIR_PATH/$CONFIG_FILE_NAME"
echo "External keyboard"
echo
echo "This is a predefined rule for changing the configuration when an external keyboard is connected/disconnected."
echo
echo "The application of this rule results in the following changes if an external keyboard is connected:"
echo
echo " - Numlock key does not activate NumberPad (config value is set to sys_numlock_enables_numpad=0)"
echo " - Numberpad disactivation does not disable Numlock (config value is set to numpad_disables_sys_numlock=0)"
echo
echo "In summary when an external keyboard is connected then NumberPad activation is not linked to Numlock state and vice versa."
echo
read -r -p "Do you want install the rule for external keyboard? [y/N]" RESPONSE
case "$RESPONSE" in [yY][eE][sS]|[yY])
EXTERNAL_KEYBOARD_TOGGLE=1
echo
cat "udev/90-numberpad-external-keyboard.rules" | INSTALL_DIR_PATH=$INSTALL_DIR_PATH envsubst '$INSTALL_DIR_PATH' | sudo tee "$INSTALL_UDEV_DIR_PATH/rules.d/90-numberpad-external-keyboard.rules" >/dev/null
if [[ $? != 0 ]]; then
echo "Something went wrong when applying 90-numberpad-external-keyboard.rules"
exit 1
else
echo "Rule 90-numberpad-external-keyboard.rules applied"
fi
sudo mkdir -p "$INSTALL_DIR_PATH/udev"
cat "udev/external_keyboard_is_connected.sh" | CONFIG_FILE_PATH=$CONFIG_FILE_PATH envsubst '$CONFIG_FILE_PATH' | sudo tee "$INSTALL_DIR_PATH/udev/external_keyboard_is_connected.sh" >/dev/null
cat "udev/external_keyboard_is_disconnected.sh" | CONFIG_FILE_PATH=$CONFIG_FILE_PATH envsubst '$CONFIG_FILE_PATH' | sudo tee "$INSTALL_DIR_PATH/udev/external_keyboard_is_disconnected.sh" >/dev/null
sudo chmod +x "$INSTALL_DIR_PATH/udev/external_keyboard_is_connected.sh"
sudo chmod +x "$INSTALL_DIR_PATH/udev/external_keyboard_is_disconnected.sh"
sudo udevadm control --reload-rules && sudo udevadm trigger
if [[ $? != 0 ]]; then
echo "Something went wrong when reloading or triggering udev rules"
exit 1
else
echo "Udev rules reloaded and triggered"
fi
;;
*)
;;
esac