mirror of
https://github.com/unifi-utilities/unifios-utilities.git
synced 2024-08-30 18:32:21 +00:00
Use a shell one-liner to embed on_boot.sh logic in service file (#113)
This commit is contained in:
parent
9093ddde27
commit
2d61fe6403
@ -3,7 +3,7 @@
|
||||
## Features
|
||||
|
||||
1. Allows you to run a shell script at S95 anytime your UDM starts / reboots
|
||||
1. Persists through reboot and **firmware updates**! It is able to do this because Ubiquiti caches all debian package installs on the UDM in /mnt/data, then re-installs them on every boot
|
||||
1. Persists through reboot and **firmware updates**! It is able to do this because Ubiquiti caches all debian package installs on the UDM in /mnt/data, then re-installs them on reset of unifi-os container.
|
||||
|
||||
## Compatibility
|
||||
|
||||
|
@ -1,2 +1 @@
|
||||
on_boot.sh usr/share/udm-boot/
|
||||
udm-boot.service lib/systemd/system/
|
||||
|
@ -21,8 +21,6 @@ alias deb-systemd-invoke='systemctl --no-block --'
|
||||
|
||||
case "$1" in
|
||||
configure)
|
||||
scp -P "$(cat /etc/unifi-os/ssh_proxy_port)" -o StrictHostKeyChecking=no -q /usr/share/udm-boot/on_boot.sh root@localhost:/mnt/data/on_boot.sh
|
||||
/sbin/ssh-proxy 'chmod +x /mnt/data/on_boot.sh && mkdir -p /mnt/data/on_boot.d'
|
||||
;;
|
||||
|
||||
abort-upgrade|abort-remove|abort-deconfigure)
|
||||
|
@ -1,9 +0,0 @@
|
||||
#!/bin/sh
|
||||
|
||||
if [ -d /mnt/data/on_boot.d ]; then
|
||||
for i in /mnt/data/on_boot.d/*.sh; do
|
||||
if [ -r $i ]; then
|
||||
. $i
|
||||
fi
|
||||
done
|
||||
fi
|
@ -4,9 +4,8 @@ After=network.target
|
||||
|
||||
[Service]
|
||||
Type=oneshot
|
||||
ExecStart=/sbin/ssh-proxy '/mnt/data/on_boot.sh'
|
||||
ExecStart=/sbin/ssh-proxy 'mkdir -p /mnt/data/on_boot.d && find /mnt/data/on_boot.d -mindepth 1 -maxdepth 1 -type f -print0 | sort -z | xargs -0 -r -n 1 -- sh -c '\''if test -x "$0"; then echo "%n: running $0"; "$0"; else case "$0" in *.sh) echo "%n: sourcing $0"; . "$0";; *) echo "%n: ignoring $0";; esac; fi'\'
|
||||
RemainAfterExit=true
|
||||
StandardOutput=journal
|
||||
|
||||
[Install]
|
||||
WantedBy=multi-user.target
|
||||
|
@ -1,9 +0,0 @@
|
||||
#!/bin/sh
|
||||
|
||||
if [ -d /mnt/data/on_boot.d ]; then
|
||||
for i in /mnt/data/on_boot.d/*.sh; do
|
||||
if [ -r $i ]; then
|
||||
. $i
|
||||
fi
|
||||
done
|
||||
fi
|
@ -1,3 +0,0 @@
|
||||
#!/bin/sh
|
||||
|
||||
ssh -o StrictHostKeyChecking=no root@127.0.1.1 '/mnt/data/on_boot.sh'
|
@ -1,9 +0,0 @@
|
||||
[Unit]
|
||||
Description=Run On Startup UDM
|
||||
After=network.target
|
||||
|
||||
[Service]
|
||||
ExecStart=/etc/init.d/udm.sh
|
||||
|
||||
[Install]
|
||||
WantedBy=multi-user.target
|
@ -1,17 +0,0 @@
|
||||
#!/bin/sh
|
||||
|
||||
echo "#!/bin/sh
|
||||
ssh -o StrictHostKeyChecking=no root@127.0.1.1 '/mnt/data/on_boot.sh'" > /etc/init.d/udm.sh
|
||||
chmod u+x /etc/init.d/udm.sh
|
||||
|
||||
echo "[Unit]
|
||||
Description=Run On Startup UDM
|
||||
After=network.target
|
||||
|
||||
[Service]
|
||||
ExecStart=/etc/init.d/udm.sh
|
||||
|
||||
[Install]
|
||||
WantedBy=multi-user.target" > /etc/systemd/system/udmboot.service
|
||||
|
||||
systemctl enable --now udmboot
|
@ -1,44 +1,13 @@
|
||||
#!/bin/sh
|
||||
|
||||
echo "Creating on boot script on device"
|
||||
echo '#!/bin/sh
|
||||
# Download and install the service
|
||||
podman exec unifi-os curl -fsSLo /lib/systemd/system/udm-boot.service https://raw.githubusercontent.com/boostchicken/udm-utilities/master/on-boot-script/dpkg-build-files/udm-boot.service
|
||||
|
||||
if [ -d /mnt/data/on_boot.d ]; then
|
||||
for i in /mnt/data/on_boot.d/*.sh; do
|
||||
if [ -r $i ]; then
|
||||
. $i
|
||||
fi
|
||||
done
|
||||
fi
|
||||
' > /mnt/data/on_boot.sh
|
||||
# If you want to manually install this offline,
|
||||
# Have that file downloaded first, scp it to udm (e.g. /tmp/udm-boot.service)
|
||||
# Then copy it from host to container with this command:
|
||||
#
|
||||
# podman cp /tmp/udm-boot.service unifi-os:/lib/systemd/system/udm-boot.service
|
||||
|
||||
chmod u+x /mnt/data/on_boot.sh
|
||||
mkdir -p /mnt/data/on_boot.d
|
||||
|
||||
echo "Creating script to modify unifios container"
|
||||
echo '#!/bin/sh
|
||||
|
||||
echo "#!/bin/sh
|
||||
ssh -o StrictHostKeyChecking=no root@127.0.1.1 ''/mnt/data/on_boot.sh''" > /etc/init.d/udm.sh
|
||||
chmod u+x /etc/init.d/udm.sh
|
||||
|
||||
echo "[Unit]
|
||||
Description=Run On Startup UDM
|
||||
After=network.target
|
||||
|
||||
[Service]
|
||||
ExecStart=/etc/init.d/udm.sh
|
||||
|
||||
[Install]
|
||||
WantedBy=multi-user.target" > /etc/systemd/system/udmboot.service
|
||||
|
||||
systemctl enable --now udmboot
|
||||
' > /tmp/install-unifios.sh
|
||||
|
||||
podman cp /tmp/install-unifios.sh unifi-os:/root/install-unifios.sh
|
||||
podman exec -it unifi-os chmod +x /root/install-unifios.sh
|
||||
echo "Executing container modifications"
|
||||
podman exec -it unifi-os sh -c /root/install-unifios.sh
|
||||
rm /tmp/install-unifios.sh
|
||||
|
||||
echo "Installed on_boot hook. Populate /mnt/data/on_boot.d with scripts to run"
|
||||
# Start the service
|
||||
podman exec unifi-os systemctl enable --now udm-boot.service
|
Loading…
Reference in New Issue
Block a user