From 48a96591d14910748744e256975c3fb55795f055 Mon Sep 17 00:00:00 2001 From: Nico Schottelius Date: Fri, 1 Apr 2011 12:11:50 +0200 Subject: [PATCH] add template for type __debconf_set_selections/ Signed-off-by: Nico Schottelius --- .../explorer/pkg_status | 31 ++++++++++ .../__debconf_set_selections/gencode-remote | 53 +++++++++++++++++ conf/type/__debconf_set_selections/man.text | 59 +++++++++++++++++++ .../parameter/optional | 3 + .../parameter/required | 1 + 5 files changed, 147 insertions(+) create mode 100755 conf/type/__debconf_set_selections/explorer/pkg_status create mode 100755 conf/type/__debconf_set_selections/gencode-remote create mode 100644 conf/type/__debconf_set_selections/man.text create mode 100644 conf/type/__debconf_set_selections/parameter/optional create mode 100644 conf/type/__debconf_set_selections/parameter/required diff --git a/conf/type/__debconf_set_selections/explorer/pkg_status b/conf/type/__debconf_set_selections/explorer/pkg_status new file mode 100755 index 00000000..86b94825 --- /dev/null +++ b/conf/type/__debconf_set_selections/explorer/pkg_status @@ -0,0 +1,31 @@ +#!/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 . +# +# +# 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 new file mode 100755 index 00000000..b2c7179d --- /dev/null +++ b/conf/type/__debconf_set_selections/gencode-remote @@ -0,0 +1,53 @@ +#!/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 . +# +# +# Manage packages on Debian and co. +# + +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 diff --git a/conf/type/__debconf_set_selections/man.text b/conf/type/__debconf_set_selections/man.text new file mode 100644 index 00000000..8b7476b4 --- /dev/null +++ b/conf/type/__debconf_set_selections/man.text @@ -0,0 +1,59 @@ +cdist-type__package_apt(7) +========================== +Nico Schottelius + + +NAME +---- +cdist-type__package_apt - Manage packages with apt-get + + +DESCRIPTION +----------- +apt-get is usually used on Debian and variants (like Ubuntu) to +manage packages. + + +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:: + If supplied, use the given filename as input for debconf-set-selections(1) + + +EXAMPLES +-------- + +-------------------------------------------------------------------------------- +# Ensure zsh in installed +__package_apt zsh --state installed + +# 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 +-------------------------------------------------------------------------------- + + +SEE ALSO +-------- +- cdist-type(7) +- cdist-type__package(7) + + +COPYING +------- +Copyright \(C) 2011 Nico Schottelius. Free use of this software is +granted under the terms of the GNU General Public License version 3 (GPLv3). diff --git a/conf/type/__debconf_set_selections/parameter/optional b/conf/type/__debconf_set_selections/parameter/optional new file mode 100644 index 00000000..2dae648e --- /dev/null +++ b/conf/type/__debconf_set_selections/parameter/optional @@ -0,0 +1,3 @@ +name +preseed +version diff --git a/conf/type/__debconf_set_selections/parameter/required b/conf/type/__debconf_set_selections/parameter/required new file mode 100644 index 00000000..ff72b5c7 --- /dev/null +++ b/conf/type/__debconf_set_selections/parameter/required @@ -0,0 +1 @@ +state