various fixes and improvements
[automated-distro-installer] / chost
diff --git a/chost b/chost
new file mode 100755 (executable)
index 0000000..9a0034f
--- /dev/null
+++ b/chost
@@ -0,0 +1,13 @@
+#!/bin/bash
+
+# chost: get canonical hostname
+
+set -eE -o pipefail
+trap 'echo "$0:$LINENO:error: \"$BASH_COMMAND\" returned $?" >&2' ERR
+
+host=$1
+addr=$(host $host)
+addr=${addr##* }
+h=$(host $addr)
+h=${h##* }
+echo ${h%%.*}