Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions debian/arduino-app-cli/DEBIAN/postinst
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ chown -R arduino:arduino /home/arduino/.local/share/arduino-app-cli

systemctl enable arduino-app-cli
systemctl enable arduino-burn-bootloader
systemctl enable arduino-avahi-serial.service
1 change: 1 addition & 0 deletions debian/arduino-app-cli/DEBIAN/prerm
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@

systemctl disable arduino-app-cli
systemctl disable arduino-burn-bootloader
systemctl disable arduino-avahi-serial.service
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
[Unit]
Description=Configure Avahi with board serial number
Before=avahi-daemon.service
ConditionPathExists=!/var/lib/arduino-app-cli/avahi_serial_configured.flag

[Service]
Type=oneshot
RemainAfterExit=true
ExecStart=/var/lib/arduino-app-cli/arduino-avahi-serial.sh
ExecStartPost=/bin/mkdir -p /var/lib/arduino-app-cli
ExecStartPost=/bin/touch /var/lib/arduino-app-cli/avahi_serial_configured.flag

StandardOutput=journal
StandardError=journal

[Install]
WantedBy=multi-user.target
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#!/bin/sh
# Configure Avahi with the serial number.


TARGET_FILE="/etc/avahi/services/arduino.service"
SERIAL_NUMBER_PATH="/sys/devices/soc0/serial_number"

echo "Configuring Avahi with serial number for network discovery..."

if [ ! -f "$SERIAL_NUMBER_PATH" ]; then
echo "Error: Serial number path not found at $SERIAL_NUMBER_PATH." >&2
exit 1
fi


if [ ! -w "$TARGET_FILE" ]; then
echo "Error: Target file $TARGET_FILE not found or not writable." >&2
exit 1
fi

SERIAL_NUMBER=$(cat "$SERIAL_NUMBER_PATH")

if [ -z "$SERIAL_NUMBER" ]; then
echo "Error: Serial number file is empty." >&2
exit 1
fi

if grep -q "serial_number=" "$TARGET_FILE"; then
echo "Serial number ($SERIAL_NUMBER) already configured."
exit 0
fi

echo "Adding serial number to $TARGET_FILE..."
sed -i "/<\/service>/i <txt-record>serial_number=${SERIAL_NUMBER}<\/txt-record>" "$TARGET_FILE"

echo "Avahi configuration attempt finished."
exit 0