From 5279b7239ce0d34c6d0a504e2ae9dd84c354df29 Mon Sep 17 00:00:00 2001
From: Nico Schottelius <nico@bento.schottelius.org>
Date: Mon, 20 Jan 2014 13:47:45 +0100
Subject: [PATCH] import __hostname - Thanks, Steven!

Signed-off-by: Nico Schottelius <nico@bento.schottelius.org>
---
 cdist/conf/type/__hostname/gencode-remote     | 33 +++++++++++++
 cdist/conf/type/__hostname/man.text           | 47 +++++++++++++++++++
 cdist/conf/type/__hostname/manifest           | 42 +++++++++++++++++
 cdist/conf/type/__hostname/parameter/optional |  1 +
 cdist/conf/type/__hostname/singleton          |  0
 5 files changed, 123 insertions(+)
 create mode 100755 cdist/conf/type/__hostname/gencode-remote
 create mode 100644 cdist/conf/type/__hostname/man.text
 create mode 100755 cdist/conf/type/__hostname/manifest
 create mode 100644 cdist/conf/type/__hostname/parameter/optional
 create mode 100644 cdist/conf/type/__hostname/singleton

diff --git a/cdist/conf/type/__hostname/gencode-remote b/cdist/conf/type/__hostname/gencode-remote
new file mode 100755
index 00000000..88ee069a
--- /dev/null
+++ b/cdist/conf/type/__hostname/gencode-remote
@@ -0,0 +1,33 @@
+#!/bin/sh
+#
+# 2014 Steven Armstrong (steven-cdist at armstrong.cc)
+#
+# This file is part of cdist.
+#
+# cdist is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# cdist is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with cdist. If not, see <http://www.gnu.org/licenses/>.
+#
+
+name="$(cat "$__object/parameter/name")"
+os=$(cat "$__global/explorer/os")
+
+echo "printf '%s\n' '$name' > /etc/hostname"
+
+case "$os" in
+   debian|ubuntu)
+      echo "hostname \"$name\""
+   ;;
+   archlinux)
+      echo "hostnamectl set-hostname \"$name\""
+   ;;
+esac
diff --git a/cdist/conf/type/__hostname/man.text b/cdist/conf/type/__hostname/man.text
new file mode 100644
index 00000000..07ec1083
--- /dev/null
+++ b/cdist/conf/type/__hostname/man.text
@@ -0,0 +1,47 @@
+cdist-type__hostname(7)
+=======================
+Steven Armstrong <steven-cdist--@--armstrong.cc>
+
+
+NAME
+----
+cdist-type__hostname - set the hostname
+
+
+DESCRIPTION
+-----------
+Set's the hostname on various operating systems.
+
+
+REQUIRED PARAMETERS
+-------------------
+None.
+
+OPTIONAL PARAMETERS
+-------------------
+name::
+   The hostname to set. Defaults to the first segment of __target_host 
+   (${__target_host%%.*})
+
+
+EXAMPLES
+--------
+
+--------------------------------------------------------------------------------
+# take hostname from __target_host
+__hostname
+
+# set hostname explicitly
+__hostname --name some-static-hostname
+--------------------------------------------------------------------------------
+
+
+SEE ALSO
+--------
+- cdist-type(7)
+
+
+COPYING
+-------
+Copyright \(C) 2012 Steven Armstrong. Free use of this software is
+granted under the terms of the GNU General Public License version 3 (GPLv3).
diff --git a/cdist/conf/type/__hostname/manifest b/cdist/conf/type/__hostname/manifest
new file mode 100755
index 00000000..3aa6de45
--- /dev/null
+++ b/cdist/conf/type/__hostname/manifest
@@ -0,0 +1,42 @@
+#!/bin/sh
+#
+# 2012 Steven Armstrong (steven-cdist at armstrong.cc)
+#
+# This file is part of cdist.
+#
+# cdist is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# cdist is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with cdist. If not, see <http://www.gnu.org/licenses/>.
+#
+
+# set defaults
+name="$(cat "$__object/parameter/name" 2>/dev/null \
+   || echo "${__target_host%%.*}" | tee "$__object/parameter/name")"
+
+os=$(cat "$__global/explorer/os")
+
+not_supported() {
+   echo "Your operating system ($os) is currently not supported by this type (${__type##*/})." >&2
+   echo "Please contribute an implementation for it if you can." >&2
+   exit 1
+}
+
+case "$os" in
+   archlinux|debian|ubuntu)
+      # handled in gencode-remote
+      # FIXED: hostname setup in archlinuz via rc.local ist outdated
+      :
+   ;;
+   *)
+      not_supported
+   ;;
+esac
diff --git a/cdist/conf/type/__hostname/parameter/optional b/cdist/conf/type/__hostname/parameter/optional
new file mode 100644
index 00000000..f121bdbf
--- /dev/null
+++ b/cdist/conf/type/__hostname/parameter/optional
@@ -0,0 +1 @@
+name
diff --git a/cdist/conf/type/__hostname/singleton b/cdist/conf/type/__hostname/singleton
new file mode 100644
index 00000000..e69de29b