forked from networkupstools/nut
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
FreeBSD: generate devd.conf files for USB UPSes
This adds a --with-devd-dir=PATH option to ./configure, which defaults to /usr/local/etc/devd (or /etc/devd, whichever is found first). Unlike udev, there does not seem to be a way to re-trigger rules at runtime. This means you will likely need to unplug and replug your UPS after installing the new nut-usb.conf file.
- Loading branch information
Showing
7 changed files
with
99 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
nut-usb.conf* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
|
||
if WITH_DEVD | ||
devdconfdir = $(devddir) | ||
devdconf_DATA = | ||
if WITH_USB | ||
devdconf_DATA += nut-usb.conf | ||
endif | ||
endif | ||
|
||
EXTRA_DIST = README | ||
|
||
DISTCLEANFILES = nut-usb.conf | ||
# we should never remove this one, apart from a distclean-check | ||
#MAINTAINERCLEANFILES = nut-usbups.rules.in |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
On FreeBSD, devd has a similar role to udev on Linux. The devd.conf file | ||
defines actions to perform when devices are plugged in. | ||
|
||
The tools/nut-usbinfo.pl script generates nut-usb.conf.in by processing USB | ||
macros in all of the drivers. In this case, the defined action for each | ||
matching UPS is to change the permissions such that the NUT drivers can access | ||
the devices without requiring root privileges. You may need to restart devd and | ||
re-plug in the UPS to trigger the actions. | ||
|
||
The format of this configuration file should work with devd on FreeBSD 9.0 and | ||
9.1, at the very least. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,6 +3,7 @@ | |
# Copyright (C) 2008 - 2012 | ||
# Arnaud Quette <[email protected]> | ||
# dloic (loic.dardant AT gmail DOT com) | ||
# Copyright (C) 2013 - 2014 Charles Lepple <[email protected]> | ||
# | ||
# Based on the usbdevice.pl script, made for the Ubuntu Media Center | ||
# for the final use of the LIRC project. | ||
|
@@ -40,8 +41,12 @@ | |
# udev output file | ||
my $outputUdev="../scripts/udev/nut-usbups.rules.in"; | ||
|
||
# BSD devd output file | ||
my $output_devd="../scripts/devd/nut-usb.conf.in"; | ||
|
||
# UPower output file | ||
my $outputUPower="../scripts/upower/95-upower-hid.rules"; | ||
|
||
# tmp output, to allow generating the ENV{UPOWER_VENDOR} header list | ||
my $tmpOutputUPower; | ||
# mfr header flag | ||
|
@@ -109,6 +114,10 @@ sub gen_usb_files | |
print $outUdev 'SUBSYSTEM!="usb", GOTO="nut-usbups_rules_end"'."\n\n"; | ||
print $outUdev 'LABEL="nut-usbups_rules_real"'."\n"; | ||
|
||
open my $out_devd, ">$output_devd" || die "error $output_devd : $!"; | ||
print $out_devd '# This file is generated and installed by the Network UPS Tools package.'."\n"; | ||
print $out_devd "# Homepage: http://www.networkupstools.org/\n\n"; | ||
|
||
# UPower file header | ||
open my $outputUPower, ">$outputUPower" || die "error $outputUPower : $!"; | ||
print $outputUPower '##############################################################################################################'."\n"; | ||
|
@@ -147,6 +156,12 @@ sub gen_usb_files | |
print $outUdev "\n# ".$vendorName{$vendorId}."\n"; | ||
} | ||
|
||
# devd vendor header | ||
if ($vendorName{$vendorId}) { | ||
print $out_devd "\n# ".$vendorName{$vendorId}."\n"; | ||
} | ||
|
||
|
||
# UPower vendor header flag | ||
$upowerMfrHeaderDone = 0; | ||
|
||
|
@@ -172,6 +187,17 @@ sub gen_usb_files | |
print $outUdev "\", ATTR{idProduct}==\"".removeHexPrefix($productId)."\","; | ||
print $outUdev ' MODE="664", GROUP="@RUN_AS_GROUP@"'."\n"; | ||
|
||
# devd device entry | ||
print $out_devd "# ".$vendor{$vendorId}{$productId}{"comment"}.' - '.$vendor{$vendorId}{$productId}{"driver"}."\n"; | ||
print $out_devd "notify 100 {\n\tmatch \"system\"\t\t\"USB\";\n"; | ||
print $out_devd "\tmatch \"subsystem\"\t\"DEVICE\";\n"; | ||
print $out_devd "\tmatch \"type\"\t\t\"ATTACH\";\n"; | ||
print $out_devd "\tmatch \"vendor\"\t\t\"$vendorId\";\n"; | ||
# | ||
print $out_devd "\tmatch \"product\"\t\t\"$productId\";\n"; | ||
print $out_devd "\taction \"chgrp \@RUN_AS_GROUP\@ /dev/\$device-name*; chmod g+rw /dev/\$device-name*\";\n"; | ||
print $out_devd "};\n"; | ||
|
||
# UPower device entry (only for USB/HID devices!) | ||
if ($vendor{$vendorId}{$productId}{"driver"} eq "usbhid-ups") | ||
{ | ||
|