Skip to content
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

Update run.sh to include lowercase I in hostname. #26

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all 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
2 changes: 1 addition & 1 deletion casaos-add-lan-ip-to-nextcloud-config/run.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/usr/bin/env bash

# Get the LAN IP address
lan_ip=$(hostname -I | awk '{print $1}')
lan_ip=$(hostname -i | awk '{print $1}')
Copy link

@coderabbitai coderabbitai bot Jan 5, 2025

Choose a reason for hiding this comment

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

⚠️ Potential issue

Consider using more reliable IP detection methods

While hostname -i might work in some cases, it can be unreliable as it may return 127.0.1.1 on some systems, which would break Nextcloud's external access. Consider using more reliable methods to detect the LAN IP.

Here's a more robust implementation:

-lan_ip=$(hostname -i | awk '{print $1}')
+# Get the first non-localhost IPv4 address
+lan_ip=$(ip -4 addr show | grep -oP '(?<=inet\s)\d+(\.\d+){3}' | grep -v '^127\.' | head -n1)

This solution:

  • Uses ip command which is more reliable
  • Explicitly filters for IPv4 addresses
  • Excludes localhost addresses
  • Takes the first valid LAN IP
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
lan_ip=$(hostname -i | awk '{print $1}')
# Get the first non-localhost IPv4 address
lan_ip=$(ip -4 addr show | grep -oP '(?<=inet\s)\d+(\.\d+){3}' | grep -v '^127\.' | head -n1)

Copy link
Author

Choose a reason for hiding this comment

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

that may be, however as written this does not resolve. ‘hostname -I’ results in the following error message followed by usage:

hostname: invalid option — ‘I’
IMG_0176

Copy link

Choose a reason for hiding this comment

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

@simianspaceman, thanks for clarifying why you switched to the lowercase -i. Indeed, some environments don’t recognize the uppercase -I option, leading to that error. If you find that hostname -i occasionally yields 127.0.1.1 instead of your true LAN IP, you might consider switching to the more robust ip-based approach. Otherwise, if your environment is guaranteed to return the correct IP with hostname -i, then this fix should resolve your immediate issue.


✏️ Learnings added
Learnt from: simianspaceman
PR: bigbeartechworld/big-bear-scripts#26
File: casaos-add-lan-ip-to-nextcloud-config/run.sh:4-4
Timestamp: 2025-01-05T15:21:39.952Z
Learning: On certain systems, the `hostname` command does not support the uppercase `-I` option, leading to an invalid option error. A lowercase `-i` may work, but it can return `127.0.1.1` on some systems.

Note: Learnings are effective only in the context of similar code segments. To apply general coding guidelines, please configure review instructions. You can manage existing learnings in the app.


# Backup the original config.php file
cp /DATA/AppData/big-bear-nextcloud/html/config/config.php /DATA/AppData/big-bear-nextcloud/html/config/config.php.bak
Expand Down