mirror of
https://github.com/novatiq/packages.git
synced 2026-04-30 07:28:39 +01:00
nut: Add USB hotplug support
usbhid-ups has the necessary information in the source, so let's support USB hotplugging out of the box. Takes advantage of the procd support now in nut-server initscript. Signed-off-by: Daniel F. Dickinson <cshored@thecshore.com>
This commit is contained in:
Executable
+51
@@ -0,0 +1,51 @@
|
||||
#!/bin/sh
|
||||
|
||||
. /lib/functions.sh
|
||||
|
||||
nut_driver_config() {
|
||||
local cfg="$1"
|
||||
local nomatch="$2"
|
||||
|
||||
config_get runas "$cfg" runas "nut"
|
||||
config_get vendorid "$cfg" vendorid
|
||||
config_get productid "$cfg" productid
|
||||
|
||||
[ "$ACTION" = "add" ] &&[ -n "$DEVNAME" ] && {
|
||||
chmod 0660 /dev/"$DEVNAME"
|
||||
chown ${runas:-root}:$(id -gn "${runas:-root}") /dev/"$DEVNAME"
|
||||
}
|
||||
|
||||
if [ "$(printf "%04x" 0x"$pvendid")" = "$vendorid" ] && \
|
||||
[ "$(printf "%04x" 0x"$pprodid")" = "$productid" ]; then
|
||||
[ "$ACTION" = "add" ] && {
|
||||
/etc/init.d/nut-server start "$cfg"
|
||||
}
|
||||
[ "$ACTION" = "remove" ] && {
|
||||
/etc/init.d/nut-server stop "$cfg"
|
||||
}
|
||||
found=1
|
||||
elif [ "$nomatch" = "1" ]; then
|
||||
[ "$ACTION" = "add" ] && {
|
||||
/etc/init.d/nut-server start "$cfg"
|
||||
}
|
||||
[ "$ACTION" = "remove" ] && {
|
||||
/etc/init.d/nut-server stop "$cfg"
|
||||
}
|
||||
fi
|
||||
}
|
||||
|
||||
perform_libhid_action() {
|
||||
local vendorid productid runas
|
||||
local pvendid pprodid found
|
||||
|
||||
pvendid=${PRODUCT%/*}
|
||||
pvendid=${pvendid%/*}
|
||||
pprodid=${PRODUCT%/*}
|
||||
pprodid=${pprodid##*/}
|
||||
|
||||
config_load nut_server
|
||||
config_foreach nut_driver_config driver 0
|
||||
[ "$found" != "1" ] && config_foreach nut_driver_config driver 1
|
||||
}
|
||||
|
||||
[ -n "$PRODUCT" ] && case "$PRODUCT" in
|
||||
Reference in New Issue
Block a user