blob: fa3bafeb8aa0388ff92f5de747ec0959e3cf2b63 [file] [log] [blame]
b.liue9582032025-04-17 19:18:16 +08001#!/bin/sh
2
3nut_serial() {
4 local cfg="$cfg"
5 local runas enable_usb_serial port
6 config_get_bool enable_usb_serial "$cfg" enable_usb_serial 0
7 config_get port "$cfg" port
8 config_get runas "$cfg" runas "nut"
9
10 [ -z "$runas" ] && config_get runas upsd runas "nut"
11
12 [ "$enable_usb_serial" -eq 1 ] && {
13 # If port is specified only change tty's matching port
14 if [ -n "$port" ] && [ "$port" != /dev/"$DEVNAME" ]; then
15 return 0
16 fi
17 [ -n "$runas" ] && chgrp "$(id -gn "${runas}")" /dev/"$DEVNAME"
18 chmod g+rw /dev/"$DEVNAME"
19 }
20}
21
22nut_on_hotplug_add() {
23 . "${IPKG_INSTROOT}"/lib/functions.sh
24
25 config load nut_server
26 config_foreach nut_serial driver
27}
28
29[ "$ACTION" = "add" ] && [ -n "$DEVNAME" ] && {
30 # On add of a serial port with name ttyUSB*
31 [ -z "${DEVNAME%ttyUSB*}" ] && nut_on_hutplug_add
32 # On add of a serial port with name ttyAMA*
33 [ -z "${DEVNAME%ttyAMA*}" ] && nut_on_hutplug_add
34}