|
#!/bin/bash |
|
# setup-ydotool.sh - Install and configure ydotool on Pop!_OS / Ubuntu |
|
|
|
set -e |
|
|
|
echo "=== ydotool setup ===" |
|
|
|
# --- Dependencies --- |
|
echo "[1/5] Installing dependencies..." |
|
sudo apt install -y cmake libevdev-dev scdoc git |
|
|
|
# --- uinput --- |
|
echo "[2/5] Setting up uinput..." |
|
sudo modprobe uinput |
|
|
|
# Make uinput load on boot |
|
echo "uinput" | sudo tee /etc/modules-load.d/uinput.conf > /dev/null |
|
|
|
# Set uinput permissions |
|
echo 'KERNEL=="uinput", GROUP="input", MODE="0660"' | sudo tee /etc/udev/rules.d/60-uinput.rules > /dev/null |
|
sudo udevadm control --reload-rules |
|
sudo udevadm trigger |
|
|
|
# Add user to input group |
|
sudo usermod -aG input "$USER" |
|
echo " Added $USER to input group (will take full effect after logout/login)" |
|
|
|
# --- Build & install ydotool --- |
|
echo "[3/5] Building ydotool from source..." |
|
BUILD_DIR="$(mktemp -d)/ydotool" |
|
git clone https://github.com/ReimuNotMoe/ydotool "$BUILD_DIR" |
|
cd "$BUILD_DIR" |
|
mkdir build && cd build |
|
cmake .. |
|
make -j"$(nproc)" |
|
sudo make install |
|
|
|
# --- systemd user service for ydotoold --- |
|
echo "[4/5] Setting up ydotoold as a systemd user service..." |
|
systemctl --user daemon-reload |
|
systemctl --user enable ydotoold |
|
systemctl --user start ydotoold |
|
|
|
# --- Shell profile setup --- |
|
echo "[5/5] Configuring shell environment..." |
|
PROFILE_LINE='export YDOTOOL_SOCKET="/run/user/$(id -u)/.ydotool_socket"' |
|
|
|
for RC in "$HOME/.bashrc" "$HOME/.zshrc"; do |
|
if [ -f "$RC" ]; then |
|
if ! grep -q "YDOTOOL_SOCKET" "$RC"; then |
|
echo "$PROFILE_LINE" >> "$RC" |
|
echo " Added YDOTOOL_SOCKET to $RC" |
|
else |
|
echo " YDOTOOL_SOCKET already set in $RC, skipping" |
|
fi |
|
fi |
|
done |
|
|
|
# Apply to current session |
|
export YDOTOOL_SOCKET="/run/user/$(id -u)/.ydotool_socket" |
|
|
|
# --- Test --- |
|
echo "" |
|
echo "=== Testing ydotool ===" |
|
sleep 1 |
|
if ydotool type "Test" 2>/dev/null; then |
|
echo "ydotool is working correctly!" |
|
else |
|
echo "Test failed. You may need to log out and back in for group changes to take effect." |
|
echo "Then run: ydotool type 'Test'" |
|
fi |
|
|
|
echo "" |
|
echo "=== Done ===" |
|
echo "Note: If this is your first install, log out and back in to apply input group permissions." |