From fc57b4a1aa582bded9e1b873ce2b065ce458cea9 Mon Sep 17 00:00:00 2001 From: Brett Sanderson Date: Thu, 10 Jul 2025 12:45:40 -0400 Subject: [PATCH] Avahi ssh publish (#476) * add avahi-daemon and avahi-utils * avahi override * enable avahi daemon * avahi publish * Update userspace/usr/comma/avahi-publish-service.sh Co-authored-by: Adeeb Shihadeh * Update avahi-publish-service.sh * Update userspace/files/avahi-ssh-publish.service Co-authored-by: Adeeb Shihadeh * add device alias * remove openpilot reference --------- Co-authored-by: Adeeb Shihadeh --- Dockerfile.agnos | 3 +++ userspace/files/avahi-override.conf | 3 +++ userspace/files/avahi-ssh-publish.service | 16 ++++++++++++++++ userspace/install_extras.sh | 4 +++- userspace/services.sh | 2 ++ userspace/usr/comma/avahi-publish-service.sh | 18 ++++++++++++++++++ 6 files changed, 45 insertions(+), 1 deletion(-) create mode 100644 userspace/files/avahi-override.conf create mode 100644 userspace/files/avahi-ssh-publish.service create mode 100755 userspace/usr/comma/avahi-publish-service.sh diff --git a/Dockerfile.agnos b/Dockerfile.agnos index 121cf07..09d02f0 100644 --- a/Dockerfile.agnos +++ b/Dockerfile.agnos @@ -222,6 +222,9 @@ RUN echo "precedence ::ffff:0:0/96 100" >> /etc/gai.conf # Don't let logind delete /dev/shm COPY ./userspace/files/logind.conf /etc/systemd/logind.conf +# Copy Avahi daemon override +COPY ./userspace/files/avahi-override.conf /etc/systemd/system/avahi-daemon.service.d/override.conf + # Remove qt network bearer plugins RUN rm -rf /usr/lib/aarch64-linux-gnu/qt5/plugins/bearer diff --git a/userspace/files/avahi-override.conf b/userspace/files/avahi-override.conf new file mode 100644 index 0000000..308da73 --- /dev/null +++ b/userspace/files/avahi-override.conf @@ -0,0 +1,3 @@ +[Unit] +After=network.target +Wants=network.target \ No newline at end of file diff --git a/userspace/files/avahi-ssh-publish.service b/userspace/files/avahi-ssh-publish.service new file mode 100644 index 0000000..108563d --- /dev/null +++ b/userspace/files/avahi-ssh-publish.service @@ -0,0 +1,16 @@ +[Unit] +Description=Publish comma SSH service via Avahi +After=avahi-daemon.service network.target +Requires=avahi-daemon.service +Wants=network.target +StartLimitIntervalSec=0 + +[Service] +Type=simple +ExecStart=/usr/comma/avahi-publish-service.sh +Restart=always +RestartSec=5 +User=comma + +[Install] +WantedBy=multi-user.target \ No newline at end of file diff --git a/userspace/install_extras.sh b/userspace/install_extras.sh index 45b8318..ab5c1ae 100755 --- a/userspace/install_extras.sh +++ b/userspace/install_extras.sh @@ -13,7 +13,9 @@ apt-fast update && apt-fast install -y --no-install-recommends \ ncdu \ nfs-common \ socat \ - wavemon + wavemon \ + avahi-daemon \ + avahi-utils # color prompt sed -i 's/#force_color_prompt=yes/force_color_prompt=yes/g' /home/comma/.bashrc diff --git a/userspace/services.sh b/userspace/services.sh index 94b36b5..db26c79 100755 --- a/userspace/services.sh +++ b/userspace/services.sh @@ -24,6 +24,8 @@ systemctl enable ssh-param-watcher.service systemctl enable adb-param-watcher.path systemctl enable adb-param-watcher.service systemctl enable logrotate-hourly.timer +systemctl enable avahi-daemon +systemctl enable avahi-ssh-publish.service # Disable some of our services systemctl disable agnos-tests.service diff --git a/userspace/usr/comma/avahi-publish-service.sh b/userspace/usr/comma/avahi-publish-service.sh new file mode 100755 index 0000000..b8ed8c6 --- /dev/null +++ b/userspace/usr/comma/avahi-publish-service.sh @@ -0,0 +1,18 @@ +#!/bin/bash + +# Read the raw device model +RAW_MODEL=$(tr -d '\0' < /sys/firmware/devicetree/base/model) + +# Extract the device model (e.g., tici, tizi, mici) +MODEL=$(echo "$RAW_MODEL" | sed 's/comma //g' | awk '{print $1}') + +[ -z "$MODEL" ] && MODEL="unknown" + +HOSTNAME=$(hostname) +SERVICE_NAME="comma SSH - $MODEL - [$HOSTNAME]" + +ALIAS_FILE="/data/params/d_tmp/ApiCache_Device" +ALIAS=$(jq -e -r '.alias // empty' "$ALIAS_FILE" 2>/dev/null | grep -E '\S' || echo "$RAW_MODEL") + +# Publish avahi service +exec avahi-publish -s "$SERVICE_NAME" _ssh._tcp 22 "vendor=comma" "device=comma" "model=$MODEL" "alias=$ALIAS"