nut: Optionally set serial USB to NUT user

When using serial-port based UPSes with NUT, it is handy to be able to
configure a USB serial port to have be set tot the NUT runas user, so
that NUT can access the serial port automagically.
Closes #6997

Signed-off-by: Daniel F. Dickinson <cshored@thecshore.com>
This commit is contained in:
Daniel F. Dickinson
2018-12-05 01:36:45 -05:00
parent 18a10cec48
commit a5d06ce110
2 changed files with 24 additions and 1 deletions
+21
View File
@@ -0,0 +1,21 @@
#!/bin/sh
nut_serial() {
local cfg="$cfg"
config_get runas upsd runas "nut"
config_get_bool enable_usb_serial "$cfg" enable_usb_serial 0
}
[ "$ACTION" = "add" ] && [ -n "$DEVNAME" ] && [ -z "${DEVNAME%ttyUSB*}" ] && {
config load nut_server
config_foreach nut_serial driver
[ -z "$RUNAS" ] && {
RUNAS="$runas"
}
[ "$enable_usb_serial" -eq 1 ] && {
chown "${RUNAS:-nut}" /dev/$DEVNAME
chmod g+rw /dev/$DEVNAME
}
}