Files
TTSDream/lan-ups/desktop/deploy/router/lanups-hotplug
T

34 lines
1.5 KiB
Bash

#!/bin/sh
# Sourced by OpenWrt hotplug. A separate process owns the retry lock.
case "${ACTION:-}:${PRODUCT:-}" in
add:665/5161/*|add:0665/5161/*)
if [ -n "${DEVNAME:-}" ]; then
(
lock=/var/run/lanups-router-setup.lock
mkdir "$lock" 2>/dev/null || exit 0
trap 'rmdir "$lock"' EXIT
sleep 3
if [ -f /etc/lanups/pending ]; then
LANUPS_SKIP_PACKAGES=1 /usr/sbin/lanups-router 2>&1 | logger -t lanups-router
exit
fi
[ ! -e /var/run/killpower ] && [ ! -e /var/run/nut/disable-hotplug ] || exit 0
case "$(uci -q get nut_server.h1000m.driver)" in
blazer_usb|nutdrv_qx) ;;
*) exit 0 ;;
esac
case "$DEVNAME" in bus/usb/*) ;; *) exit 0 ;; esac
[ -c "/dev/$DEVNAME" ] || exit 0
chown nut:nut "/dev/$DEVNAME" && chmod 0660 "/dev/$DEVNAME" || exit 1
for check in 1 2 3; do
upsc h1000m@127.0.0.1 ups.status >/dev/null 2>&1 && exit 0
sleep 2
done
[ ! -e /var/run/killpower ] && [ ! -e /var/run/nut/disable-hotplug ] || exit 0
logger -t lanups-router 'H1000M reconnected but NUT is offline; restarting nut-server'
/etc/init.d/nut-server restart
) </dev/null >/dev/null 2>&1 &
fi
;;
esac