Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Feat/install script #2

Merged
merged 15 commits into from
Feb 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/Release_CLI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ jobs:
mv $ARCHIVE $OUTPUT_DIR

- name: Name Release
run: echo "RELEASE_NAME=${GITHUB_REPOSITORY#*/} ${GITHUB_REF_NAME#v}" >> $GITHUB_ENV
run: echo "RELEASE_NAME=${GITHUB_REPOSITORY#*/}-cli ${GITHUB_REF_NAME#v}" >> $GITHUB_ENV

- name: Release
uses: softprops/action-gh-release@v1
Expand Down
70 changes: 46 additions & 24 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,40 +18,23 @@ acceleration factor

## Install

Clone the repo, and run some make commands.
Make sure to have these dependencies installed on your machine:
`curl`, `git`, `make`, `gcc`, and the linux headers in `/lib/modules/`

```sh
git clone https://github.com/Gnarus-G/maccel.git
cd maccel
curl -fsSL https://raw.githubusercontent.com/Gnarus-G/maccel/main/install.sh | sudo sh
```

### Install the cli.

If you don't have `cargo`, then get it with rust
from https://www.rust-lang.org/tools/install
## Uninstall

```sh
cargo install --path maccel-cli
sh /opt/maccel/uninstall.sh
```

### Instal the driver and the udev rules.

```sh
make install
make udev_install # This depends on the cli and will install in /usr/local/bin
```

Optionally, it's recommended that you add yourself to the `maccel` group;
and remember to restart your session after you do so it takes effect.

Adding yourself to that `maccel` group allows you to run the maccel-cli
to set parameter values without `sudo`

### Uninstall
Or

```sh
make uninstall
make udev_uninstall
curl -fsSL https://raw.githubusercontent.com/Gnarus-G/maccel/main/uninstall.sh | sudo sh
```

## CLI Usage
Expand Down Expand Up @@ -91,3 +74,42 @@ Here is [Breakdown of why and how I ended up making this](https://www.bytin.tech
- https://github.com/a1xd/rawaccel/blob/master/doc/Guide.md
- https://github.com/Skyl3r/leetmouse/blob/master/driver/accel.c
- https://sourceforge.net/p/fixedptc/code/ci/default/tree/

## Troubleshooting Install

### gcc

The version matters, it must match the version with which the kernel was built.

For example you might such an error:

![image](https://github.com/Gnarus-G/maccel/assets/37311893/6147e20a-a132-4132-a45e-2af3dc035552)

And you'll have to find a version of `gcc` that matches. This will be more or less annoying
depending on your distro and/or how familiar you're familiar with it.

### linux headers

You want to make sure that `/lib/modules/` is not empty. For example mine looks like this:

```
total 0
drwxr-xr-x 1 root root 114 Jan 29 17:59 .
drwxr-xr-x 1 root root 159552 Jan 29 22:39 ..
drwxr-xr-x 1 root root 10 Jan 29 17:59 6.6.14-1-lts
drwxr-xr-x 1 root root 12 Jan 29 17:59 6.7.0-zen3-1-zen
drwxr-xr-x 1 root root 494 Jan 29 17:59 6.7.2-arch1-1
drwxr-xr-x 1 root root 494 Jan 31 21:54 6.7.2-zen1-1-zen
```

You want to find headers that match your kernel as represented by

```
uname -r
```

On an arch based distro you list the available headers with

```
sudo pacman -Ss linux headers
```
44 changes: 44 additions & 0 deletions install.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
set -e

setup_dirs() {
rm -rf /opt/maccel && mkdir -p /opt/maccel
cd /opt/maccel
git clone --depth 1 https://github.com/Gnarus-G/maccel.git .
}

install_driver() {
make uninstall || true
make install
}


install_cli() {
export VERSION=$(wget -qO- https://github.com/Gnarus-G/maccel/releases/latest | grep -oP 'v\d+\.\d+\.\d+' | tail -n 1);
curl -fsSL https://github.com/Gnarus-G/maccel/releases/download/$VERSION/maccel-cli.tar.gz -o maccel-cli.tar.gz
tar -zxvf maccel-cli.tar.gz maccel_$VERSION/maccel
sudo install -m 755 -v -D maccel_$VERSION/maccel bin/maccel
sudo ln -vfs `pwd`/bin/maccel /usr/local/bin/maccel
}

install_udev_rules() {
sudo install -m 644 -v -D `pwd`/udev_rules/99-maccel.rules /usr/lib/udev/rules.d/99-maccel.rules
sudo install -m 755 -v -D `pwd`/udev_rules/maccel_bind /usr/lib/udev/maccel_bind
}

trigger_udev_rules() {
udevadm control --reload-rules
udevadm trigger --subsystem-match=usb --subsystem-match=input --subsystem-match=hid --attr-match=bInterfaceClass=03 --attr-match=bInterfaceSubClass=01 --attr-match=bInterfaceProtocol=02
}


# Run the installation
setup_dirs
install_driver
install_udev_rules

trigger_udev_rules

install_cli

echo '[Recommended] Add yourself to the "maccel" group'
echo '[Recommended] usermod -aG maccel $$USER'
4 changes: 2 additions & 2 deletions maccel-cli/src/params.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,9 @@ impl Param {
}

fn save_reset_script(&self, value: i32) -> anyhow::Result<()> {
let script_dir = "/var/lib/maccel";
let script_dir = "/var/opt/maccel/resets";
if !Path::new(script_dir).exists() {
std::fs::create_dir(script_dir).context(format!("failed create directory: {}", script_dir))
std::fs::create_dir_all(script_dir).context(format!("failed create directory: {}", script_dir))
.context("failed to create the directory where we'd save the parameter value to apply on reboot")?;
}
std::fs::write(
Expand Down
17 changes: 10 additions & 7 deletions udev_rules/maccel_bind
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,15 @@

PATH='/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/bin'

maccel bind $1 &> /var/log/maccel-cli;
chown -v :maccel /sys/module/maccel/parameters/* &> /var/log/maccel-chown;
LOG_DIR=/var/opt/maccel/logs
mkdir -p $LOG_DIR

maccel bind $1 &> $LOG_DIR/cli;
chown -v :maccel /sys/module/maccel/parameters/* &> $LOG_DIR/chown;

# For persisting parameters values across reboots
LIB_DIR=/var/lib/maccel
mkdir -p $LIB_DIR
chown -v :maccel $LIB_DIR
chmod -v g+w "$LIB_DIR"
ls $LIB_DIR/set_last_*_value.sh | xargs cat | sh &> /var/log/maccel-reset-scripts
RESET_SCRIPTS_DIR=/var/opt/maccel/resets
mkdir -p $RESET_SCRIPTS_DIR
chown -v :maccel $RESET_SCRIPTS_DIR
chmod -v g+w "$RESET_SCRIPTS_DIR"
ls $RESET_SCRIPTS_DIR/set_last_*_value.sh | xargs cat | sh &> $LOG_DIR/reset-scripts
23 changes: 23 additions & 0 deletions uninstall.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
MODULEDIR=/lib/modules/`uname -r`/kernel/drivers/usb

delete_module() {
sudo rmmod maccel
sudo rm -vf $MODULEDIR/maccel.ko
}


udev_uninstall() {
sudo maccel unbindall

sudo rm -vf /usr/lib/udev/rules.d/99-maccel.rules /usr/lib/udev/maccel_bind
sudo udevadm control --reload-rules
}

delete_everything() {
sudo rm -vf $(which maccel)
sudo rm -vrf /opt/maccel /var/opt/maccel
}

delete_module
udev_uninstall
delete_everything