8000 Fix IPv4 and IPv6 output in Armbian welcome MOTD by useful64 · Pull Request #7911 · armbian/build · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Fix IPv4 and IPv6 output in Armbian welcome MOTD #7911

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
merged 3 commits into from
Mar 23, 2025

Conversation

useful64
Copy link
Contributor
@useful64 useful64 commented Mar 5, 2025

Description

Now "Armbian welcome MOTD" only prints one LAN IPv4 address and does not print any IPv6 address if you have more than one.

I changed to print all IPv4 and IPv6 addresses. I also made some cosmetic changes (based on .editorconfig from this repository).

Added by @igorpecovnik

  • sort out duplicate addresses. When LAN and WAN is the same, only show WAN.
  • add variable to hide all local IPV6 addresses. This is handy if have large number of containers and we probably don't want to see them all.
  • cosmetic changes / column alignment

How Has This Been Tested?

  • On dev machine.

Checklist:

Please delete options that are not relevant.

  • My code follows the style guidelines of this project
  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • My changes generate no new warnings

@useful64 useful64 requested a review from a team as a code owner March 5, 2025 01:14
@github-actions github-actions bot added size/medium PR with more then 50 and less then 250 lines Needs review Seeking for review BSP Board Support Packages labels Mar 5, 2025
@igorpecovnik
Copy link
Member

Thank you for addressing this problem. Current way is not the best and we also have a Jira ticket on the topic. https://armbian.atlassian.net/browse/AR-2571

I tried changed script and few of our production servers:
image

What stand out is:

  • ipv6 management. WAN ipv6 is among all and in the (Outgoing WAN) section. Also there is probably very small need to display local IPV6 addresses?

The other example machine:

IPv4 addresses: (LAN) 100.100.100.100, XX.YYY.XX (WAN) 100.100.100.100
IPv6 addresses: (All) 2 x local, 2 x external (one from tailscale, other from ISP)

Here we also have unnecessary duplication. We need to shuffle the logic around a bit - space for displaying is very limited, so its important we try our best.

The other issue is cosmetic nature - aligning data into columns. Now, IP sticks out as label text is longer.

Thank you!

@igorpecovnik igorpecovnik added Work in progress Unfinished / work in progress 05 Milestone: Second quarter release labels Mar 16, 2025
@igorpecovnik
Copy link
Member

VPS where we have one IP address that is local and global, only ipv6 is local and global.

image

@igorpecovnik igorpecovnik added Needs review Seeking for review and removed Needs review Seeking for review labels Mar 23, 2025
Copy link
Contributor
coderabbitai bot commented Mar 23, 2025

Walkthrough

The changes introduce a new configuration variable, HIDE_LOCAL_IPV6, which is set to "true" by default. This variable is used to control the visibility of local IPv6 addresses. The update modifies the logic for retrieving IP addresses by filtering out the link-local addresses (those starting with fe80) when the variable is active. Additionally, a new function, get_wan6_address, has been added to specifically retrieve the WAN IPv6 address, complementing the existing WAN IPv4 retrieval. Formatting improvements have been made, such as using braces around variable names and refining echo statements, to enhance code readability and maintain a clearer separation between LAN and WAN address outputs.

Poem

I'm a hopper of code, a rabbit on the run,
Guarding the IPv6 secrets as I dance in fun.
With HIDE_LOCAL_IPV6 in place, local addresses hide away,
And new functions bring bright clarity to the display.
I nibble on neat syntax, where each line leaps with grace,
Formatting so tidy, it brings a smile to every space.
Hoppy coding days ahead—carrots and bytes in a joyful race! 🥕


🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Contributor
@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (5)
packages/bsp/common/etc/update-motd.d/10-armbian-header (5)

194-195: Potential command substitution issue in sed replacement

The current implementation uses unquoted variables in the sed command which could lead to issues if the IP address contains special characters that need escaping.

Consider using a more robust approach:

-        ipv4s=$(echo $ipv4s | sed "s/"${wan_ip_address}"//g" | xargs )
+        ipv4s=$(echo "$ipv4s" | sed "s/$(echo "$wan_ip_address" | sed 's/[\/&]/\\&/g')//g" | xargs)

209-210: Same sed replacement issue for IPv6 addresses

Similar to the IPv4 section, the unquoted variables in the sed command could cause issues with IPv6 addresses which contain more special characters.

Consider using a more robust approach:

-	ipv6s=$(echo $ipv6s | sed "s/"${wan_ip6_address}"//g" | xargs )
+	ipv6s=$(echo "$ipv6s" | sed "s/$(echo "$wan_ip6_address" | sed 's/[\/&]/\\&/g')//g" | xargs)

214-214: Fix alignment issue for IPv6 label

The IPv6 label has an extra space compared to the IPv4 label, which could cause misalignment in the output.

- all_ip6_address=" IPv6:         "
+ all_ip6_address=" IPv6:        "

200-201: Consider adding conditional label for LAN addresses

The current implementation always adds the "(LAN)" label even if there's only one address, which might be unnecessary.

Consider a more concise approach:

-	if [[ -n ${ipv4s} ]]; then
-		all_ip_address+=" \x1B[93m(LAN)\x1B[0m "
-	fi
+	[[ -n ${ipv4s} && $(echo "$ipv4s" | wc -w) -gt 1 ]] && all_ip_address+=" \x1B[93m(LAN)\x1B[0m "

89-91: Improve HIDE_LOCAL_IPV6 variable check

The current implementation checks for the literal string "true" but it would be better to handle different possible inputs.

-			if [[ "${HIDE_LOCAL_IPV6}" == true ]]; then
+			if [[ "${HIDE_LOCAL_IPV6}" == "true" || "${HIDE_LOCAL_IPV6}" == "yes" || "${HIDE_LOCAL_IPV6}" == "1" ]]; then

This would make the configuration more user-friendly by accepting different common ways to express a boolean true value.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 838ac68 and 2d832e8.

📒 Files selected for processing (2)
  • packages/bsp/common/etc/default/armbian-motd.dpkg-dist (1 hunks)
  • packages/bsp/common/etc/update-motd.d/10-armbian-header (3 hunks)
🔇 Additional comments (12)
packages/bsp/common/etc/default/armbian-motd.dpkg-dist (1)

10-10: Good addition of configuration variable

Adding HIDE_LOCAL_IPV6="true" as a configurable option aligns with the PR objectives to allow users to hide local IPv6 addresses, especially useful for systems with numerous containers.

packages/bsp/common/etc/update-motd.d/10-armbian-header (11)

15-15: Default setting for IPv6 address display control

This establishes the default setting for hiding local IPv6 addresses, maintaining consistency with the configuration in armbian-motd.dpkg-dist.


35-38: Improved distribution detection logic

These changes enhance the robustness of distribution detection by:

  1. Adding proper variable scoping with braces
  2. Ensuring logical progression from one detection method to another
  3. Maintaining consistent variable naming and quoting

This makes the code more maintainable and readable.


44-50: Enhanced upgrade filter parsing

The improved formatting with proper variable quoting and consistent indentation makes this section more readable while maintaining the same functionality.


53-56: Consistent variable usage in script disabling logic

The addition of braces around variables provides more consistent syntax throughout the script.


58-60: Explicit IPv4 specification in WAN address retrieval

Adding the -4 flag to curl ensures the function explicitly requests an IPv4 address, which aligns with the function's purpose.


62-64: New WAN IPv6 address retrieval function

Good addition of a dedicated function for fetching WAN IPv6 addresses, following the same pattern as the IPv4 function. This modular approach improves code organization and maintainability.


68-75: Improved variable declarations

Better organization of variable declarations with more descriptive naming makes the function more readable and maintainable.


77-102: Enhanced IP address collection logic

This section includes several improvements:

  1. Better variable quoting for reliability
  2. Implementation of the HIDE_LOCAL_IPV6 flag to filter out link-local addresses
  3. Consistent handling of both IPv4 and IPv6 addresses
  4. Use of arrays for cleaner collection of addresses

These changes address the key objectives of the PR by ensuring all relevant addresses are collected while filtering out unwanted ones.


114-114: Added WAN IPv6 address retrieval

This complements the existing WAN IPv4 address retrieval, enabling the script to display outgoing WAN IPv6 addresses as requested in the PR objectives.


191-207: Improved IPv4 address display logic

The new display logic for IPv4 addresses:

  1. Separates LAN and WAN addresses clearly with labels
  2. Removes WAN address from the LAN address list to avoid duplication
  3. Uses color coding for better visual distinction

This implementation addresses the PR objective of showing all available LAN IPv4 addresses while avoiding duplication.


208-222: New IPv6 address display implementation

This section implements a dedicated display for IPv6 addresses that:

  1. Removes WAN IPv6 from the list of local addresses
  2. Only displays IPv6 section when addresses are available
  3. Uses clear labeling and color coding to distinguish LAN and WAN addresses

This addresses the PR objective of displaying all available IPv6 addresses and sorting out duplicates.

@igorpecovnik igorpecovnik added Ready to merge Reviewed, tested and ready for merge and removed Work in progress Unfinished / work in progress labels Mar 23, 2025
@igorpecovnik igorpecovnik merged commit dea159a into armbian:main Mar 23, 2025
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
05 Milestone: Second quarter release BSP Board Support Packages Needs review Seeking for review Ready to merge Reviewed, tested and ready for merge size/medium PR with more then 50 and less then 250 lines
Development

Successfully merging this pull request may close these issues.

2 participants
0