From e6667ea933f1af742d053eb09d253f7744456767 Mon Sep 17 00:00:00 2001 From: Christopher <1289128+dragonfire1119@users.noreply.github.com> Date: Wed, 30 Apr 2025 23:48:01 -0500 Subject: [PATCH] =?UTF-8?q?=F0=9F=94=A7=20feat(casaos-nextcloud):=20Add=20?= =?UTF-8?q?LAN=20IP=20to=20Nextcloud=20config=20(#40)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This commit adds the LAN IP address to the Nextcloud configuration file (`config.php`). The changes ensure that Nextcloud can be accessed using the LAN IP address, in addition to the default `localhost` address. The key changes are: - Implement a function `Get_IPs()` to reliably detect the LAN IP address, prioritizing non-loopback and non-docker interfaces. - Use the detected LAN IP address to update the `config.php` file, adding it as an additional entry in the `trusted_domains` setting. - Backup the original `config.php` file before making changes. --- casaos-add-lan-ip-to-nextcloud-config/run.sh | 30 ++++++++++++++++++-- 1 file changed, 27 insertions(+), 3 deletions(-) diff --git a/casaos-add-lan-ip-to-nextcloud-config/run.sh b/casaos-add-lan-ip-to-nextcloud-config/run.sh index f1feb70..06fdc92 100644 --- a/casaos-add-lan-ip-to-nextcloud-config/run.sh +++ b/casaos-add-lan-ip-to-nextcloud-config/run.sh @@ -1,13 +1,37 @@ #!/usr/bin/env bash -# Get the LAN IP address -lan_ip=$(hostname -I | awk '{print $1}') +# Function to get LAN IP addresses, prioritizing non-loopback and non-docker interfaces +Get_IPs() { + # Try ip command first (more reliable) + if command -v ip >/dev/null 2>&1; then + # Get all IPv4 addresses, exclude loopback (127.0.0.0/8) and docker interfaces + ip -4 addr show | grep -v "inet 127\." | grep -v "docker" | grep -v "br-" | grep -v "veth" | grep "inet" | awk '{print $2}' | cut -d/ -f1 + # Fall back to ifconfig if ip command is not available + elif command -v ifconfig >/dev/null 2>&1; then + # Get all IPv4 addresses, exclude loopback (127.0.0.0/8) and docker interfaces + ifconfig | grep -v "inet 127\." | grep -v "docker" | grep -v "br-" | grep -v "veth" | grep "inet" | awk '{print $2}' | cut -d: -f2 + # Last resort, try hostname -I but filter out loopback addresses + else + hostname -I | tr ' ' '\n' | grep -v "^127\." | head -n 1 + fi +} + +# Get the first valid LAN IP address +lan_ip=$(Get_IPs | head -n 1) + +# If no valid IP was found, exit with error +if [ -z "$lan_ip" ]; then + echo "Error: Could not determine LAN IP address." + exit 1 +fi + +echo "Using LAN IP: $lan_ip" # 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 # Add the LAN IP to the config.php file -awk -v ip="$lan_ip" '/0 => '\''localhost'\''/{print; print " 1 => '\''"ip"'\'',"; next}1' /DATA/AppData/big-bear-nextcloud/html/config/config.php.bak > /DATA/AppData/big-bear-nextcloud/html/config/config.php +awk -v ip="$lan_ip" '/0 => '\''localhost'\''/{print; print " 1 => '\''" ip "'\'',"; next}1' /DATA/AppData/big-bear-nextcloud/html/config/config.php.bak > /DATA/AppData/big-bear-nextcloud/html/config/config.php # Get the path to the docker-compose.yml file COMPOSE_FILE="/var/lib/casaos/apps/big-bear-nextcloud/docker-compose.yml"