Skip to content

Commit 3d0cc97

Browse files
committed
Enable installation as system service
1 parent d0b0f88 commit 3d0cc97

4 files changed

Lines changed: 252 additions & 15 deletions

File tree

README.md

Lines changed: 52 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -38,35 +38,72 @@ Where:
3838

3939
This creates a smooth curve that starts slow for precision and ramps up for speed.
4040

41-
## 🚀 Quick Start
41+
## 📦 Installation as System Service
4242

43-
### Prerequisites
43+
### Quick Installation
4444

45-
- Linux system with evdev/uinput support
46-
- Rust toolchain (latest stable)
47-
- Root privileges (for device access)
45+
To install the daemon as a system service that starts automatically on boot:
4846

49-
### Building
47+
```bash
48+
# Install and optionally start the service
49+
sudo ./install.sh
50+
51+
# Uninstall the service
52+
sudo ./uninstall.sh
53+
```
54+
55+
### Manual Installation
56+
57+
If you prefer to install manually:
5058

5159
```bash
52-
git clone <repository-url>
53-
cd cursor-anxious
60+
# Build the release binary
5461
cargo build --release
62+
63+
# Copy binary to system location
64+
sudo cp target/release/anxious-scroll-daemon /usr/local/bin/
65+
sudo chmod +x /usr/local/bin/anxious-scroll-daemon
66+
67+
# Copy service file
68+
sudo cp anxious-scroll-daemon.service /etc/systemd/system/
69+
70+
# Enable and start the service
71+
sudo systemctl daemon-reload
72+
sudo systemctl enable anxious-scroll-daemon
73+
sudo systemctl start anxious-scroll-daemon
5574
```
5675

57-
### Running
76+
### Service Management
5877

5978
```bash
60-
# Auto-detect mouse device
61-
sudo ./target/release/anxious-scroll-daemon
79+
# Check service status
80+
sudo systemctl status anxious-scroll-daemon
81+
82+
# Start the service
83+
sudo systemctl start anxious-scroll-daemon
84+
85+
# Stop the service
86+
sudo systemctl stop anxious-scroll-daemon
87+
88+
# Restart the service
89+
sudo systemctl restart anxious-scroll-daemon
6290

63-
# Specify device manually
64-
sudo ./target/release/anxious-scroll-daemon --device /dev/input/event3
91+
# View live logs
92+
sudo journalctl -u anxious-scroll-daemon -f
6593

66-
# Enable debug logging
67-
sudo ./target/release/anxious-scroll-daemon --debug
94+
# View recent logs
95+
sudo journalctl -u anxious-scroll-daemon --since "1 hour ago"
6896
```
6997

98+
### Troubleshooting
99+
100+
If the service fails to start or doesn't detect your mouse:
101+
102+
1. **Check service logs**: `sudo journalctl -u anxious-scroll-daemon -f`
103+
2. **Find your mouse device**: `ls -l /dev/input/by-id/`
104+
3. **Test device manually**: `sudo evtest /dev/input/eventX`
105+
4. **Specify device manually**: Edit `/etc/systemd/system/anxious-scroll-daemon.service` and add `--device /dev/input/eventX` to the ExecStart line
106+
70107
### Finding Your Mouse Device
71108

72109
```bash

anxious-scroll-daemon.service

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
[Unit]
2+
Description=Anxious Scroll Daemon - Mouse scroll wheel acceleration
3+
Documentation=https://github.com/your-repo/cursor-anxious
4+
After=multi-user.target
5+
Wants=multi-user.target
6+
7+
[Service]
8+
Type=simple
9+
User=root
10+
Group=root
11+
ExecStart=/usr/local/bin/anxious-scroll-daemon
12+
Restart=always
13+
RestartSec=5
14+
StandardOutput=journal
15+
StandardError=journal
16+
SyslogIdentifier=anxious-scroll-daemon
17+
18+
# Security settings
19+
NoNewPrivileges=true
20+
PrivateTmp=true
21+
ProtectSystem=strict
22+
ProtectHome=true
23+
ReadWritePaths=/dev/input
24+
25+
# Required capabilities for device access
26+
CapabilityBoundingSet=CAP_SYS_ADMIN
27+
AmbientCapabilities=CAP_SYS_ADMIN
28+
29+
[Install]
30+
WantedBy=multi-user.target

install.sh

Lines changed: 122 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,122 @@
1+
#!/bin/bash
2+
3+
set -e
4+
5+
# Colors for output
6+
RED='\033[0;31m'
7+
GREEN='\033[0;32m'
8+
YELLOW='\033[1;33m'
9+
NC='\033[0m' # No Color
10+
11+
echo -e "${GREEN}Installing Anxious Scroll Daemon...${NC}"
12+
13+
# Check if running as root
14+
if [[ $EUID -ne 0 ]]; then
15+
echo -e "${RED}This script must be run as root (use sudo)${NC}"
16+
exit 1
17+
fi
18+
19+
# Find the original user
20+
ORIGINAL_USER=""
21+
if [ -n "$SUDO_USER" ]; then
22+
ORIGINAL_USER="$SUDO_USER"
23+
elif [ -n "$USER" ] && [ "$USER" != "root" ]; then
24+
ORIGINAL_USER="$USER"
25+
else
26+
# Last resort: try to find a non-root user
27+
ORIGINAL_USER=$(logname 2>/dev/null || echo "")
28+
fi
29+
30+
if [ -z "$ORIGINAL_USER" ]; then
31+
echo -e "${RED}Error: Could not determine original user.${NC}"
32+
exit 1
33+
fi
34+
35+
# Check if cargo is available in user environment
36+
CARGO_CMD=""
37+
USER_HOME=$(getent passwd "$ORIGINAL_USER" | cut -d: -f6)
38+
USER_CARGO="$USER_HOME/.cargo/bin/cargo"
39+
40+
if [ -f "$USER_CARGO" ]; then
41+
CARGO_CMD="sudo -u $ORIGINAL_USER $USER_CARGO"
42+
elif sudo -u "$ORIGINAL_USER" command -v cargo &> /dev/null; then
43+
CARGO_CMD="sudo -u $ORIGINAL_USER cargo"
44+
fi
45+
46+
if [ -z "$CARGO_CMD" ]; then
47+
echo -e "${RED}Error: cargo not found in user environment.${NC}"
48+
echo ""
49+
echo "Would you like to install Rust toolchain now? (y/N)"
50+
read -r -n 1 -p "> " response
51+
echo
52+
if [[ $response =~ ^[Yy]$ ]]; then
53+
echo -e "${YELLOW}Installing Rust toolchain for user $ORIGINAL_USER...${NC}"
54+
# Download and run rustup as the original user
55+
sudo -u "$ORIGINAL_USER" bash -c "curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y"
56+
57+
# Source the cargo environment and try again
58+
if [ -f "$USER_CARGO" ]; then
59+
CARGO_CMD="sudo -u $ORIGINAL_USER $USER_CARGO"
60+
echo -e "${GREEN}Rust toolchain installed successfully!${NC}"
61+
else
62+
echo -e "${RED}Failed to install Rust toolchain.${NC}"
63+
echo "Please install manually: https://rustup.rs/"
64+
exit 1
65+
fi
66+
else
67+
echo "Please install Rust toolchain manually: https://rustup.rs/"
68+
exit 1
69+
fi
70+
fi
71+
72+
# Build the release binary
73+
echo -e "${YELLOW}Building release binary...${NC}"
74+
$CARGO_CMD build --release
75+
76+
# Check if build was successful
77+
if [ ! -f "target/release/anxious-scroll-daemon" ]; then
78+
echo -e "${RED}Error: Build failed. Binary not found.${NC}"
79+
exit 1
80+
fi
81+
82+
# Create directories if they don't exist
83+
mkdir -p /usr/local/bin
84+
mkdir -p /etc/systemd/system
85+
86+
# Copy binary
87+
echo -e "${YELLOW}Installing binary to /usr/local/bin/...${NC}"
88+
cp target/release/anxious-scroll-daemon /usr/local/bin/
89+
chmod +x /usr/local/bin/anxious-scroll-daemon
90+
91+
# Copy service file
92+
echo -e "${YELLOW}Installing systemd service...${NC}"
93+
cp anxious-scroll-daemon.service /etc/systemd/system/
94+
95+
# Reload systemd daemon
96+
echo -e "${YELLOW}Reloading systemd daemon...${NC}"
97+
systemctl daemon-reload
98+
99+
# Enable service for auto-start on boot
100+
echo -e "${YELLOW}Enabling service for auto-start...${NC}"
101+
systemctl enable anxious-scroll-daemon.service
102+
103+
# Ask if user wants to start the service now
104+
echo -e "${GREEN}Installation complete!${NC}"
105+
echo ""
106+
read -p "Do you want to start the service now? (y/N): " -n 1 -r
107+
echo
108+
if [[ $REPLY =~ ^[Yy]$ ]]; then
109+
echo -e "${YELLOW}Starting service...${NC}"
110+
systemctl start anxious-scroll-daemon.service
111+
echo -e "${GREEN}Service started!${NC}"
112+
echo ""
113+
echo "To check service status: sudo systemctl status anxious-scroll-daemon"
114+
echo "To view logs: sudo journalctl -u anxious-scroll-daemon -f"
115+
else
116+
echo "Service installed but not started. Start it manually with:"
117+
echo " sudo systemctl start anxious-scroll-daemon"
118+
fi
119+
120+
echo ""
121+
echo -e "${GREEN}Installation complete!${NC}"
122+
echo "The daemon will now start automatically on system boot."

uninstall.sh

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
#!/bin/bash
2+
3+
set -e
4+
5+
# Colors for output
6+
RED='\033[0;31m'
7+
GREEN='\033[0;32m'
8+
YELLOW='\033[1;33m'
9+
NC='\033[0m' # No Color
10+
11+
echo -e "${YELLOW}Uninstalling Anxious Scroll Daemon...${NC}"
12+
13+
# Check if running as root
14+
if [[ $EUID -ne 0 ]]; then
15+
echo -e "${RED}This script must be run as root (use sudo)${NC}"
16+
exit 1
17+
fi
18+
19+
# Stop the service if it's running
20+
if systemctl is-active --quiet anxious-scroll-daemon.service; then
21+
echo -e "${YELLOW}Stopping service...${NC}"
22+
systemctl stop anxious-scroll-daemon.service
23+
fi
24+
25+
# Disable the service
26+
if systemctl is-enabled --quiet anxious-scroll-daemon.service; then
27+
echo -e "${YELLOW}Disabling service...${NC}"
28+
systemctl disable anxious-scroll-daemon.service
29+
fi
30+
31+
# Remove service file
32+
if [ -f "/etc/systemd/system/anxious-scroll-daemon.service" ]; then
33+
echo -e "${YELLOW}Removing service file...${NC}"
34+
rm /etc/systemd/system/anxious-scroll-daemon.service
35+
fi
36+
37+
# Remove binary
38+
if [ -f "/usr/local/bin/anxious-scroll-daemon" ]; then
39+
echo -e "${YELLOW}Removing binary...${NC}"
40+
rm /usr/local/bin/anxious-scroll-daemon
41+
fi
42+
43+
# Reload systemd daemon
44+
echo -e "${YELLOW}Reloading systemd daemon...${NC}"
45+
systemctl daemon-reload
46+
47+
echo -e "${GREEN}Uninstallation complete!${NC}"
48+
echo "The daemon has been completely removed from your system."

0 commit comments

Comments
 (0)