]> Frank Brehm's Git Trees - pixelpark/create-vmware-tpl.git/commitdiff
Minor changes to snippets/tpl.001.basics.sh
authorFrank Brehm <frank.brehm@pixelpark.com>
Fri, 12 Jun 2020 13:55:59 +0000 (15:55 +0200)
committerFrank Brehm <frank.brehm@pixelpark.com>
Fri, 12 Jun 2020 13:55:59 +0000 (15:55 +0200)
snippets/tpl.001.basics.sh

index 86473d5089bba04b70d033b6386bda34c15eec52..a3449676ea5c54f847626de3f8817f090e8908af 100644 (file)
@@ -10,15 +10,36 @@ echo
 if [[ -z "${hostname}" ]] ; then
     hostname="template.pixelpark.com"
 fi
-IP_ADDRESS_ETH0=$( host "${hostname}" | sed -e 's/.*has address[       ][      ]*//' )
-DOMAIN=$( echo "${hostname}" | cut -d. -f2,3 )
-SIMPLE_HOSTNAME=$( echo "${hostname}" | cut -d. -f1 )
+
+DEVNAME_ETH0=$( ip -oneline link show | \
+                grep -v ' lo: ' | \
+                head -n 1 | \
+                awk '{print $2}' | \
+                sed -e 's/:$//' )
+IP_ADDRESS_ETH0=$( ip -oneline addr show dev "${DEVNAME_ETH0}" | \
+                   grep ' inet ' | \
+                   head -n 1 | \
+                   awk '{print $4}' | \
+                   sed -e 's|/.*||' )
+GATEWAY=$( ip -oneline route show | grep ^default | head -n 1 | awk '{print $3}' )
+DOMAIN=$( echo "${hostname}" | sed -e 's/^[^\.]*\.//' )
+SIMPLE_HOSTNAME=$( echo "${hostname}" | sed -e 's/\..*//' )
 
 if [[ -z "${ip_address_eth0}" ]] ; then
     ip_address_eth0="${IP_ADDRESS_ETH0}"
 fi
 
-POSTFIX_MYORIGIN='pixelpark.net'
+if [[ -z "${gateway}" ]] ; then
+    gateway="${GATEWAY}"
+fi
+
+if [[ -z "${mac_address_eth0}" ]] ; then
+    mac_address_eth0=$( ip -oneline link show dev "${DEVNAME_ETH0}" | \
+                        grep -P -o 'link/ether\s+\S+' | \
+                        awk '{print $2}' )
+fi
+
+POSTFIX_MYORIGIN='pixelpark.com'
 POSTFIX_RELAYHOST='[mx.pixelpark.com]'
 
 ERROR_POINTER="/root/postinst-error.txt"