From: Alex Date: Tue, 4 Mar 2025 16:01:58 +0000 (+0100) Subject: Add setup_x12 script X-Git-Url: https://xn--ix-yja.es/gitweb/?a=commitdiff_plain;h=0d421c43ede5034594b8513ab11766828c46b1dd;p=alex.git Add setup_x12 script --- diff --git a/scripts/p7s/x12.py b/scripts/p7s/x12.py new file mode 100644 index 0000000..3fdd1ac --- /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) diff --git a/scripts/pyproject.toml b/scripts/pyproject.toml index af6196d..c775609 100644 --- a/scripts/pyproject.toml +++ b/scripts/pyproject.toml @@ -29,4 +29,5 @@ setup_bash = 'p7s.bash:setup_bash' setup_emacs = 'p7s.emacs:setup_emacs' setup_ubpkg = 'p7s.ubpkg:setup_ubpkg' setup_paperwm = 'p7s.paperwm:setup_paperwm' +setup_x12 = 'p7s.x12:setup_x12' update_zfs = 'p7s.zfs:update_zfs'