Fallback hostname to localhost.
[bacula-cn.git] / debian / config
index 1fe6e1f..eb026c6 100644 (file)
@@ -4,19 +4,30 @@ set -e
 . /usr/share/debconf/confmodule
 
 # Guess default hostname
-HOST=$( hostname -f )
+HOST=$( hostname -f || true )
+if [ -z "$HOST" ]; then
+    HOST=localhost
+fi
+
 db_get bacula-cn/hostname || true
 if [ -z "$RET" ]; then
     db_set bacula-cn/hostname "$HOST"
 fi
 
 # Guess default ip
-. /usr/share/carnet-tools/functions.sh
-cp_get_ifaddr
-IP=$RET
 db_get bacula-cn/ip || true
 if [ -z "$RET" ]; then
-    db_set bacula-cn/ip "$IP"
+    # default via 161.53.55.1 dev eth0
+    DEV=$( ip route show to exact 0/0 \
+           | awk '$1 == "default" && $4 == "dev" { print $5; nextfile }' )
+    if [ "$DEV" ]; then
+        # inet 161.53.55.202/24 brd 161.53.55.255 scope global eth0
+        IP=$( ip address show dev $DEV scope global \
+              | awk '$1 == "inet" { sub("/[^ ]+", ""); print $2; nextfile }' )
+        if [ "$IP" ]; then
+            db_set bacula-cn/ip "$IP"
+        fi
+    fi
 fi
 
 # Sample contact