Skip to content

Commit

Permalink
improve IP detection
Browse files Browse the repository at this point in the history
  • Loading branch information
nacho committed Nov 16, 2017
1 parent c4a0bba commit 29109ba
Show file tree
Hide file tree
Showing 6 changed files with 7 additions and 7 deletions.
2 changes: 1 addition & 1 deletion docker-armhf/nextcloud/020nextcloud
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ test -f /data/app/config/config.php || {

# Trusted Domain ( local IP )
IFACE=$( ip r | grep "default via" | awk '{ print $5 }' )
IP=$( ip a | grep "global $IFACE" | grep -oP '\d{1,3}(\.\d{1,3}){3}' | head -1 )
IP=$( ip a show dev "$IFACE" | grep global | grep -oP '\d{1,3}(.\d{1,3}){3}' | head -1 )
sudo -u www-data php "$OCC" config:system:set trusted_domains 1 --value="$IP"

# Trusted Domain ( as an argument )
Expand Down
2 changes: 1 addition & 1 deletion docker/nextcloud/020nextcloud
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ test -f /data/app/config/config.php || {

# Trusted Domain ( local IP )
IFACE=$( ip r | grep "default via" | awk '{ print $5 }' )
IP=$( ip a | grep "global $IFACE" | grep -oP '\d{1,3}(\.\d{1,3}){3}' | head -1 )
IP=$( ip a show dev "$IFACE" | grep global | grep -oP '\d{1,3}(.\d{1,3}){3}' | head -1 )
sudo -u www-data php "$OCC" config:system:set trusted_domains 1 --value="$IP"

# Trusted Domain ( as an argument )
Expand Down
2 changes: 1 addition & 1 deletion etc/nextcloudpi-config.d/dnsmasq.sh
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ configure()
[[ $ACTIVE_ != "yes" ]] && { service dnsmasq stop; update-rc.d dnsmasq disable; return; }

local IFACE=$( ip r | grep "default via" | awk '{ print $5 }' )
local IP=$( ip a | grep "global $IFACE" | grep -oP '\d{1,3}(\.\d{1,3}){3}' | head -1 )
local IP=$( ip a show dev "$IFACE" | grep global | grep -oP '\d{1,3}(.\d{1,3}){3}' | head -1 )

[[ "$IP" == "" ]] && { echo "could not detect IP"; return 1; }

Expand Down
2 changes: 1 addition & 1 deletion etc/nextcloudpi-config.d/nc-forward-ports.sh
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ install()
configure()
{
local IFACE=$( ip r | grep "default via" | awk '{ print $5 }' )
local IP=$( ip a | grep "global $IFACE" | grep -oP '\d{1,3}(\.\d{1,3}){3}' | head -1 )
local IP=$( ip a show dev "$IFACE" | grep global | grep -oP '\d{1,3}(.\d{1,3}){3}' | head -1 )
upnpc -d "$HTTPSPORT_" TCP
upnpc -d "$HTTPPORT_" TCP
upnpc -a "$IP" 443 "$HTTPSPORT_" TCP | tee >(cat - >&2) | grep -q "is redirected to internal" || \
Expand Down
2 changes: 1 addition & 1 deletion etc/nextcloudpi-config.d/nc-notify-updates.sh
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ test -e \$NOTIFIED && [[ "\$( cat \$LATEST )" == "\$( cat \$NOTIFIED )" ]] && {
echo "Found update from \$( cat \$VERFILE ) to \$( cat \$LATEST ). Sending notification..."
IFACE=\$( ip r | grep "default via" | awk '{ print \$5 }' )
IP=\$( ip a | grep "global \$IFACE" | grep -oP '\d{1,3}(\.\d{1,3}){3}' | head -1 )
IP=\$( ip a show dev "\$IFACE" | grep global | grep -oP '\d{1,3}(\.\d{1,3}){3}' | head -1 )
sudo -u www-data php /var/www/nextcloud/occ notification:generate \
$USER_ "NextCloudPi update" \
Expand Down
4 changes: 2 additions & 2 deletions nextcloudpi.sh
Original file line number Diff line number Diff line change
Expand Up @@ -139,11 +139,11 @@ EOF
cat > /usr/local/bin/nextcloud-domain.sh <<'EOF'
#!/bin/bash
IFACE=$( ip r | grep "default via" | awk '{ print $5 }' )
IP=$( ip a | grep "global $IFACE" | grep -oP '\d{1,3}(\.\d{1,3}){3}' | head -1 )
IP=$( ip a show dev "$IFACE" | grep global | grep -oP '\d{1,3}(.\d{1,3}){3}' | head -1 )
# wicd service finishes before completing DHCP
while [[ "$IP" == "" ]]; do
sleep 3
IP=$( ip a | grep "global $IFACE" | grep -oP '\d{1,3}(\.\d{1,3}){3}' | head -1 )
IP=$( ip a show dev "$IFACE" | grep global | grep -oP '\d{1,3}(.\d{1,3}){3}' | head -1 )
done
cd /var/www/nextcloud
sudo -u www-data php occ config:system:set trusted_domains 1 --value=$IP
Expand Down

0 comments on commit 29109ba

Please sign in to comment.