-
Notifications
You must be signed in to change notification settings - Fork 3
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 our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
+56
−0
Merged
Changes from 5 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
fdb3736
set serial number for network discovery at post install time
mirkoCrobu a9ddaa2
adds space in a comment
mirkoCrobu c52f211
set script running before Avahi service
mirkoCrobu 3076350
code review fix
mirkoCrobu c1eb54f
code review fix
mirkoCrobu 088a594
code review fix
mirkoCrobu File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
17 changes: 17 additions & 0 deletions
17
debian/arduino-app-cli/etc/systemd/system/arduino-avahi-serial.service
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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=/usr/local/bin/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 |
38 changes: 38 additions & 0 deletions
38
debian/arduino-app-cli/usr/local/bin/arduino-avahi-serial.sh
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,38 @@ | ||
| #!/bin/sh | ||
| # Configure Avahi with the serial number. | ||
|
|
||
|
|
||
| TARGET_FILE="/etc/avahi/services/arduino.service" | ||
| MARKER_LINE="</service>" | ||
mirkoCrobu marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| 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. Skipping." | ||
mirkoCrobu marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| exit 0 | ||
mirkoCrobu marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| 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 | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.