#!/bin/bash # # vim:shiftwidth=2:tabstop=2:expandtab:textwidth=80:softtabstop=4:ai # # This script generates udev and/or policykit rules for Logitech Harmony # devices. # # This script is loosely-based on scripts by Douglas E. Warner # # # GPLv2 # # Copyright 2009 Phil Dibowitz # # CONDITIONS # varios "conditions" to make udev rules # A partial template, used largely when generating one-line per device UDEV_CONDITION_PARTIAL_TEMPLATE='ATTR{idVendor}=="%s", ATTR{idProduct}=="%s"' # The above, but also with a USB specifier, for the one-line-for-all version UDEV_CONDITION_TEMPLATE="SUBSYSTEM==\"usb\", $UDEV_CONDITION_PARTIAL_TEMPLATE" # The older syntax for ancient udev. This one is also "partial" since you # have to specify each device ID separately on this version of udev. UDEV_CONDITION_OLD_TEMPLATE='SYSFS{idVendor}=="%s", SYSFS{idProduct}=="%s"' # ACTIONS # The "action" part of udev rules. # When using udev-acl, this instructs it to give access to the current # console user. UDEV_ACTION='ENV{ID_REMOTE_CONTROL}="1"' # This says give r/w to the dialout group UDEV_ACTION_GENERIC='MODE="0660", GROUP="dialout"' # This says make a symlink in /dev called "harmony-" UDEV_ACTION_POLICYKIT='SYMLINK+="harmony-%%k"' # Stuff for HAL. Deprecated. HAL_PRE_TEMPLATE=' ' HAL_RULE_TEMPLATE=' access_control linux.device_file libconcord ' HAL_POST=' ' NATIONAL_VID='0400' NATIONAL_PID='c359' LOGITECH_VID='046d' LOGITECH_MIN_PID='c110' LOGITECH_MAX_PID='c14f' LOGITECH_PID_GLOB='c1[1-4][0-9a-f]' UDEV_FILE='libconcord.rules' UDEV_USBNET_FILE='libconcord-usbnet.rules' HAL_POLICY_FILE='libconcord.fdi' POLICYKIT_FILE='org.freedesktop.hal.device-access.libconcord.policy' CONSOLEKIT_FILE='libconcord.perms' # # GENERAL FUNCTIONS # emit_for_all() { file="$1" template="$2" include_vid="$3" printf "$template\n" $NATIONAL_VID $NATIONAL_PID >>$file for pid in `seq 0x$LOGITECH_MIN_PID 0x$LOGITECH_MAX_PID`; do pid=`printf "%x" $pid` if [ "$include_vid" == 'yes' ] ; then printf "$template\n" $LOGITECH_VID $pid >>$file else printf "$template\n" $pid >>$file fi done } # # UDEV FUNCTIONS # emit_old_udev_header() { file="$1" cat >$file <>$file <>$file printf "$template\n" $LOGITECH_VID $LOGITECH_PID_GLOB >>$file } # Rule for the usbnet family of remotes to start a DHCP daemon upon detection. emit_udev_usbnet_rules() { file="$1" cat >$file <$file < END printf "$HAL_PRE_TEMPLATE\n" $LOGITECH_VID >>$file } emit_hal_policy_footer() { printf "$HAL_POST\n" >>$file file="$1" cat >>$file < END } emit_hal_policy_rules() { file="$1" emit_for_all $file "$HAL_RULE_TEMPLATE" } create_hal_policy_file() { echo -n "Creating hal policy file: $HAL_POLICY_FILE ... " emit_hal_policy_header $HAL_POLICY_FILE emit_hal_policy_rules $HAL_POLICY_FILE emit_hal_policy_footer $HAL_POLICY_FILE echo 'done' } # # POLICYKIT FUNCITONS # emit_policykit() { file="$1" cat >$file < Directly access the Logitech Harmony remote System policy prevents access to the Logitech Harmony remote no yes END } create_policykit_file() { echo -n "Creating PolicyKit file: $POLICYKIT_FILE ..." emit_policykit $POLICYKIT_FILE echo ' done' } # # CONSOLEKIT # emit_perms() { file="$1" cat >$file <=/dev/harmony* 0600 0600 root END } create_perms_file() { echo -n "Creating perms file: $CONSOLEKIT_FILE ..." emit_perms $CONSOLEKIT_FILE echo ' done' } # # OTHER FUNCTIONS # usage() { echo "Usage: $0 <-u|-p|-c|-o>" } # # MAIN # while getopts cgopu opt; do case $opt in c) MODE='consolekit' ;; g) MODE='generic_udev' ;; o) MODE='old_udev' ;; p) MODE='policykit' ;; u) MODE='udev' ;; *) usage exit 1 ;; esac done if [ "$MODE" == '' ]; then usage exit 1 fi create_udev_files $MODE if [ "$MODE" == 'policykit' ]; then create_hal_policy_file create_policykit_file elif [ "$MODE" == 'consolekit' ]; then create_perms_file fi