Skip to content

Commit b067844

Browse files
committed
add get_ip function
Signed-off-by: nachoparker <nacho@ownyourbits.com>
1 parent 6ad96ed commit b067844

File tree

8 files changed

+27
-21
lines changed

8 files changed

+27
-21
lines changed

bin/ncp-diag

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111
# More at https://ownyourbits.com
1212
#
1313

14+
source /usr/local/etc/library.sh
15+
1416
# Distro, NCP version and tag
1517
echo "NextCloudPi version|$( cat /usr/local/etc/ncp-version )"
1618
[[ -f /usr/local/etc/ncp-baseimage ]] && echo "NextCloudPi image|$( cat /usr/local/etc/ncp-baseimage )"
@@ -67,7 +69,7 @@ function is_port_open()
6769
{
6870
local port=$1
6971
local public_ip
70-
public_ip="$(curl -4 https://icanhazip.com 2>/dev/null)" || { echo "closed"; return 1; }
72+
public_ip="$(curl -m4 -4 https://icanhazip.com 2>/dev/null)" || { echo "closed"; return 1; }
7173
local tmp_file=$(mktemp)
7274
local token=$(wget -T2 -t1 -qO- --keep-session-cookies --save-cookies $tmp_file https://portchecker.co | grep -oP "_csrf\" value=\"\K.*\"")
7375

@@ -85,7 +87,7 @@ echo "port check 443|$( is_port_open 443 )"
8587
# LAN
8688
IFACE=$( ip r | grep "default via" | awk '{ print $5 }' | head -1 )
8789
GW=$( ip r | grep "default via" | awk '{ print $3 }' | head -1 )
88-
IP=$( ip a show dev "$IFACE" | grep global | grep -oP '\d{1,3}(.\d{1,3}){3}' | head -1 )
90+
IP="$(get_ip)"
8991

9092
echo "IP|$IP"
9193
echo "gateway|$GW"

bin/ncp/NETWORKING/dnsmasq.sh

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,10 @@ configure()
4848
return
4949
}
5050

51-
local IFACE=$( ip r | grep "default via" | awk '{ print $5 }' | head -1 )
52-
local IP=$( ncc config:system:get trusted_domains "${TRUSTED_DOMAINS[docker_overwrite]}" | grep -oP '\d{1,3}(.\d{1,3}){3}' )
53-
[[ "$IP" == "" ]] && IP=$( ip a show dev "$IFACE" | grep global | grep -oP '\d{1,3}(.\d{1,3}){3}' | head -1 )
51+
local IFACE IP
52+
IFACE=$( ip r | grep "default via" | awk '{ print $5 }' | head -1 )
53+
IP=$( ncc config:system:get trusted_domains "${TRUSTED_DOMAINS[docker_overwrite]}" | grep -oP '\d{1,3}(.\d{1,3}){3}' )
54+
[[ "$IP" == "" ]] && IP="$(get_ip)"
5455

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

bin/ncp/NETWORKING/nc-forward-ports.sh

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,13 @@ install()
1717

1818
configure()
1919
{
20-
local IFACE=$( ip r | grep "default via" | awk '{ print $5 }' | head -1 )
21-
local IP=$( ip a show dev "$IFACE" | grep global | grep -oP '\d{1,3}(.\d{1,3}){3}' | head -1 )
20+
local ip
21+
ip="$(get_ip)"
2222
upnpc -d "$HTTPSPORT" TCP
2323
upnpc -d "$HTTPPORT" TCP
24-
upnpc -a "$IP" 443 "$HTTPSPORT" TCP | tee >(cat - >&2) | grep -q "is redirected to internal" || \
24+
upnpc -a "$ip" 443 "$HTTPSPORT" TCP | tee >(cat - >&2) | grep -q "is redirected to internal" || \
2525
{ echo -e "\nCould not forward ports automatically.\nDo it manually, or activate UPnP in your router and try again"; return 1; }
26-
upnpc -a "$IP" 80 "$HTTPPORT" TCP | tee >(cat - >&2) | grep -q "is redirected to internal" || \
26+
upnpc -a "$ip" 80 "$HTTPPORT" TCP | tee >(cat - >&2) | grep -q "is redirected to internal" || \
2727
{ echo -e "\nCould not forward ports automatically.\nDo it manually, or activate UPnP in your router and try again"; return 1; }
2828
}
2929

bin/ncp/UPDATES/nc-notify-updates.sh

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212

1313
# check every hour
1414
CHECKINTERVAL=1
15-
NCDIR=/var/www/nextcloud
1615

1716
configure()
1817
{
@@ -41,12 +40,9 @@ test -e \$NOTIFIED && [[ "\$( cat \$LATEST )" == "\$( cat \$NOTIFIED )" ]] && {
4140
4241
echo "Found update from \$( cat \$VERFILE ) to \$( cat \$LATEST ). Sending notification..."
4342
44-
IFACE=\$( ip r | grep "default via" | awk '{ print \$5 }' | head -1 )
45-
IP=\$( ip a show dev "\$IFACE" | grep global | grep -oP '\d{1,3}(\.\d{1,3}){3}' | head -1 )
46-
4743
notify_admin \
4844
"NextCloudPi update" \
49-
"Update from \$( cat \$VERFILE ) to \$( cat \$LATEST ) is available. Update from https://\$IP:4443"
45+
"Update from \$( cat \$VERFILE ) to \$( cat \$LATEST ) is available. Update from https://\$(get_ip):4443"
5046
5147
cat \$LATEST > \$NOTIFIED
5248
EOF

bin/nextcloud-domain.sh

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,12 @@ source /usr/local/etc/library.sh
44

55
# wicd service finishes before completing DHCP
66
while :; do
7-
iface="$( ip r | grep "default via" | awk '{ print $5 }' | head -1 )"
8-
ip="$( ip a show dev "$iface" | grep global | grep -oP '\d{1,3}(.\d{1,3}){3}' | head -1 )"
7+
ip="$(get_ip)"
8+
public_ip="$(curl -m4 icanhazip.com 2>/dev/null)"
99

10-
public_ip="$(curl icanhazip.com 2>/dev/null)"
1110
[[ "$public_ip" != "" ]] && ncc config:system:set trusted_domains 11 --value="$public_ip"
12-
1311
[[ "$ip" != "" ]] && break
12+
1413
sleep 3
1514
done
1615

changelog.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11

2-
[v1.39.14](https://github.com/nextcloud/nextcloudpi/commit/077c3bc) (2021-09-25) nc-https:only fix infinite redirects behind proxy
2+
[v1.39.15](https://github.com/nextcloud/nextcloudpi/commit/3e408f1) (2021-09-27) add get_ip function
3+
4+
[v1.39.14](https://github.com/nextcloud/nextcloudpi/commit/6ad96ed) (2021-09-25) nc-https:only fix infinite redirects behind proxy
35

46
[v1.39.13](https://github.com/nextcloud/nextcloudpi/commit/eef7b09) (2021-09-23) ncp-web: make letsencrypt detection more robust
57

etc/library.sh

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -382,6 +382,13 @@ function nc_version()
382382
ncc status | grep "version:" | awk '{ print $3 }'
383383
}
384384

385+
function get_ip()
386+
{
387+
local iface
388+
iface="$( ip r | grep "default via" | awk '{ print $5 }' | head -1 )"
389+
ip a show dev "$iface" | grep global | grep -oP '\d{1,3}(.\d{1,3}){3}' | head -1
390+
}
391+
385392
function is_an_ip()
386393
{
387394
local ip_or_domain="${1}"

install.sh

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,7 @@ rm /.ncp-image
6767
cd -
6868
rm -rf "${TMPDIR}"
6969

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

7372
echo "Done.
7473

0 commit comments

Comments
 (0)