#!/bin/sh

escapere()
{
  sed 's/\./\\\\./g'
}

if [ -n "$(hostname --fqdn)" ]; then 
  printf "@@define FQDN %s\\n" "$(hostname --fqdn | escapere)"
fi
if [ -n "$(hostname)" ]; then
  printf "@@define HOSTNAME %s\\n" "$(hostname | escapere)"
fi
if [ -n "$(dnsdomainname)" ]; then
  printf "@@define DNSDOMAINNAME %s\\n" "$(dnsdomainname | escapere)"
fi
if [ -n "$(dpkg --print-architecture)" ]; then
  printf "@@define ARCH %s\\n" "$(dpkg --print-architecture)"
fi
if [ -n "$(dpkg --print-foreign-architectures)" ]; then
  if [ "$(dpkg --print-foreign-architectures | wc -l)" -gt 1 ]; then
    printf "@@define FOREIGN_ARCHES %s\\n" "$(dpkg --print-foreign-architectures | tr '\\n' '|' | sed 's/^/(/; s/|$/)/')"
  else
    printf "@@define FOREIGN_ARCHES %s\\n" "$(dpkg --print-foreign-architectures)"
  fi
fi
dpkg-architecture --host-type 2>/dev/null | awk '{print "@@define " $1 " " $2}' FS="="

