mirror of
https://github.com/novatiq/packages.git
synced 2026-04-30 07:28:39 +01:00
nut: initscripts hotplug: Fix many small semantic issues
Small but important tweaks to fix the operation of the nut initscripts and hotplug scripts. All hail shellcheck and proofreading and dogfooding. Signed-off-by: Daniel F. Dickinson <cshored@thecshore.com>
This commit is contained in:
@@ -2,20 +2,33 @@
|
||||
|
||||
nut_serial() {
|
||||
local cfg="$cfg"
|
||||
config_get runas upsd runas "nut"
|
||||
local runas enable_usb_serial port
|
||||
config_get_bool enable_usb_serial "$cfg" enable_usb_serial 0
|
||||
}
|
||||
config_get port "$cfg" port
|
||||
config_get runas "$cfg" runas "nut"
|
||||
|
||||
[ "$ACTION" = "add" ] && [ -n "$DEVNAME" ] && [ -z "${DEVNAME%ttyUSB*}" ] && {
|
||||
config load nut_server
|
||||
config_foreach nut_serial driver
|
||||
|
||||
[ -z "$RUNAS" ] && {
|
||||
RUNAS="$runas"
|
||||
}
|
||||
[ -z "$runas" ] && config_get runas upsd runas "nut"
|
||||
|
||||
[ "$enable_usb_serial" -eq 1 ] && {
|
||||
chown "${RUNAS:-nut}" /dev/$DEVNAME
|
||||
chmod g+rw /dev/$DEVNAME
|
||||
# If port is specified only change tty's matching port
|
||||
if [ -n "$port" ] && [ "$port" != /dev/"$DEVNAME" ]; then
|
||||
return 0
|
||||
fi
|
||||
[ -n "$runas" ] && chgrp "$(id -gn "${runas}")" /dev/"$DEVNAME"
|
||||
chmod g+rw /dev/"$DEVNAME"
|
||||
}
|
||||
}
|
||||
|
||||
nut_on_hotplug_add() {
|
||||
. "${IPKG_INSTROOT}"/lib/functions.sh
|
||||
|
||||
config load nut_server
|
||||
config_foreach nut_serial driver
|
||||
}
|
||||
|
||||
[ "$ACTION" = "add" ] && [ -n "$DEVNAME" ] && {
|
||||
# On add of a serial port with name ttyUSB*
|
||||
[ -z "${DEVNAME%ttyUSB*}" ] && nut_on_hutplug_add
|
||||
# On add of a serial port with name ttyAMA*
|
||||
[ -z "${DEVNAME%ttyAMA*}" ] && nut_on_hutplug_add
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user