Discourse-setup uses ifconfig to check the IP address for Let's Encrypt, but it's not available on Debian stretch

These lines in discourse-setup depend on ifconfig, but Debian Stretch doesn’t have ifconfig:

  local IFACE=none
  local IFCONFIG=`which ifconfig`
  /sbin/route |grep default > /tmp/route$PPID

  if grep default /tmp/route$PPID > /dev/null
  then
      local IFACE=`cut -c 73-100 /tmp/route$PPID |head -1`
  else
    echo WARNING: Cannot check your IP number.
  fi
  local IP=`$IFCONFIG $IFACE|grep  "inet addr:" |cut -d":" -f 2|cut -d" " -f1|head -1`

The way I check for the IP address on Debian Stretch is to use hostname -i, for example:

#!/bin/bash

local IFCONFIG=$(which ifconfig)
local HOSTNAME=$(which hostname)

# Check is ifconfig is available
if [[ ${IFCONFIG} ]]; then
  # https://stackoverflow.com/a/4046101
  local IP=$($IFCONFIG | fgrep 'inet addr:' | fgrep -v '127.0.0.1' | cut -d: -f2 | awk '{print $1}' | head -n1)
# If we don't have ifconfig then try to use hostname
elif [[ ${HOSTNAME} ]]; then
  local IP=$(hostname -i)
else
  echo "Sorry, couldn't find ifconfig or hostname so couldn't use them to work out the local IP address"
fi
4 Likes

Aha this is an issue for @pfaffman

I wonder how many distros do not have this command? I suggest we skip the check if the command is missing, assuming it is a rare thing in a distro.

It is good to do this check, hostname -i is a lot simpler than getting the IP address from ifconfig.

4 Likes

A couple of other things, dig is part of dnsutils which isn’t installed by default so needs to be installed before this check will work, furthermore if the local dns server resolves an address it isn’t always the case that a public one will – you could consider if it would be safer to use a public server, for example dig @8.8.8.8.

4 Likes

Not only Debian, but some other distro don’t install ifconfig by default in a minimal setup, including CentOS 7. It is still available in the net-tools package for CentOS 7 as part of the base repository, and I believe Debain should have it too, just not sure whether they use the same package name.

Newer distros moved to iproute package. The new ip command from this package now does ifconfig/route and many other tasks. To get IP address, just use ip addr (multiline output) or ip -o addr (single line output for each interface).

Well, the version that Digital Ocean installs has ifconfig. hostname -i on the Digital Ocean droplet I just checked returns 127.0.1.1, so that doesn’t seem helpful.

I don’t remember any in the past 20 years. Apparently, it’s been deprecated. It seems that ip -a is the New Way.

It worked on Centos, which now appears to work with the Docker that ./discourse-setup will install (alas, that script doesn’t actually start Docker, but I can probably fix it so that it will).

It could be that Digital Ocean adds ifconfig.

One or both of Debian and Centos are missing git.

I think I can do a bit of work and make ./discourse-setup work for Ubuntu, Debian, and Centos, including installing Docker and git.

3 Likes

Oops. Discourse-setup can’t install install git. Chicken. Eggs.

1 Like

Probably we need a different command that is more compatible with more distros.