From 6e751d32c0a502b5e9e413c0bc261fdfb031ca49 Mon Sep 17 00:00:00 2001 From: John Dorman Date: Sun, 5 Jul 2020 20:09:26 -0700 Subject: [PATCH] on-boot now persists through firmware updates --- .gitattributes | 1 + README.md | 1 + dns-common/on_boot.d/10-dns.sh | 2 +- on-boot-script/README-MANUALmd | 58 ++++++++++++ on-boot-script/README.md | 84 ++++++------------ .../dpkg-build-files/debian/changelog | 5 ++ .../dpkg-build-files/debian/control | 14 +++ .../dpkg-build-files/debian/copyright | 9 ++ on-boot-script/dpkg-build-files/debian/files | 2 + .../dpkg-build-files/debian/install | 1 + .../dpkg-build-files/debian/postinst | 31 +++++++ on-boot-script/dpkg-build-files/debian/rules | 24 +++++ .../dpkg-build-files/debian/source/format | 1 + on-boot-script/dpkg-build-files/udm.sh | 4 + .../packages/udm-boot_1.0.0-1_all.deb | Bin 0 -> 1964 bytes 15 files changed, 178 insertions(+), 59 deletions(-) create mode 100644 on-boot-script/README-MANUALmd create mode 100644 on-boot-script/dpkg-build-files/debian/changelog create mode 100644 on-boot-script/dpkg-build-files/debian/control create mode 100644 on-boot-script/dpkg-build-files/debian/copyright create mode 100644 on-boot-script/dpkg-build-files/debian/files create mode 100644 on-boot-script/dpkg-build-files/debian/install create mode 100644 on-boot-script/dpkg-build-files/debian/postinst create mode 100644 on-boot-script/dpkg-build-files/debian/rules create mode 100644 on-boot-script/dpkg-build-files/debian/source/format create mode 100644 on-boot-script/dpkg-build-files/udm.sh create mode 100644 on-boot-script/packages/udm-boot_1.0.0-1_all.deb diff --git a/.gitattributes b/.gitattributes index d29f870..0cb6ac2 100644 --- a/.gitattributes +++ b/.gitattributes @@ -5,4 +5,5 @@ *.yml filter=lfs diff=lfs merge=lfs -text *.conf filter=lfs diff=lfs merge=lfs -text *.gitignore filter=lfs diff=lfs merge=lfs -text +*.deb filter=lfs diff=lfs merge=lfs -text * text !filter !merge !diff 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 0000000000000000000000000000000000000000..7bcb9a3bd7f1b1a572588b459e2c3751eba1026a GIT binary patch literal 1964 zcmbu;X*3&%76)-kbB@hj-?~`=5L6IrrXkKmKHm17ZV1OnHzu5vYJjH3TX$ zAU07(Mn+2)sslZXK14=F^KAZi*V5F~gPiTo>R<8a(N@>w35<%w#72dyV*+B;6R>~% zZ=kRD=l_X5*4+~TU|XfMTC?@la-=%SvWNoynOkEZI!%GeD(eFf~Xary(m45zyCpkT`=BQowRh)2~(y@#fhLi@(6{7Q4Sf7vYV z#lK=Y?tFmk3c5pivp_e$JuHpVc*5$=Tjy}u0XwU4?@oK8Z60Zy%t6rRek(=n z5U<0r(UJ9LN}@R&LFrfCNi+EYZu5k=a+R!#9p;X(dGBu|^t`xZip2U}O~F|O&|4=i zIxdwzd>Xaq@#6{};brh?u6u%X-h;!vt7iy5-d~4-mLAHurYkH>)NE{t3%nWlVCQ zQ%0e9l@>kxErvDsYx_=4n1?aLYOIK0ry81abv2n;A_puKRkty|kV!0nu435QE0C1G z9l=zqCTYy?(7y9XXNj&haMSm~35__2+%miown&Ddumb(-qoLH>hXPc{EausM=jI9$ z%s|f<{JLu*T?PC5+Rqnz$+)s>)oBF6;<@8y1qq!W?n^U03h{4Jq05&)FTwks1!p)D z2A+JC@#C+r^~tDJei@qJ@MR&$u*uXS_ZtoicPb@d&G3d?9Aj!nhw3r$`_!*thR&k_ zBh#xVi1sQgh5ld#RM#s|J&m77DZeADGwU%W@d03fWP9QMEIY?$)40jCY#PlJe0j`- zHeraCFz=ZeQHh_Z@9*ZKT9Kn68e~LXS4~R4c1i<9wJKU=o@awNhQ0&7n$-W%z5`pk zuwBPqES95^DFt$Ks@{5^LaZdH_LvA-CQOItFKq-)=U4uwCczuSpflKkg2z8S2(b)w z*h$q=9FqEMPHuQBl(Z_?lg%FSZA+9qzf-i;nHo3V2noz3iOVnCeF!~0*m%*Hba&=7888i|HHHpuDGTM zZc96OWuTjFfD#$zXhjVNF<|2~plQd^-~eKog$rq?a%o|48+DLW-Hc(6#P3bk#Vy)K zCFk9e^@CYdZ{){bUhKI`i5L~WTclopPQq1&wX3STP6Cz^E(9Evz7!IxOg1sZs6nk+I7sVd-vPW8oJeNv_1o{CiqX@;GXf#1*6@ux5FUis+WEw~qU; z>i3Lr!LFvVottA-hx_3H&*1ARK0d|#UUX4e%C&^cNxk-y9aR;sy(3az)4eypvCV8y zu+8BeO+esi+fyZ;VtWsGsYu0G`=zIKvld$c& z#RVjl13pmH;6DOoO|p?;5Zx!IM5oQ2RLTi$ z=YNeJ$6`#nwkBXEGjrr>z-{h9*LJW%5ZPN_wjAk(XpYB;jSdkWuf><-#HI0_2YIqZ(5Cj7@*7~R7`ZFk0mTAY)~jhE`kcB^?!n|*iOm}|LtK%dmz0~6ULs5g|oik_nr z46l>c?teo2@P|4mK5UV7nY0SCKy76B)DrJoXbgU@@pzH;aXxmfvWRrX)5bjR%Xr`H R5rBpIhh1{IOY(o({Rd5^hHwA? literal 0 HcmV?d00001