Skip to content

Instantly share code, notes, and snippets.

@joshuaspence
Last active February 2, 2024 13:37
Show Gist options
  • Save joshuaspence/a745426ab7d72631b1a4313f15e1774a to your computer and use it in GitHub Desktop.
Save joshuaspence/a745426ab7d72631b1a4313f15e1774a to your computer and use it in GitHub Desktop.
UXG on-boot-script

on-boot-script is a popular method for extending the UniFi Dream Machine to execute init.d style scripts on boot. It works by installing a custom systemd service into the unifi-os container, but this method doesn't work on the UXG-Pro. The bootstrap.sh script below allows similar functionality to work on the UXG-Pro using a different approach (modify the Docker entrypoint script in the main uxg-setup container).

To install, either copy bootstrap.sh onto the UXG-Pro and execute it with sh bootstrap.sh or execute the script directly with curl -LsS https://gist.github.com/joshuaspence/a745426ab7d72631b1a4313f15e1774a/raw/bootstrap.sh | sh.

#!/bin/sh
set -e
set -u
set -o pipefail
cat << 'EOD' > /tmp/docker-entrypoint.sh
#!/bin/sh
# Wait for SSH to be ready.
timeout 20 bash <<- 'EOF'
until printf '' 2>/dev/null >/dev/tcp/localhost/22; do
sleep 1
done
EOF
# Execute boot scripts.
ssh -o StrictHostKeyChecking=no -q localhost <<- 'EOF'
mkdir -p /mnt/data/on_boot.d
find -L /mnt/data/on_boot.d -mindepth 1 -maxdepth 1 -type f -print0 | sort -z | xargs -0 -r -n 1 -- sh -c "$(cat <<- 'EOT'
if test -x "${0}"; then
echo "running ${0}"
"${0}"
else
case "${0}" in
*.sh)
echo "sourcing ${0}"
. "${0}"
;;
*)
echo "ignoring ${0}"
;;
esac
fi
EOT
)"
EOF
set -e
if [ "${1#-}" != "${1}" ] || [ -z "$(command -v "${1}")" ]; then
set -- node "$@"
fi
exec "$@"
EOD
chmod +x /tmp/docker-entrypoint.sh
podman cp --pause=false /tmp/docker-entrypoint.sh uxg-setup:/usr/local/bin
uxg-setup restart
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment