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:
Daniel F. Dickinson
2019-01-16 07:09:13 -05:00
parent e549c53f36
commit d7db15459f
11 changed files with 166 additions and 126 deletions
+27 -22
View File
@@ -4,11 +4,6 @@
# See /LICENSE for more information.
#
. /lib/functions.sh
mount -o remount,ro /overlay /overlay
mount -o remount,ro / /
stop_instance() {
/etc/init.d/nut-server stop "$1"
}
@@ -16,29 +11,39 @@ stop_instance() {
shutdown_instance() {
local cfg="$1"
config_get driver "$cfg" driver "usbhid-ups"
# Only FSD if killpower was indicated
if [ -f /var/run/killpower ]; then
/lib/nut/${driver} -a "$cfg" -k
/lib/nut/"${driver}" -a "$cfg" -k
fi
}
if [ -f /var/run/killpower ]; then
if [ -f /etc/config/nut_server ]; then
config_load nut_server
do_fsd() {
if [ -f /var/run/killpower ]; then
# Only make FS readonly if we are doing an FSD
mount -o remount,ro /overlay /overlay
mount -o remount,ro / /
# Can't FSD unless drivers are stopped
config_foreach stop_instance driver
# Driver will wait 'offdelay' before shutting down
config_foreach shutdown_instance driver
# So this can happen
poweroff
# And just in case
sleep 120
# Uh-oh failed to poweroff UPS
reboot -f
. ${IPKG_INSTOOT}/lib/functions.sh
if [ -f /etc/config/nut_server ]; then
config_load nut_server
# Can't FSD unless drivers are stopped
config_foreach stop_instance driver
# Driver will wait 'offdelay' before shutting down
config_foreach shutdown_instance driver
# So this can happen
rm -f /var/run/killpower
poweroff
# And just in case
sleep 120
# Uh-oh failed to poweroff UPS
reboot -f
else
poweroff
fi
else
poweroff
fi
else
poweroff
fi
}