File tree Expand file tree Collapse file tree 4 files changed +56
-0
lines changed Expand file tree Collapse file tree 4 files changed +56
-0
lines changed Original file line number Diff line number Diff line change @@ -4,3 +4,4 @@ chown -R arduino:arduino /home/arduino/.local/share/arduino-app-cli
44
55systemctl enable arduino-app-cli
66systemctl enable arduino-burn-bootloader
7+ systemctl enable arduino-avahi-serial.service
Original file line number Diff line number Diff line change 22
33systemctl disable arduino-app-cli
44systemctl disable arduino-burn-bootloader
5+ systemctl disable arduino-avahi-serial.service
Original file line number Diff line number Diff line change 1+ [Unit]
2+ Description =Configure Avahi with board serial number
3+ Before =avahi-daemon.service
4+ ConditionPathExists =!/var/lib/arduino-app-cli/avahi_serial_configured.flag
5+
6+ [Service]
7+ Type =oneshot
8+ RemainAfterExit =true
9+ ExecStart =/var/lib/arduino-app-cli/arduino-avahi-serial.sh
10+ ExecStartPost =/bin/mkdir -p /var/lib/arduino-app-cli
11+ ExecStartPost =/bin/touch /var/lib/arduino-app-cli/avahi_serial_configured.flag
12+
13+ StandardOutput =journal
14+ StandardError =journal
15+
16+ [Install]
17+ WantedBy =multi-user.target
Original file line number Diff line number Diff line change 1+ #! /bin/sh
2+ # Configure Avahi with the serial number.
3+
4+
5+ TARGET_FILE=" /etc/avahi/services/arduino.service"
6+ SERIAL_NUMBER_PATH=" /sys/devices/soc0/serial_number"
7+
8+ echo " Configuring Avahi with serial number for network discovery..."
9+
10+ if [ ! -f " $SERIAL_NUMBER_PATH " ]; then
11+ echo " Error: Serial number path not found at $SERIAL_NUMBER_PATH ." >&2
12+ exit 1
13+ fi
14+
15+
16+ if [ ! -w " $TARGET_FILE " ]; then
17+ echo " Error: Target file $TARGET_FILE not found or not writable." >&2
18+ exit 1
19+ fi
20+
21+ SERIAL_NUMBER=$( cat " $SERIAL_NUMBER_PATH " )
22+
23+ if [ -z " $SERIAL_NUMBER " ]; then
24+ echo " Error: Serial number file is empty." >&2
25+ exit 1
26+ fi
27+
28+ if grep -q " serial_number=" " $TARGET_FILE " ; then
29+ echo " Serial number ($SERIAL_NUMBER ) already configured."
30+ exit 0
31+ fi
32+
33+ echo " Adding serial number to $TARGET_FILE ..."
34+ sed -i " /<\/service>/i <txt-record>serial_number=${SERIAL_NUMBER} <\/txt-record>" " $TARGET_FILE "
35+
36+ echo " Avahi configuration attempt finished."
37+ exit 0
You can’t perform that action at this time.
0 commit comments