diff --git a/README.md b/README.md index ea9536e..4ab52bb 100644 --- a/README.md +++ b/README.md @@ -4,6 +4,7 @@ A collection of things to enhance the capabilities of your Unifi Dream Machine o ## General Tools ### on-boot-script Enables init.d style scripts to run on every boot of your UDM. Includes a wpa-supplicant/eap-proxy example +**Persists through Firmware upgrades!!!** ### python If you need python3 on your UDM, generally not recommended, can always use it in unifi-os container diff --git a/dns-common/on_boot.d/10-dns.sh b/dns-common/on_boot.d/10-dns.sh index 981673a..466e6f2 100644 --- a/dns-common/on_boot.d/10-dns.sh +++ b/dns-common/on_boot.d/10-dns.sh @@ -72,7 +72,7 @@ fi if podman container exists ${CONTAINER}; then podman start ${CONTAINER} else - echo "Container $CONTAINER not found, make sure you set the proper name, if you have you can ignore this error" + logger Container $CONTAINER not found, make sure you set the proper name, if you have you can ignore this error fi # (optional) IPv4 force DNS (TCP/UDP 53) through DNS container diff --git a/on-boot-script/README-MANUALmd b/on-boot-script/README-MANUALmd new file mode 100644 index 0000000..548012c --- /dev/null +++ b/on-boot-script/README-MANUALmd @@ -0,0 +1,58 @@ +* NB! THESE WILL NOT PERSIST THROUGH FIRMWARE. They still work however +### Automated Setup + +1. Copy [install.sh](install.sh) to your UDM and execute it +1. Copy any shell scripts you want to run to /mnt/data/on_boot.d and make sure they are executable and have the correct shebang (#!/bin/sh) + Examples: + * Start a DNS Container [10-dns.sh](../dns-common/on_boot.d/10-dns.sh) + * Start wpa_supplicant [on_boot.d/10-wpa_supplicant.sh](examples/udm-files/on_boot.d/10-start-containers.sh) + +### Manual Setup + +1. Copy on_boot.sh and make on_boot.d and add scripts to on_boot.d + ```shell script + mkdir -p /mnt/data/on_boot.d + vi /mnt/data/on_boot.sh + chmod u+x /mnt/data/on_boot.sh + ``` + Example: [on_boot.sh](examples/udm-files/on_boot.sh) + +1. Enter the container shell + ```shell script + unifi-os shell + ``` +1. make a script that sshs to the udm and runs on our boot script. 127.0.1.1 always points to the UDM + ```shell script + 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 + ``` + Example: [udm.sh](examples/unifi-os-files/udm.sh) +1. make a service that runs on startup, after we have networking + ```shell script + 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 + ``` + Example: [udmboot.service](examples/unifi-os-files/udmboot.service) + +1. enable it and test + ```shell script + systemctl enable udmboot + systemctl start udmboot + ``` +1. back to the udm + ```shell script + exit + ``` +1. reboot your udm/udmpro and make sure it worked + ```shell script + reboot + exit + ``` diff --git a/on-boot-script/README.md b/on-boot-script/README.md index 560d751..0b9a585 100644 --- a/on-boot-script/README.md +++ b/on-boot-script/README.md @@ -1,69 +1,37 @@ # UDM / UDMPro Boot Script ### Features 1. Allows you to run a shell script at S95 anytime your UDM starts / reboots -1. Persists through reboot -1. Must be re-done after firmware updates +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 + ### Compatibility 1. Should work on any UDM/UDMPro after 1.6.3 2. Tested and confirmed on 1.6.6, 1.7.0, 1.7.2rc4, 1.7.3rc1 +### Upgrade from earlier way +* As long as you didn't change the filenames, installing the deb package is all you need to do. If you want to clean up beforehand anyways.... +``` +rm /etc/init.d/udm.sh +systemctl disable udmboot +rm /etc/systemd/system/udmboot.service +``` +* The new package is exactly the old steps packaged in a debian package +* [dpkg-build-files](dpkg-build-files) contains the scripts that build the package (using dh_make and debuild) if you want to build it yourself / change it +* Built on Ubuntu-20.04 on Windows 10/WSL2 + ## Steps - -### Automated Setup - -1. Copy [install.sh](install.sh) to your UDM and execute it -1. Copy any shell scripts you want to run to /mnt/data/on_boot.d and make sure they are executable and have the correct shebang (#!/bin/sh) +1. Get into the unifios shell on your udm +```shell script +unifi-os shell +``` +2. Download the [udm-boot_1.0.0-1_all.deb](packages/udm-boot_1.0.0-1_all.deb) and install it and go back to the UDM +```shell script +wget https://raw.githubusercontent.com/boostchicken/udm-utilities/master/on-boot-script/packages/udm-boot_1.0.0-1_all.deb +dpkg -i udm-boot_1.0.0-1_all.deb +exit +``` +3. Copy any shell scripts you want to run to /mnt/data/on_boot.d and make sure they are executable and have the correct shebang (#!/bin/sh) Examples: * Start a DNS Container [10-dns.sh](../dns-common/on_boot.d/10-dns.sh) - * Start wpa_supplicant [on_boot.d/10-wpa_supplicant.sh](examples/udm-files/on_boot.d/10-wpa_supplicant.sh) - -### Manual Setup - -1. Copy on_boot.sh and make on_boot.d and add scripts to on_boot.d - ```shell script - mkdir -p /mnt/data/on_boot.d - vi /mnt/data/on_boot.sh - chmod u+x /mnt/data/on_boot.sh - ``` - Example: [on_boot.sh](examples/udm-files/on_boot.sh) - -1. Enter the container shell - ```shell script - unifi-os shell - ``` -1. make a script that sshs to the udm and runs on our boot script. 127.0.1.1 always points to the UDM - ```shell script - 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 - ``` - Example: [udm.sh](examples/unifi-os-files/udm.sh) -1. make a service that runs on startup, after we have networking - ```shell script - 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 - ``` - Example: [udmboot.service](examples/unifi-os-files/udmboot.service) - -1. enable it and test - ```shell script - systemctl enable udmboot - systemctl start udmboot - ``` -1. back to the udm - ```shell script - exit - ``` -1. reboot your udm/udmpro and make sure it worked - ```shell script - reboot - exit - ``` + * Start wpa_supplicant [on_boot.d/10-wpa_supplicant.sh](examples/udm-files/on_boot.d/10-start-containers.sh) + \ No newline at end of file diff --git a/on-boot-script/dpkg-build-files/debian/changelog b/on-boot-script/dpkg-build-files/debian/changelog new file mode 100644 index 0000000..00e6193 --- /dev/null +++ b/on-boot-script/dpkg-build-files/debian/changelog @@ -0,0 +1,5 @@ +udm-boot (1.0.0-1) unstable; urgency=medium + + * Initial release, happy firmware persisting! + + -- Boostchicken Sun, 05 Jul 2020 18:46:14 -0700 diff --git a/on-boot-script/dpkg-build-files/debian/control b/on-boot-script/dpkg-build-files/debian/control new file mode 100644 index 0000000..cbf5539 --- /dev/null +++ b/on-boot-script/dpkg-build-files/debian/control @@ -0,0 +1,14 @@ +Source: udm-boot +Section: unknown +Priority: optional +Maintainer: Boostchicken +Build-Depends: debhelper-compat (= 12) +Standards-Version: 4.4.1 +Homepage: https://github.com/boostchicken/udm-utilities +#Vcs-Browser: https://salsa.debian.org/debian/udmboot +#Vcs-Git: https://salsa.debian.org/debian/udmboot.git + +Package: udm-boot +Architecture: all +Description: Run things on boot on UDM + Run things on boot! diff --git a/on-boot-script/dpkg-build-files/debian/copyright b/on-boot-script/dpkg-build-files/debian/copyright new file mode 100644 index 0000000..2d8063a --- /dev/null +++ b/on-boot-script/dpkg-build-files/debian/copyright @@ -0,0 +1,9 @@ +Format: https://www.debian.org/doc/packaging-manuals/copyright-format/1.0/ +Upstream-Name: udm-boot +Upstream-Contact: John Dorman / Boostchicken +Source: https://github.com/boostchicken/udm-utilities + +Files: * +Copyright: 2020 dorman@ataxia.cloud +License: GPLv3 + https://github.com/boostchicken/udm-utilities/blob/master/LICENSE diff --git a/on-boot-script/dpkg-build-files/debian/files b/on-boot-script/dpkg-build-files/debian/files new file mode 100644 index 0000000..4208e4f --- /dev/null +++ b/on-boot-script/dpkg-build-files/debian/files @@ -0,0 +1,2 @@ +udm-boot_1.0.0-1_all.deb unknown optional +udm-boot_1.0.0-1_amd64.buildinfo unknown optional diff --git a/on-boot-script/dpkg-build-files/debian/install b/on-boot-script/dpkg-build-files/debian/install new file mode 100644 index 0000000..f5d0d69 --- /dev/null +++ b/on-boot-script/dpkg-build-files/debian/install @@ -0,0 +1 @@ +udm.sh etc/init.d diff --git a/on-boot-script/dpkg-build-files/debian/postinst b/on-boot-script/dpkg-build-files/debian/postinst new file mode 100644 index 0000000..3672285 --- /dev/null +++ b/on-boot-script/dpkg-build-files/debian/postinst @@ -0,0 +1,31 @@ +#!/bin/sh + +set -e + + +case "$1" in + configure) + chmod +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 udmboot + systemctl start udmboot + ;; + + abort-upgrade|abort-remove|abort-deconfigure) + ;; + + *) + echo "postinst called with unknown argument \`$1'" >&2 + exit 1 + ;; +esac + +exit 0 diff --git a/on-boot-script/dpkg-build-files/debian/rules b/on-boot-script/dpkg-build-files/debian/rules new file mode 100644 index 0000000..5aafcca --- /dev/null +++ b/on-boot-script/dpkg-build-files/debian/rules @@ -0,0 +1,24 @@ +#!/usr/bin/make -f +# See debhelper(7) (uncomment to enable) +# output every command that modifies files on the build system. +#export DH_VERBOSE = 1 + + +# see FEATURE AREAS in dpkg-buildflags(1) +#export DEB_BUILD_MAINT_OPTIONS = hardening=+all + +# see ENVIRONMENT in dpkg-buildflags(1) +# package maintainers to append CFLAGS +#export DEB_CFLAGS_MAINT_APPEND = -Wall -pedantic +# package maintainers to append LDFLAGS +#export DEB_LDFLAGS_MAINT_APPEND = -Wl,--as-needed + + +%: + dh $@ + + +# dh_make generated override targets +# This is example for Cmake (See https://bugs.debian.org/641051 ) +#override_dh_auto_configure: +# dh_auto_configure -- # -DCMAKE_LIBRARY_PATH=$(DEB_HOST_MULTIARCH) diff --git a/on-boot-script/dpkg-build-files/debian/source/format b/on-boot-script/dpkg-build-files/debian/source/format new file mode 100644 index 0000000..163aaf8 --- /dev/null +++ b/on-boot-script/dpkg-build-files/debian/source/format @@ -0,0 +1 @@ +3.0 (quilt) diff --git a/on-boot-script/dpkg-build-files/udm.sh b/on-boot-script/dpkg-build-files/udm.sh new file mode 100644 index 0000000..7712ca1 --- /dev/null +++ b/on-boot-script/dpkg-build-files/udm.sh @@ -0,0 +1,4 @@ +#!/bin/sh + +ssh -o StrictHostKeyChecking=no root@127.0.1.1 '/mnt/data/on_boot.sh' + diff --git a/on-boot-script/packages/udm-boot_1.0.0-1_all.deb b/on-boot-script/packages/udm-boot_1.0.0-1_all.deb new file mode 100644 index 0000000..7bcb9a3 Binary files /dev/null and b/on-boot-script/packages/udm-boot_1.0.0-1_all.deb differ