File tree Expand file tree Collapse file tree 3 files changed +64
-0
lines changed Expand file tree Collapse file tree 3 files changed +64
-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 1+ [Unit]
2+ Description =Configure Avahi with board serial number
3+ After =avahi-daemon.service
4+ ConditionPathExists =!/var/lib/arduino/avahi_serial_configured.flag
5+
6+ [Service]
7+ Type =oneshot
8+ RemainAfterExit =true
9+ ExecStart =/usr/sbin/arduino-avahi-serial.sh
10+ ExecStartPost =/bin/mkdir -p /var/lib/arduino
11+ ExecStartPost =/bin/touch /var/lib/arduino/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+ #
3+ # Configure Avahi with the serial number.
4+ # This operation is non-blocking: if it fails,
5+ # the script will exit with success in order to
6+ # not to interrupt the post-install process.
7+ #
8+
9+ TARGET_FILE=" /etc/avahi/services/arduino.service"
10+ MARKER_LINE=" </service>"
11+ SERIAL_NUMBER_PATH=" /sys/devices/soc0/serial_number"
12+
13+ echo " Configuring Avahi with serial number for network discovery..."
14+
15+ if [ ! -f " $SERIAL_NUMBER_PATH " ]; then
16+ echo " Warning: Serial number path not found at $SERIAL_NUMBER_PATH . Skipping." >&2
17+ exit 0
18+ fi
19+
20+
21+ if [ ! -w " $TARGET_FILE " ]; then
22+ echo " Warning: Target file $TARGET_FILE not found or not writable. Skipping." >&2
23+ exit 0
24+ fi
25+
26+ SERIAL_NUMBER=$( cat " $SERIAL_NUMBER_PATH " )
27+
28+ if [ -z " $SERIAL_NUMBER " ]; then
29+ echo " Warning: Serial number file is empty. Skipping." >&2
30+ exit 0
31+ fi
32+
33+ if grep -q " serial_number=${SERIAL_NUMBER} " " $TARGET_FILE " ; then
34+ echo " Serial number ($SERIAL_NUMBER ) already configured. Skipping."
35+ exit 0
36+ fi
37+
38+ SERIAL_NUMBER_ESCAPED=$( echo " $SERIAL_NUMBER " | sed -e ' s/\\/\\\\/g' -e ' s/\//\\\//g' -e ' s/\&/\\\&/g' )
39+ NEW_LINE=" <txt-record>serial_number=${SERIAL_NUMBER_ESCAPED} </txt-record>"
40+
41+ echo " Adding serial number to $TARGET_FILE ..."
42+
43+ sed -i " \#${MARKER_LINE} #i ${NEW_LINE} " " $TARGET_FILE "
44+
45+ echo " Avahi configuration attempt finished."
46+ exit 0
You can’t perform that action at this time.
0 commit comments