From 3cd49eec2e1d16d57d817cf602904e00f78e7bb7 Mon Sep 17 00:00:00 2001
From: Thomas Bellman <bellman@lysator.liu.se>
Date: Tue, 19 Dec 2017 21:04:10 +0100
Subject: [PATCH] Definition for managing Linux console keymap files.

This adds a definition console::keymap::mapfile for installing (or
removing) keymap files for the Linux VGA console.

There is also a class console::keymap::params for defining where
keymap files are stored, with suitable defaults for some Linux
distributions.
---
 manifests/keymap/mapfile.pp | 56 +++++++++++++++++++++++++++++++++++++
 manifests/keymap/params.pp  | 33 ++++++++++++++++++++++
 2 files changed, 89 insertions(+)
 create mode 100644 manifests/keymap/mapfile.pp
 create mode 100644 manifests/keymap/params.pp

diff --git a/manifests/keymap/mapfile.pp b/manifests/keymap/mapfile.pp
new file mode 100644
index 0000000..48c3f02
--- /dev/null
+++ b/manifests/keymap/mapfile.pp
@@ -0,0 +1,56 @@
+# Copyright © 2017   Thomas Bellman, Linköping, Sweden
+# Licensed under the GNU LGPL v3+; see the README file for more information.
+
+
+/*
+ * Manage (install or remove) Linux console keymap files.
+ *
+ * Parameters:
+ *  - name		Name under which the keymap file will be installed.
+ *			The suffix ".map" will be added to $name.
+ *  - ensure		One of 'present' (the default) or 'absent'.
+ *  - layouttype	The keyboard layout type which this keymap file
+ *			uses.  This governs which subdirectory the file is
+ *			installed in; typically something like "sun" or
+ *			"i386/azerty".
+ *  - source, content	Where the content of the installed keymap file will
+ *			come from.  These have the same meanings as the
+ *			corresponding parameters to the 'file' type.
+ */
+define console::keymap::mapfile(
+    $ensure='present',
+    $source=undef, $content=undef,
+    $layouttype='i386/qwerty')
+{
+    include console::keymap::params
+    $mapfile = "${console::keymap::params::keymapdir}/${layouttype}/${name}.map"
+
+    case $ensure
+    {
+	'present': {
+	    if ($source and $content) {
+		fail("Console::Keymap::Mapfile[${title}]:",
+		     "Must only specify one of source and content")
+	    } elsif (! $source and ! $content) {
+		fail("Console::Keymap::Mapfile[${title}]:",
+		     "Must specify either source or content")
+	    }
+	    file {
+		$mapfile:
+		    ensure => file,
+		    source => $source, content => $content,
+		    owner => 'root', group => 'root', mode => '0444';
+	    }
+	}
+	'absent': {
+	    file {
+		$mapfile:
+		    ensure => absent;
+	    }
+	}
+	default: {
+	    fail("Console::Keymap::Mapfile[${title}]:",
+		 "Bad value for parameter ensure, `${ensure}'")
+	}
+    }
+}
diff --git a/manifests/keymap/params.pp b/manifests/keymap/params.pp
new file mode 100644
index 0000000..7b3b7cb
--- /dev/null
+++ b/manifests/keymap/params.pp
@@ -0,0 +1,33 @@
+# Copyright © 2017   Thomas Bellman, Linköping, Sweden
+# Licensed under the GNU LGPL v3+; see the README file for more information.
+
+
+class console::keymap::params::default
+{
+    case "${::operatingsystem}:${::operatingsystemrelease}"
+    {
+	/^(RedHat|CentOS|Scientific):[56]\.[0-9]+$/: {
+	    $keymapdir = '/lib/kbd/keymaps'
+	}
+	/^(RedHat|CentOS|Scientific):[7]\.[0-9.]+$/: {
+	    $keymapdir = '/lib/kbd/keymaps/legacy'
+	}
+	/^Gentoo:.*$/: {
+	    $keymapdir = '/usr/share/keymaps'
+	}
+	/^Debian:.*$/: {
+	    $keymapdir = '/usr/share/keymaps'
+	}
+    }
+}
+
+
+class console::keymap::params(
+    $keymapdir = $console::keymap::params::default::keymapdir,
+)
+    inherits console::keymap::params::default
+{
+    if ! $keymapdir {
+	fail("Console::Keymap::Params: Directory for keymaps not known")
+    }
+}
-- 
GitLab