-
-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathinstall_user_groups.sh
More file actions
121 lines (96 loc) · 3.88 KB
/
install_user_groups.sh
File metadata and controls
121 lines (96 loc) · 3.88 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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
#!/usr/bin/env bash
source non_sudo_check.sh
# ENV VARS
if [ -z "$INSTALL_UDEV_DIR_PATH" ]; then
INSTALL_UDEV_DIR_PATH="/usr/lib/udev"
fi
UINPUT_GID=$(getent group "uinput" | cut -d: -f3)
# https://github.com/asus-linux-drivers/asus-dialpad-driver/issues/19#issuecomment-3625958498
if [ -n "$UINPUT_GID" ] && [ "$UINPUT_GID" -ge 1000 ]; then
echo "The group 'uinput' was not system (GID=$UINPUT_GID), removing..."
sudo groupdel "uinput"
fi
I2C_GID=$(getent group "i2c" | cut -d: -f3)
# https://github.com/asus-linux-drivers/asus-dialpad-driver/issues/19#issuecomment-3625958498
if [ -n "$I2C_GID" ] && [ "$I2C_GID" -ge 1000 ]; then
echo "The group 'i2c' was not system (GID=$I2C_GID), removing..."
sudo groupdel "i2c"
fi
sudo groupadd --system "input"
sudo groupadd --system "i2c"
sudo groupadd --system "uinput"
sudo usermod -a -G "i2c,input,uinput,dialpad" $USER
if [[ $? != 0 ]]; then
echo "Something went wrong when adding the groups to current user"
exit 1
else
echo "Added groups input, i2c, uinput, dialpad to current user"
fi
# workaround when is "failing" (return code is 0) adding of `input` group on BazziteOS using `usermod` or `ujust add-user-to-input-group`: https://github.com/asus-linux-drivers/asus-numberpad-driver/issues/282
if grep -q "^input:" /etc/group; then
# current members of group `input`
current_members=$(grep "^input:" /etc/group | cut -d: -f4)
# is current user already a member of group `input`?
if ! echo "$current_members" | grep -qw "$USER"; then
sudo sed -i "s/^input:\([^:]*:[^:]*:[^:]*\)/input:\1,$USER/" /etc/group
fi
else
# if group `input` does not exist in `/etc/group`` at all
sudo bash -c "echo 'input:x:104:$USER' >> /etc/group"
fi
sudo modprobe uinput
# check if the uinput module is successfully loaded
if [[ $? != 0 ]]; then
echo "uinput module cannot be loaded"
exit 1
else
echo "uinput module loaded"
fi
sudo modprobe i2c-dev
# check if the i2c-dev module is successfully loaded
if [[ $? != 0 ]]; then
echo "i2c-dev module cannot be loaded. Make sure you have installed i2c-tools package"
exit 1
else
echo "i2c-dev module loaded"
fi
sudo mkdir -p /etc/modules-load.d
# autodetects KERNEL and SUBSYSTEM values for /dev/uinput
read UINPUT_KERNEL UINPUT_SUBSYSTEM < <(
udevadm info --attribute-walk --name=/dev/uinput \
| awk -F '==' '
/KERNEL==/ && !k { gsub(/"/,"",$2); k=$2 }
/SUBSYSTEM==/ && !s { gsub(/"/,"",$2); s=$2 }
k && s { print k, s; exit }
'
)
# autodetects SUBSYSTEM for /dev/i2c-0
I2C_SUBSYSTEM=$(
udevadm info --attribute-walk --name=/dev/i2c-0 \
| awk -F '==' '
/SUBSYSTEM==/ { gsub(/"/,"",$2); print $2; exit }
'
)
echo "Udevadm detected values:"
echo " uinput: KERNEL=$UINPUT_KERNEL SUBSYSTEM=$UINPUT_SUBSYSTEM"
echo " i2c: SUBSYSTEM=$I2C_SUBSYSTEM"
# create uinput udev rule
echo 'SUBSYSTEM=="'"$UINPUT_SUBSYSTEM"'", KERNEL=="'"$UINPUT_KERNEL"'", GROUP="uinput", MODE="0660"' \
| sudo tee "$INSTALL_UDEV_DIR_PATH"/rules.d/99-asus-dialpad-driver-uinput.rules >/dev/null
echo 'uinput' | sudo tee /etc/modules-load.d/uinput-asus-dialpad-driver.conf >/dev/null
# create i2c udev rule
echo 'KERNEL=="i2c-[0-9]*", SUBSYSTEM=="'"$I2C_SUBSYSTEM"'", GROUP="i2c", MODE="0660"' \
| sudo tee "$INSTALL_UDEV_DIR_PATH"/rules.d/99-asus-dialpad-driver-i2c-dev.rules >/dev/null
echo "i2c-dev" | sudo tee /etc/modules-load.d/i2c-dev-asus-dialpad-driver.conf >/dev/null
if [[ $? != 0 ]]; then
echo "Something went wrong when adding uinput module to auto loaded modules"
exit 1
else
echo "uinput module added to auto loaded modules"
fi
sudo udevadm control --reload-rules && sudo udevadm trigger --sysname-match=uinput && sudo udevadm trigger --attr-match=subsystem=i2c-dev
if [[ $? != 0 ]]; then
echo "Something went wrong when reloading or triggering uinput udev rules"
else
echo "Udev rules reloaded and triggered"
fi