mirror of
https://github.com/mail-in-a-box/mailinabox.git
synced 2026-03-11 16:57:23 +01:00
Improve hostname/IP default values
Default IP+hostname values were incorrect for my VPS provider. I improved the detection, which should give correct results results for almost any provider. Specific issues addressed: - icanhazip.com detection was only enabled in non-interactive mode - `hostname` is by convention a short (non-fqdn) name in Ubuntu - `hostname --fqdn` fails if provider does not pouplate `hosts` file - `hostname -i` fails if provider does not populate `hosts` file - `curl` without `--fail` will someday return crazy results when icanhazip.com returns 500 errors or similar
This commit is contained in:
@@ -19,6 +19,34 @@ function apt_install {
|
||||
DEBIAN_FRONTEND=noninteractive apt-get -qq -y install $PACKAGES > /dev/null;
|
||||
}
|
||||
|
||||
function get_default_hostname {
|
||||
set -- $(hostname --fqdn 2>/dev/null ||
|
||||
hostname --all-fqdns 2>/dev/null ||
|
||||
hostname 2>/dev/null)
|
||||
printf '%s\n' "$1"
|
||||
}
|
||||
|
||||
function get_default_publicip {
|
||||
get_publicip_from_web_service || get_publicip_from_dns
|
||||
}
|
||||
|
||||
function get_publicip_from_web_service {
|
||||
curl --fail --silent icanhazip.com 2>/dev/null
|
||||
}
|
||||
|
||||
function get_publicip_from_dns {
|
||||
set -- $(hostname --ip-address 2>/dev/null) \
|
||||
$(hostname --all-ip-addresses 2>/dev/null)
|
||||
while (( $# )) && is_loopback_ip "$1"; do
|
||||
shift
|
||||
done
|
||||
printf '%s\n' "$1"
|
||||
}
|
||||
|
||||
function is_loopback_ip {
|
||||
[[ "$1" == 127.* ]]
|
||||
}
|
||||
|
||||
function ufw_allow {
|
||||
if [ -z "$DISABLE_FIREWALL" ]; then
|
||||
# ufw has completely unhelpful output
|
||||
|
||||
Reference in New Issue
Block a user