Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

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

Open
mirkoCrobu wants to merge3 commits intomain
base:main
Choose a base branch
Loading
fromissue_694
Open
Show file tree
Hide file tree
Changes fromall 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 deletionsdebian/arduino-app-cli/DEBIAN/postinst
View file
Open in desktop
Original file line numberDiff line numberDiff 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
Copy link
Contributor

@dido18dido18Nov 7, 2025
edited
Loading

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Is the .service suffix needed ?

Suggested change
systemctl enable arduino-avahi-serial.service
systemctl enable arduino-avahi-serial

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

nit

Suggested change
systemctl enable arduino-avahi-serial.service
systemctl enable arduino-avahi-serial

View file
Open in desktop
Original file line numberDiff line numberDiff 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
46 changes: 46 additions & 0 deletionsdebian/arduino-app-cli/usr/sbin/arduino-avahi-serial.sh
View file
Open in desktop
Original file line numberDiff line numberDiff 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
Copy link
Contributor

Choose a reason for hiding this comment

The 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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Suggested change
echo"Warning: Serial number path not found at$SERIAL_NUMBER_PATH. Skipping.">&2
exit0
echo"Warning: Serial number path not found at$SERIAL_NUMBER_PATH">&2
exit1

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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Suggested change
echo"Warning: Target file$TARGET_FILE not found or not writable. Skipping.">&2
exit0
echo"Warning: Target file$TARGET_FILE not found or not writable.">&2
exit1

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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Suggested change
echo"Warning: Serial number file is empty. Skipping.">&2
exit0
echo"Warning: Serial number file is empty.">&2
exit1

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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Suggested change
echo"Serial number ($SERIAL_NUMBER) already configured. Skipping."
exit0
echo"Serial number ($SERIAL_NUMBER) already configured."
exit1

fi

SERIAL_NUMBER_ESCAPED=$(echo"$SERIAL_NUMBER"| sed -e's/\\/\\\\/g' -e's/\//\\\//g' -e's/\&/\\\&/g')
Copy link
Contributor

Choose a reason for hiding this comment

The 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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Suggested change
exit 0


[8]ページ先頭

©2009-2025 Movatter.jp