From 3b91443f813a154e3dc0e7afa523b1e6970607aa Mon Sep 17 00:00:00 2001
From: Andres Erbsen <andreser@mit.edu>
Date: Fri, 2 Sep 2016 11:39:22 -0400
Subject: [PATCH] __hostname: openbsd support

---
 cdist/conf/type/__hostname/gencode-remote |  4 ++--
 cdist/conf/type/__hostname/manifest       | 12 +++++++++++-
 2 files changed, 13 insertions(+), 3 deletions(-)

diff --git a/cdist/conf/type/__hostname/gencode-remote b/cdist/conf/type/__hostname/gencode-remote
index c1808de0..4eb08723 100755
--- a/cdist/conf/type/__hostname/gencode-remote
+++ b/cdist/conf/type/__hostname/gencode-remote
@@ -40,7 +40,7 @@ case "$os" in
             exit 0
         fi
     ;;
-    scientific|centos)
+    scientific|centos|openbsd)
         if [ "$name_sysconfig" = "$name_should" -a "$name_running" = "$name_should" ]; then
             exit 0
         fi
@@ -64,7 +64,7 @@ else
             echo "hostname '$name_should'"
             echo "printf '%s\n' '$name_should' > /etc/hostname"
         ;;
-        centos)
+        centos|openbsd)
             echo "hostname '$name_should'"
         ;;
         suse)
diff --git a/cdist/conf/type/__hostname/manifest b/cdist/conf/type/__hostname/manifest
index 842075e0..823d2f7e 100755
--- a/cdist/conf/type/__hostname/manifest
+++ b/cdist/conf/type/__hostname/manifest
@@ -23,7 +23,14 @@ os=$(cat "$__global/explorer/os")
 if [ -f "$__object/parameter/name" ]; then
     name_should="$(cat "$__object/parameter/name")"
 else
-    name_should="$(echo "${__target_host%%.*}")"
+    case "$os" in
+    openbsd)
+        name_should="$(echo "${__target_host}")"
+    ;;
+    *)
+        name_should="$(echo "${__target_host%%.*}")"
+    ;;
+    esac
 fi
 
 
@@ -45,6 +52,9 @@ case "$os" in
             --key HOSTNAME \
             --value "$name_should" --exact_delimiter
     ;;
+    openbsd)
+        echo "$name_should" | __file /etc/myname --source -
+    ;;
     *)
         not_supported
     ;;