From 6f01afd72b2c448b11e0200fd5bea65b4e7ed1ad Mon Sep 17 00:00:00 2001 From: Chris Blake Date: Tue, 18 Jun 2024 19:26:12 -0500 Subject: [PATCH] fix: migrate UNVR init logic Let's keep ulcmd for the pro only, and move LED stuff elsewhere. --- .../etc/systemd/system/ulcmd.service | 2 +- .../filesystem/usr/lib/init/boot/ubnt-init.sh | 8 ++++ .../usr/lib/init/boot/ubnt-ulcmd.sh | 39 +++++++------------ scripts/docker/bootstrap/001-bootstrap | 2 +- scripts/docker/run_debootstrap.sh | 4 +- 5 files changed, 26 insertions(+), 29 deletions(-) diff --git a/overlay/filesystem/etc/systemd/system/ulcmd.service b/overlay/filesystem/etc/systemd/system/ulcmd.service index 6aaa00e..344cae2 100644 --- a/overlay/filesystem/etc/systemd/system/ulcmd.service +++ b/overlay/filesystem/etc/systemd/system/ulcmd.service @@ -1,5 +1,5 @@ [Unit] -Description=Unifi LED/ULCMD contoller +Description=Unifi ULCMD contoller Requires=ubnt-init.service Requires=mock-ubnt-api.service diff --git a/overlay/filesystem/usr/lib/init/boot/ubnt-init.sh b/overlay/filesystem/usr/lib/init/boot/ubnt-init.sh index 8976a19..21752a1 100755 --- a/overlay/filesystem/usr/lib/init/boot/ubnt-init.sh +++ b/overlay/filesystem/usr/lib/init/boot/ubnt-init.sh @@ -11,10 +11,18 @@ case "$1" in # Setup bluetooth hci0 device /usr/lib/init/boot/ubnt-bt.sh hci0 + + # If UNVR, turn on LED + if [ -f "/sys/class/leds/ulogo_ctrl/pattern" ]; then + # Set boot LED to blue + # 2=white, 1=blue, 0=off, needs a value set with :x for ms + echo 1:500 > /sys/class/leds/ulogo_ctrl/pattern + fi ;; stop) # Tear down BT hciconfig hci0 down + # LED shutdown on UNVR4 is done via systemd/system-shutdown/unifi-shutdown ;; *) echo "Invalid command $1" diff --git a/overlay/filesystem/usr/lib/init/boot/ubnt-ulcmd.sh b/overlay/filesystem/usr/lib/init/boot/ubnt-ulcmd.sh index ec95b34..0095a4f 100755 --- a/overlay/filesystem/usr/lib/init/boot/ubnt-ulcmd.sh +++ b/overlay/filesystem/usr/lib/init/boot/ubnt-ulcmd.sh @@ -1,29 +1,16 @@ #!/bin/bash -# ULCMD wrapper, used to start ulcmd on the UNVR Pro, or setup the status LED on the UNVR-4 +# ULCMD wrapper, used to start ulcmd on the UNVR Pro -case "$(ubnteeprom -systeminfo -key shortname)" in - "UNVRPRO") - # Ensure our tmp file with info is generated - ubnteeprom -systeminfo > /tmp/.ubnthal_system_info - # Is ulcmd running already? if so, assume it was not done via systemd so let's - # kill and respawn as this is our systemd entry script for the service, and we - # need to have it foregrounded as we act as the "daemon" here. - if pidof -q ulcmd; then - killall ulcmd - fi - # Restart ulcmd - exec ulcmd - ;; - "UNVR4") - # 2=white, 1=blue, 0=off, needs a value set with :x for ms - echo 1:500 > /sys/class/leds/ulogo_ctrl/pattern - # Start our "daemon" loop so systemd stays happy - while true; do - sleep 3600 - done - ;; - *) - exit 1 - ;; -esac +# Ensure our tmp file with info is generated for our patched ulcmd +ubnteeprom -systeminfo > /tmp/.ubnthal_system_info + +# Is ulcmd running already? if so, assume it was not done via systemd so let's +# kill and respawn as this is our systemd entry script for the service, and we +# need to have it foregrounded as we act as the "daemon" here. +if pidof -q ulcmd; then + killall ulcmd +fi + +# Start ulcmd +exec ulcmd diff --git a/scripts/docker/bootstrap/001-bootstrap b/scripts/docker/bootstrap/001-bootstrap index 29db05e..3a00c92 100755 --- a/scripts/docker/bootstrap/001-bootstrap +++ b/scripts/docker/bootstrap/001-bootstrap @@ -21,11 +21,11 @@ apt-mark hold linux-image-* # We do not want these, as we run our own kernel! # Setup our services systemctl enable ubnt-init systemctl enable unvr-fan-daemon -systemctl enable ulcmd # This runs ubnt-ulcmd.sh! # Do we have ulcmd? if so, we are UNVRPRO so enable ulcmd services if [ -f "/usr/bin/ulcmd" ]; then systemctl enable mock-ubnt-api + systemctl enable ulcmd systemctl enable ulcmd-reboot-hook systemctl enable ulcmd-shutdown-hook fi diff --git a/scripts/docker/run_debootstrap.sh b/scripts/docker/run_debootstrap.sh index b053fc1..a05b189 100755 --- a/scripts/docker/run_debootstrap.sh +++ b/scripts/docker/run_debootstrap.sh @@ -63,12 +63,14 @@ else # Remove UNVRPRO specific files/services rm "${build_path}/rootfs/etc/ld.so.conf.d/ubnt.conf" \ "${build_path}/rootfs/etc/systemd/system/mock-ubnt-api.service" \ + "${build_path}/rootfs/etc/systemd/system/ulcmd.service" \ "${build_path}/rootfs/etc/systemd/system/ulcmd-reboot-hook.service" \ "${build_path}/rootfs/etc/systemd/system/ulcmd-shutdown-hook.service" \ "${build_path}/rootfs/usr/bin/mock-ubnt-api" \ "${build_path}/rootfs/usr/bin/ubnt-systool" \ "${build_path}/rootfs/usr/bin/ubnt-tools" \ - "${build_path}/rootfs/usr/bin/ustorage" + "${build_path}/rootfs/usr/bin/ustorage" \ + "${build_path}/rootfs/usr/lib/init/boot/ubnt-ulcmd.sh" fi # Copy over bluetooth firmware files