diff --git a/on-boot-script/README.md b/on-boot-script/README.md index e210f92..545169c 100644 --- a/on-boot-script/README.md +++ b/on-boot-script/README.md @@ -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 diff --git a/on-boot-script/dpkg-build-files/debian/install b/on-boot-script/dpkg-build-files/debian/install index 2b46370..bf7b7ef 100644 --- a/on-boot-script/dpkg-build-files/debian/install +++ b/on-boot-script/dpkg-build-files/debian/install @@ -1,2 +1 @@ -on_boot.sh usr/share/udm-boot/ udm-boot.service lib/systemd/system/ diff --git a/on-boot-script/dpkg-build-files/debian/postinst b/on-boot-script/dpkg-build-files/debian/postinst index 44f05fd..463d38f 100644 --- a/on-boot-script/dpkg-build-files/debian/postinst +++ b/on-boot-script/dpkg-build-files/debian/postinst @@ -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) diff --git a/on-boot-script/dpkg-build-files/on_boot.sh b/on-boot-script/dpkg-build-files/on_boot.sh deleted file mode 100755 index 7058b2e..0000000 --- a/on-boot-script/dpkg-build-files/on_boot.sh +++ /dev/null @@ -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 diff --git a/on-boot-script/dpkg-build-files/udm-boot.service b/on-boot-script/dpkg-build-files/udm-boot.service index 136229e..29af610 100644 --- a/on-boot-script/dpkg-build-files/udm-boot.service +++ b/on-boot-script/dpkg-build-files/udm-boot.service @@ -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 diff --git a/on-boot-script/examples/udm-files/on_boot.sh b/on-boot-script/examples/udm-files/on_boot.sh deleted file mode 100644 index f41f6f4..0000000 --- a/on-boot-script/examples/udm-files/on_boot.sh +++ /dev/null @@ -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 diff --git a/on-boot-script/examples/unifi-os-files/udm.sh b/on-boot-script/examples/unifi-os-files/udm.sh deleted file mode 100644 index 0c217c5..0000000 --- a/on-boot-script/examples/unifi-os-files/udm.sh +++ /dev/null @@ -1,3 +0,0 @@ -#!/bin/sh - -ssh -o StrictHostKeyChecking=no root@127.0.1.1 '/mnt/data/on_boot.sh' diff --git a/on-boot-script/examples/unifi-os-files/udmboot.service b/on-boot-script/examples/unifi-os-files/udmboot.service deleted file mode 100644 index b7f9a5b..0000000 --- a/on-boot-script/examples/unifi-os-files/udmboot.service +++ /dev/null @@ -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 diff --git a/on-boot-script/manual-install/install-unifios.sh b/on-boot-script/manual-install/install-unifios.sh deleted file mode 100644 index 6b07721..0000000 --- a/on-boot-script/manual-install/install-unifios.sh +++ /dev/null @@ -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 diff --git a/on-boot-script/manual-install/install.sh b/on-boot-script/manual-install/install.sh index a572d12..2d8e1f3 100644 --- a/on-boot-script/manual-install/install.sh +++ b/on-boot-script/manual-install/install.sh @@ -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" \ No newline at end of file +# Start the service +podman exec unifi-os systemctl enable --now udm-boot.service \ No newline at end of file