-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathdictee.install
More file actions
88 lines (80 loc) · 3.62 KB
/
Copy pathdictee.install
File metadata and controls
88 lines (80 loc) · 3.62 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
_install_uinput_drop_in() {
# The AUR `dotool` package ships /usr/lib/udev/rules.d/80-dotool.rules
# with MODE="0620" (write-only for the input group). python-evdev opens
# /dev/uinput with O_RDWR (read+write), which fails with that mode →
# dictee-ptt.service crashes with "could not open uinput device in
# write mode" and the PTT shortcut silently doesn't work.
#
# The .deb postinst and .rpm %post fix this by `sed`ing the rule file
# they ship themselves in /etc/udev/rules.d/. On Arch we don't ship
# the rule (file conflict with the dotool AUR package would block
# the install), so we drop a higher-priority override into /etc/
# which: (1) is honored by udev because /etc/ overrides /usr/lib/,
# (2) survives `pacman -S dotool` upgrades that would otherwise
# reset the rule shipped by AUR.
DROP_IN="/etc/udev/rules.d/81-dictee-uinput.rules"
cat > "$DROP_IN" <<'RULES'
# Drop-in installed by dictee. Overrides MODE from /usr/lib/udev/rules.d/80-dotool.rules.
# python-evdev (used by dictee-ptt) opens /dev/uinput with O_RDWR, so we need
# read+write for the input group, not just write (0620).
KERNEL=="uinput", MODE="0660"
RULES
udevadm control --reload-rules 2>/dev/null || true
udevadm trigger --action=change /dev/uinput 2>/dev/null || true
}
_setup_user_groups() {
# Add logged-in users to the 'input' group (dotool / dictee-ptt
# need /dev/uinput access) and 'docker' group when docker is
# available (LibreTranslate runs in Docker). Mirrors postinst .deb
# and %post .rpm so an Arch user gets the same default behaviour
# as Debian/Ubuntu/Fedora installs — without it, PTT shortcut and
# LibreTranslate stay broken until the user runs usermod manually.
for uid in $(loginctl list-sessions --no-legend 2>/dev/null | awk '{print $2}' | sort -u); do
user=$(id -nu "$uid" 2>/dev/null) || continue
[ "$user" = "root" ] && continue
if ! id -nG "$user" | grep -qw input; then
usermod -aG input "$user"
echo "✓ $user added to group 'input' (dotool / PTT)"
fi
if command -v docker >/dev/null 2>&1; then
if ! id -nG "$user" | grep -qw docker; then
usermod -aG docker "$user"
echo "✓ $user added to group 'docker' (LibreTranslate)"
fi
fi
done
}
post_install() {
# Load uinput now so dotool & dictee-ptt work without a reboot.
# /etc/modules-load.d/dictee-uinput.conf handles subsequent boots.
modprobe uinput 2>/dev/null || true
_install_uinput_drop_in
_setup_user_groups
# Create Python venv for text2num (number conversion)
PP_VENV="/usr/share/dictee/postprocess-env"
if command -v python3 >/dev/null 2>&1; then
if [ ! -d "$PP_VENV" ]; then
if python3 -m venv "$PP_VENV" 2>/dev/null; then
"$PP_VENV/bin/pip" install --quiet --upgrade pip 2>/dev/null || true
"$PP_VENV/bin/pip" install --quiet text2num 2>/dev/null || \
echo "Warning: text2num install failed (check internet)"
fi
fi
fi
}
post_upgrade() {
modprobe uinput 2>/dev/null || true
_install_uinput_drop_in
_setup_user_groups
PP_VENV="/usr/share/dictee/postprocess-env"
if [ -d "$PP_VENV" ] && command -v python3 >/dev/null 2>&1; then
"$PP_VENV/bin/pip" install --quiet --upgrade pip 2>/dev/null || true
"$PP_VENV/bin/pip" install --quiet --upgrade text2num 2>/dev/null || true
else
post_install
fi
}
pre_remove() {
rm -rf /usr/share/dictee/postprocess-env
rm -f /etc/udev/rules.d/81-dictee-uinput.rules
}