- Notifications
You must be signed in to change notification settings - Fork2
Add Serial Number to Avahi Service for Board Deduplication#48
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
base:main
Are you sure you want to change the base?
Changes fromall commits
File filter
Filter by extension
Conversations
Uh oh!
There was an error while loading.Please reload this page.
Jump to
Uh oh!
There was an error while loading.Please reload this page.
Diff view
Diff view
There are no files selected for viewing
| 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 | ||||||||||
| systemctl enable arduino-app-cli | ||||||||||
| systemctl enable arduino-burn-bootloader | ||||||||||
| systemctl enable arduino-avahi-serial.service | ||||||||||
Contributor There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others.Learn more. Is the .service suffix needed ? Suggested change
Contributor There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others.Learn more. nit Suggested change
| ||||||||||
| 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/avahi_serial_configured.flag | ||
| [Service] | ||
| Type=oneshot | ||
| RemainAfterExit=true | ||
| ExecStart=/usr/sbin/arduino-avahi-serial.sh | ||
| ExecStartPost=/bin/mkdir -p /var/lib/arduino | ||
| ExecStartPost=/bin/touch /var/lib/arduino/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,46 @@ | ||||||||||
| #!/bin/sh | ||||||||||
| # | ||||||||||
| # Configure Avahi with the serial number. | ||||||||||
| # This operation is non-blocking: if it fails, | ||||||||||
| # the script will exit with success in order to | ||||||||||
| # not to interrupt the post-install process. | ||||||||||
Comment on lines +3 to +6 Contributor There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others.Learn more. I think this script should and could fail. If there is an issue, I would prefer that it start the next time instead of never | ||||||||||
| # | ||||||||||
| TARGET_FILE="/etc/avahi/services/arduino.service" | ||||||||||
| MARKER_LINE="</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"Warning: Serial number path not found at$SERIAL_NUMBER_PATH. Skipping.">&2 | ||||||||||
| exit 0 | ||||||||||
Comment on lines +16 to +17 Contributor There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others.Learn more. Suggested change
| ||||||||||
| fi | ||||||||||
| if [!-w"$TARGET_FILE" ];then | ||||||||||
| echo"Warning: Target file$TARGET_FILE not found or not writable. Skipping.">&2 | ||||||||||
| exit 0 | ||||||||||
Comment on lines +22 to +23 Contributor There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others.Learn more. Suggested change
| ||||||||||
| fi | ||||||||||
| SERIAL_NUMBER=$(cat"$SERIAL_NUMBER_PATH") | ||||||||||
| if [-z"$SERIAL_NUMBER" ];then | ||||||||||
| echo"Warning: Serial number file is empty. Skipping.">&2 | ||||||||||
| exit 0 | ||||||||||
Comment on lines +29 to +30 Contributor There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others.Learn more. Suggested change
| ||||||||||
| fi | ||||||||||
| if grep -q"serial_number=${SERIAL_NUMBER}""$TARGET_FILE";then | ||||||||||
| echo"Serial number ($SERIAL_NUMBER) already configured. Skipping." | ||||||||||
| exit 0 | ||||||||||
Comment on lines +34 to +35 Contributor There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others.Learn more. Suggested change
| ||||||||||
| fi | ||||||||||
| SERIAL_NUMBER_ESCAPED=$(echo"$SERIAL_NUMBER"| sed -e's/\\/\\\\/g' -e's/\//\\\//g' -e's/\&/\\\&/g') | ||||||||||
Contributor There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others.Learn more. The serial number on the unoq is just a number I don't think you need to escape anything | ||||||||||
| NEW_LINE=" <txt-record>serial_number=${SERIAL_NUMBER_ESCAPED}</txt-record>" | ||||||||||
| echo"Adding serial number to$TARGET_FILE..." | ||||||||||
| sed -i"\#${MARKER_LINE}#i${NEW_LINE}""$TARGET_FILE" | ||||||||||
| echo"Avahi configuration attempt finished." | ||||||||||
| exit 0 | ||||||||||
Contributor There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others.Learn more. Suggested change
| ||||||||||