From 0db21eb308135cbc824675bce833a2924f6b6ead Mon Sep 17 00:00:00 2001
From: Nico Schottelius <nico@kr.ethz.ch>
Date: Fri, 1 Apr 2011 12:47:48 +0200
Subject: [PATCH] document, cleanup and theoretically finish
 __debconf_set_selections

Signed-off-by: Nico Schottelius <nico@kr.ethz.ch>
---
 .../explorer/pkg_status                       | 31 ----------------
 .../__debconf_set_selections/gencode-remote   | 35 +++---------------
 conf/type/__debconf_set_selections/man.text   | 36 ++++++-------------
 .../parameter/optional                        |  3 --
 .../parameter/required                        |  2 +-
 5 files changed, 15 insertions(+), 92 deletions(-)
 delete mode 100755 conf/type/__debconf_set_selections/explorer/pkg_status
 delete mode 100644 conf/type/__debconf_set_selections/parameter/optional

diff --git a/conf/type/__debconf_set_selections/explorer/pkg_status b/conf/type/__debconf_set_selections/explorer/pkg_status
deleted file mode 100755
index 86b94825..00000000
--- a/conf/type/__debconf_set_selections/explorer/pkg_status
+++ /dev/null
@@ -1,31 +0,0 @@
-#!/bin/sh
-#
-# 2011 Nico Schottelius (nico-cdist at schottelius.org)
-#
-# 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/>.
-#
-#
-# Retrieve the status of a package - parsed dpkg output
-#
-
-if [ -f "$__object/parameter/name" ]; then
-   name="$(cat "$__object/parameter/name")"
-else
-   name="$__object_id"
-fi
-
-# Except dpkg failing, if package is not known / installed
-dpkg -s "$name" 2>/dev/null || exit 0
diff --git a/conf/type/__debconf_set_selections/gencode-remote b/conf/type/__debconf_set_selections/gencode-remote
index b2c7179d..156fc9f3 100755
--- a/conf/type/__debconf_set_selections/gencode-remote
+++ b/conf/type/__debconf_set_selections/gencode-remote
@@ -18,36 +18,9 @@
 # along with cdist. If not, see <http://www.gnu.org/licenses/>.
 #
 #
-# Manage packages on Debian and co.
+# Setup selections
 #
 
-if [ -f "$__object/parameter/name" ]; then
-   name="$(cat "$__object/parameter/name")"
-else
-   name="$__object_id"
-fi
-
-# Check for preseeding and add preseed as here document
-if [ -f "$__object/parameter/preseed" ]; then
-   echo "debconf-set-selections << __file-eof"
-   cat "$(cat "$__object/parameter/preseed")"
-   echo "__file-eof"
-fi
-
-state="$(cat "$__object/parameter/state")"
-is_installed="$(grep "^Status: install ok installed" "$__object/explorer/pkg_status" || true)"
-
-case "$state" in
-   installed)
-      # Install only if non-existent
-      if [ -z "$is_installed" ]; then
-         echo apt-get --quiet --yes install \"$name\"
-      fi
-   ;;
-   uninstalled)
-      # Remove only if existent
-      if [ -n "$is_installed" ]; then
-         echo apt-get --quiet --yes remove \"$name\"
-      fi
-   ;;
-esac
+echo "debconf-set-selections << __file-eof"
+cat "$__object/parameter/file"
+echo "__file-eof"
diff --git a/conf/type/__debconf_set_selections/man.text b/conf/type/__debconf_set_selections/man.text
index 8b7476b4..b6b2ad18 100644
--- a/conf/type/__debconf_set_selections/man.text
+++ b/conf/type/__debconf_set_selections/man.text
@@ -1,31 +1,22 @@
-cdist-type__package_apt(7)
-==========================
+cdist-type__debconf_set_selections(7)
+=====================================
 Nico Schottelius <nico-cdist--@--schottelius.org>
 
 
 NAME
 ----
-cdist-type__package_apt - Manage packages with apt-get
+cdist-type__debconf_set_selections - Setup debconf selections
 
 
 DESCRIPTION
 -----------
-apt-get is usually used on Debian and variants (like Ubuntu) to
-manage packages.
+On Debian and alike systems debconf-set-selections(1) can be used
+to setup configuration parameters.
 
 
 REQUIRED PARAMETERS
 -------------------
-state::
-   Either "installed" or "deinstalled".
-
-
-OPTIONAL PARAMETERS
--------------------
-name::
-   If supplied, use the name and not the object id as the package name.
-
-preseed::
+file::
    If supplied, use the given filename as input for debconf-set-selections(1)
 
 
@@ -33,24 +24,17 @@ EXAMPLES
 --------
 
 --------------------------------------------------------------------------------
-# Ensure zsh in installed
-__package_apt zsh --state installed
+# Setup configuration for nslcd
+__debconf_set_selections nslcd --file /path/to/file
 
-# In case you only want *a* webserver, but don't care which one
-__package_apt webserver --state installed --name nginx
-
-# Install package with defaults (from a type)
-__package_apt postfix --state installed --preseed "$__type/files/postfix-seed"
-
-# Remove obsolete package
-__package_apt puppet --state deinstalled
+# Setup configuration for nslcd from another type
+__debconf_set_selections nslcd --file "$__type/files/preseed/nslcd"
 --------------------------------------------------------------------------------
 
 
 SEE ALSO
 --------
 - cdist-type(7)
-- cdist-type__package(7)
 
 
 COPYING
diff --git a/conf/type/__debconf_set_selections/parameter/optional b/conf/type/__debconf_set_selections/parameter/optional
deleted file mode 100644
index 2dae648e..00000000
--- a/conf/type/__debconf_set_selections/parameter/optional
+++ /dev/null
@@ -1,3 +0,0 @@
-name
-preseed
-version
diff --git a/conf/type/__debconf_set_selections/parameter/required b/conf/type/__debconf_set_selections/parameter/required
index ff72b5c7..f73f3093 100644
--- a/conf/type/__debconf_set_selections/parameter/required
+++ b/conf/type/__debconf_set_selections/parameter/required
@@ -1 +1 @@
-state
+file