mirror of
https://github.com/bigbeartechworld/big-bear-scripts.git
synced 2026-03-31 06:33:56 -04:00
🔧 feat(casaos-nextcloud): Add LAN IP to Nextcloud config (#40)
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.
This commit is contained in:
@@ -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"
|
||||
|
||||
Reference in New Issue
Block a user