From df1de585f6f1b1aab2feb1e5882332249ab8c3b6 Mon Sep 17 00:00:00 2001 From: Jake Howard Date: Thu, 19 May 2016 14:20:32 +0100 Subject: [PATCH] Add installation of udev rule --- requirements.txt | 1 + yubi_lock/cli.py | 2 +- yubi_lock/data/85-yubikey-screen-lock.rules | 2 ++ yubi_lock/install/__init__.py | 0 yubi_lock/install/cli.py | 15 +++++++++++++++ 5 files changed, 19 insertions(+), 1 deletion(-) create mode 100644 yubi_lock/data/85-yubikey-screen-lock.rules create mode 100644 yubi_lock/install/__init__.py create mode 100644 yubi_lock/install/cli.py diff --git a/requirements.txt b/requirements.txt index 48f0e1a..d3eb66b 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,3 +1,4 @@ click==6.6 flake8==2.5.4 python-yubico==1.3.2 +sh==1.11 diff --git a/yubi_lock/cli.py b/yubi_lock/cli.py index cc879b4..97d5878 100644 --- a/yubi_lock/cli.py +++ b/yubi_lock/cli.py @@ -11,7 +11,7 @@ logging.getLogger("requests").setLevel(logging.WARNING) class YubiLockCLI(click.MultiCommand): def list_commands(self, ctx): - return ['status'] + return ['status', 'install'] def get_command(self, ctx, name): ns = {} diff --git a/yubi_lock/data/85-yubikey-screen-lock.rules b/yubi_lock/data/85-yubikey-screen-lock.rules new file mode 100644 index 0000000..66160f0 --- /dev/null +++ b/yubi_lock/data/85-yubikey-screen-lock.rules @@ -0,0 +1,2 @@ +SUBSYSTEM=="usb", ACTION=="remove", ENV{ID_VENDOR_ID}=="1050", RUN+="yubi-lock handle enable" +SUBSYSTEM=="usb", ACTION=="add", ENV{ID_VENDOR_ID}=="1050", RUN+="yubi-lock handle disable" diff --git a/yubi_lock/install/__init__.py b/yubi_lock/install/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/yubi_lock/install/cli.py b/yubi_lock/install/cli.py new file mode 100644 index 0000000..89c221c --- /dev/null +++ b/yubi_lock/install/cli.py @@ -0,0 +1,15 @@ +import click +from sh import sudo +import os + + +BASE_DIR = os.path.dirname(os.path.realpath(__file__)) + + +@click.command('install', short_help='Install required files for insertion detection') +@click.option('-v', '--verbose') +def cli(verbose): + if verbose: + print("Exporting UDEV rule...") + sudo.cp(BASE_DIR + "../data/85-yubikey-screen-lock.rules", "/etc/udev/rules.d/85-yubikey-screen-lock.rules") + print('Export complete!')