|
|
|
@ -23,7 +23,9 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import sys
|
|
|
|
|
import os
|
|
|
|
|
import atexit
|
|
|
|
|
import grp
|
|
|
|
|
from argparse import ArgumentParser
|
|
|
|
|
|
|
|
|
|
import gi
|
|
|
|
@ -35,9 +37,27 @@ from keymapper.logger import update_verbosity, log_info, \
|
|
|
|
|
add_filehandler, logger
|
|
|
|
|
from keymapper.daemon import Daemon, BUS_NAME
|
|
|
|
|
from keymapper.state import system_mapping
|
|
|
|
|
from keymapper.paths import USER
|
|
|
|
|
from keymapper.dev.permissions import can_read_devices
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def run(cmd):
|
|
|
|
|
"""Run and log a command."""
|
|
|
|
|
logger.info('Running `%s`...', cmd)
|
|
|
|
|
code = os.system(cmd)
|
|
|
|
|
if code != 0:
|
|
|
|
|
logger.error('Failed. exit code %d', code)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def group_exists(name):
|
|
|
|
|
"""Check if a group with that name exists."""
|
|
|
|
|
try:
|
|
|
|
|
grp.getgrnam(name)
|
|
|
|
|
return True
|
|
|
|
|
except KeyError:
|
|
|
|
|
return False
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
|
parser = ArgumentParser()
|
|
|
|
|
parser.add_argument(
|
|
|
|
@ -50,6 +70,14 @@ if __name__ == '__main__':
|
|
|
|
|
help='Print all available names for the mapping',
|
|
|
|
|
default=False
|
|
|
|
|
)
|
|
|
|
|
parser.add_argument(
|
|
|
|
|
'-s', '--setup-permissions', action='store_true', dest='setup',
|
|
|
|
|
help=(
|
|
|
|
|
'Requires sudo. Sets up all needed permissions to run'
|
|
|
|
|
'key-mapper as regular user'
|
|
|
|
|
),
|
|
|
|
|
default=False
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
options = parser.parse_args(sys.argv[1:])
|
|
|
|
|
|
|
|
|
@ -62,6 +90,26 @@ if __name__ == '__main__':
|
|
|
|
|
print('\n'.join(system_mapping.list_names()))
|
|
|
|
|
sys.exit(0)
|
|
|
|
|
|
|
|
|
|
if options.setup:
|
|
|
|
|
if os.environ['USER'] != 'root' or USER == 'root':
|
|
|
|
|
# USER should contain the actual non-root user
|
|
|
|
|
logger.error('This only works using sudo')
|
|
|
|
|
sys.exit(1)
|
|
|
|
|
|
|
|
|
|
if group_exists('input'):
|
|
|
|
|
run('usermod -a -G input $USER')
|
|
|
|
|
|
|
|
|
|
if group_exists('plugdev'):
|
|
|
|
|
run('usermod -a -G plugdev $USER')
|
|
|
|
|
|
|
|
|
|
run('setfacl -m u:$USER:rw- /dev/uinput')
|
|
|
|
|
|
|
|
|
|
logger.info(
|
|
|
|
|
'For these changes to take effect log out and in. '
|
|
|
|
|
'In some environments you may need to reboot.'
|
|
|
|
|
)
|
|
|
|
|
sys.exit(0)
|
|
|
|
|
|
|
|
|
|
can_read_devices()
|
|
|
|
|
|
|
|
|
|
bus = SessionBus()
|
|
|
|
|