From 0d421c43ede5034594b8513ab11766828c46b1dd Mon Sep 17 00:00:00 2001 From: Alex Date: Tue, 4 Mar 2025 17:01:58 +0100 Subject: Add setup_x12 script --- scripts/p7s/x12.py | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 scripts/p7s/x12.py (limited to 'scripts/p7s/x12.py') diff --git a/scripts/p7s/x12.py b/scripts/p7s/x12.py new file mode 100644 index 00000000..3fdd1ac6 --- /dev/null +++ b/scripts/p7s/x12.py @@ -0,0 +1,20 @@ +import os +import pathlib +import subprocess +import textwrap +import tempfile + + +def setup_x12(): + switcher = pathlib.Path(__file__).parent.parent.parent / "linux" / "thinkpad_x12_fn_switcher/" + binary = pathlib.Path.home() / ".local" / "bin" / "x12_fn_switcher" + subprocess.run(["gcc", switcher / "x12_fn_switcher.c", "-o", binary, "-I/usr/include/libusb-1.0", "-lusb-1.0"], check=True) + os.chmod(binary, 0o700) + with tempfile.TemporaryDirectory() as tempdir: + tempdir = pathlib.Path(tempdir) + pathlib.Path(tempdir/ "99-thinkpad-fn.rules").write_text(textwrap.dedent(f""" + ACTION=="add", ATTRS{{idVendor}}=="17ef", ATTRS{{idProduct}}=="60fe", RUN+="{binary}" + """).lstrip()) + subprocess.run(["sudo", "cp", tempdir/ "99-thinkpad-fn.rules", "/etc/udev/rules.d/99-thinkpad-fn.rules"], check=True) + subprocess.run(["sudo", "udevadm", "control", "--reload-rules"], check=True) + subprocess.run(["sudo", "udevadm", "trigger"], check=True) -- cgit v1.2.3