From b9ff43c657de458b22d7113e82d1b2c623314756 Mon Sep 17 00:00:00 2001 From: Steven Armstrong Date: Thu, 3 Mar 2011 10:37:11 +0100 Subject: [PATCH 01/15] use $__global instead of ./out/ Signed-off-by: Steven Armstrong --- conf/type/__package/manifest | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/conf/type/__package/manifest b/conf/type/__package/manifest index 89b3f179..cf085e2f 100755 --- a/conf/type/__package/manifest +++ b/conf/type/__package/manifest @@ -28,7 +28,7 @@ if [ -f "$type" ]; then type="$(cat "$type")" else # By default determine package manager based on operating system - os="$(cat "out/explorer/os")" + os="$(cat "$__global/explorer/os")" case "$os" in archlinux) type="pacman" ;; debian|ubuntu) type="apt" ;; From 614ff21f4abb45b05504a36420864a56eab86d5c Mon Sep 17 00:00:00 2001 From: Steven Armstrong Date: Thu, 3 Mar 2011 10:37:49 +0100 Subject: [PATCH 02/15] /deinstalled/uninstalled/ Signed-off-by: Steven Armstrong --- conf/manifest/init | 4 ++-- conf/type/__package_apt/gencode | 2 +- conf/type/__package_emerge/gencode | 3 +-- conf/type/__package_pacman/gencode | 2 +- 4 files changed, 5 insertions(+), 6 deletions(-) diff --git a/conf/manifest/init b/conf/manifest/init index 17ba0e92..51b06e6f 100755 --- a/conf/manifest/init +++ b/conf/manifest/init @@ -16,7 +16,7 @@ case "$__target_host" in # Alias in /etc/hosts for localhost cdist-archlinux) - __package_pacman django --state deinstalled + __package_pacman django --state uninstalled __package_pacman wireshark-cli --state installed __package_pacman zsh --state installed ;; @@ -27,6 +27,6 @@ case "$__target_host" in # Real machines ikq*) __package_apt zsh --state installed - __package_apt apache2 --state deinstalled + __package_apt apache2 --state uninstalled ;; esac diff --git a/conf/type/__package_apt/gencode b/conf/type/__package_apt/gencode index b451eb9f..c85242e6 100755 --- a/conf/type/__package_apt/gencode +++ b/conf/type/__package_apt/gencode @@ -38,7 +38,7 @@ case "$state" in echo apt-get --quiet --yes install \"$name\" fi ;; - deinstalled) + uninstalled) # Remove only if existent if [ -n "$is_installed" ]; then echo apt-get --quiet --yes remove \"$name\" diff --git a/conf/type/__package_emerge/gencode b/conf/type/__package_emerge/gencode index ee95b823..47e8bc5e 100755 --- a/conf/type/__package_emerge/gencode +++ b/conf/type/__package_emerge/gencode @@ -34,9 +34,8 @@ case "$state" in # FIXME: only install if not already installed echo "emerge -q \"$name\"" ;; - deinstalled) + uninstalled) # FIXME: only uninstall if currently installed - # FIXME: rename deinstalled to uninstalled echo "emerge -q -C \"$name\"" ;; esac diff --git a/conf/type/__package_pacman/gencode b/conf/type/__package_pacman/gencode index 9702aa8e..536b7708 100755 --- a/conf/type/__package_pacman/gencode +++ b/conf/type/__package_pacman/gencode @@ -44,7 +44,7 @@ case "$state" in echo pacman "$pacopts" -S \"$name\" fi ;; - deinstalled) + uninstalled) if [ "$pkg_version" ]; then echo pacman "$pacopts" -R \"$name\" fi From 8b614b274c6476fd3cfbae92f2c8d04bb10a3466 Mon Sep 17 00:00:00 2001 From: Steven Armstrong Date: Mon, 14 Mar 2011 09:32:18 +0100 Subject: [PATCH 03/15] fix fixing the merge conflict Signed-off-by: Steven Armstrong --- conf/manifest/init | 52 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100755 conf/manifest/init diff --git a/conf/manifest/init b/conf/manifest/init new file mode 100755 index 00000000..0a1dca50 --- /dev/null +++ b/conf/manifest/init @@ -0,0 +1,52 @@ +# +# This is a sample manifest, but used in real world +# + +# This is debug and should not be in a production environment +# echo "We could access other manifests in $__manifest" + +# Every machine becomes a marker, so sysadmins know that automatic +# configurations are happening +__file /etc/cdist-configured --type file + +case "$__target_host" in + # Everybody has this + localhost) + # Usual example + __file test --type symlink --source /etc/cdist-configured --destination /tmp/cdist-testfile + ;; + + # + # Examples using different types + # + + # Alias in /etc/hosts for localhost + cdist-archlinux) + # This is the specific package type for pacman + __package_pacman zsh --state installed + + # The __package type autoselect the right type based on the os + __package vim --state installed + + # If the type is a singleton, it does not take an object id + __issue + ;; + # This is how it would look like on gentoo + cdist-gentoo) + # Same stuff for gentoo + __package tree --state installed + ;; + cdist-debian) + __package_apt atop --state installed + __package apache2 --state deinstalled + ;; + + # Real machines may be used with their hostname or fqdn, + # depending on how you call cdist-deploy-to + # machine) + # ... + # ;; + # machine.example.org) + # ... + # ;; +esac From a9d0bfee16c484696b0a1230bb6b94ad29a9adfc Mon Sep 17 00:00:00 2001 From: Steven Armstrong Date: Tue, 15 Mar 2011 16:47:40 +0100 Subject: [PATCH 04/15] new type __user Signed-off-by: Steven Armstrong --- conf/type/__user/TODO | 3 ++ conf/type/__user/explorer/passwd | 27 +++++++++++++ conf/type/__user/gencode | 44 ++++++++++++++++++++ conf/type/__user/man.text | 62 +++++++++++++++++++++++++++++ conf/type/__user/parameter/optional | 7 ++++ 5 files changed, 143 insertions(+) create mode 100644 conf/type/__user/TODO create mode 100755 conf/type/__user/explorer/passwd create mode 100755 conf/type/__user/gencode create mode 100644 conf/type/__user/man.text create mode 100644 conf/type/__user/parameter/optional diff --git a/conf/type/__user/TODO b/conf/type/__user/TODO new file mode 100644 index 00000000..5c2eec7d --- /dev/null +++ b/conf/type/__user/TODO @@ -0,0 +1,3 @@ +- gencode: compair new value with existing one in $__object/explorer/passwd, only change if nessecary +- delete users + diff --git a/conf/type/__user/explorer/passwd b/conf/type/__user/explorer/passwd new file mode 100755 index 00000000..fdbfb193 --- /dev/null +++ b/conf/type/__user/explorer/passwd @@ -0,0 +1,27 @@ +#!/bin/sh +# +# 2011 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 . +# +# +# Get an existing users passwd entry. +# + +name=$__object_id + +getent passwd "$name" || true + diff --git a/conf/type/__user/gencode b/conf/type/__user/gencode new file mode 100755 index 00000000..7445d6f8 --- /dev/null +++ b/conf/type/__user/gencode @@ -0,0 +1,44 @@ +#!/bin/sh +# +# 2011 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 . +# +# +# Manage users. +# + +name="$__object_id" + +command= +if grep -q "^$name" "$__object/explorer/passwd"; then + # user exists + command="usermod" +else + # user does not exist + command="useradd" +fi + + +set -- "$@" +cd "$__object/parameter" +for property in $(ls .); do + # TODO: compair new value with existing one in $__object/explorer/passwd, only change if nessecary + set -- "$@" "--$property" "$(cat "$property")" +done + +echo $command $@ $name + diff --git a/conf/type/__user/man.text b/conf/type/__user/man.text new file mode 100644 index 00000000..e571c7c5 --- /dev/null +++ b/conf/type/__user/man.text @@ -0,0 +1,62 @@ +cdist-type__user(7) +=================== +Steven Armstrong + + +NAME +---- +cdist-type__user - Manage users + + +DESCRIPTION +----------- +This cdist type allows you to create or modify users on the target. + + +REQUIRED PARAMETERS +------------------- +None. + + +OPTIONAL PARAMETERS +------------------- +comment:: + see usermod(8) +home:: + see above +gid:: + see above +groups:: + see above +password:: + see above +shell:: + see above +uid:: + see above + + +EXAMPLES +-------- + +-------------------------------------------------------------------------------- +# Create user account for foobar with operating system default settings +__user foobar + +# Same but with a different shell +__user foobar --shell /bin/zsh + +# Set explicit uid and home +__user foobar --uid 1001 --shell /bin/zsh --home /home/foobar +-------------------------------------------------------------------------------- + + +SEE ALSO +-------- +- cdist-type(7) + + +COPYING +------- +Copyright \(C) 2011 Steven Armstrong. Free use of this software is +granted under the terms of the GNU General Public License version 3 (GPLv3). diff --git a/conf/type/__user/parameter/optional b/conf/type/__user/parameter/optional new file mode 100644 index 00000000..fe02e227 --- /dev/null +++ b/conf/type/__user/parameter/optional @@ -0,0 +1,7 @@ +comment +home +gid +groups +password +shell +uid From 26b10dec6906bf93cd5dec6017d4dafa04eae669 Mon Sep 17 00:00:00 2001 From: Steven Armstrong Date: Tue, 15 Mar 2011 17:01:35 +0100 Subject: [PATCH 05/15] +man Signed-off-by: Steven Armstrong --- conf/type/__package/man.text | 61 ++++++++++++++++++++++++++++++++++++ 1 file changed, 61 insertions(+) create mode 100644 conf/type/__package/man.text diff --git a/conf/type/__package/man.text b/conf/type/__package/man.text new file mode 100644 index 00000000..eeeceba0 --- /dev/null +++ b/conf/type/__package/man.text @@ -0,0 +1,61 @@ +cdist-type__user(7) +=================== +Steven Armstrong + + +NAME +---- +cdist-type__package - Manage packages + + +DESCRIPTION +----------- +This cdist type allows you to install or uninstall packages on the target. +It dispatches the actual work to the package system dependant types. + + +REQUIRED PARAMETERS +------------------- +state:: + The state the package should be in, either "installed" or "uninstalled" + + +OPTIONAL PARAMETERS +------------------- +name:: + The name of the package to install. Default is to use the object_id as the + package name. +version:: + The version of the package to install. Default is to install the version + choosen by the local package manager. +type:: + The package type to use. Default is determined based on the $os explorer + variable. + e.g. __package_apt for Debian + __package_emerge for Gentoo + + +EXAMPLES +-------- + +-------------------------------------------------------------------------------- +# Install the package vim on the target +__package vim --state installed + +# Same but install specific version +__package vim --state installed --version 7.3.50 + +# Force use of a specific package type +__package vim --state installed --type __package_apt +-------------------------------------------------------------------------------- + + +SEE ALSO +-------- +- cdist-type(7) + + +COPYING +------- +Copyright \(C) 2011 Steven Armstrong. Free use of this software is +granted under the terms of the GNU General Public License version 3 (GPLv3). From f2f67ad0ad5713ae67b72fbdbe5a928b4a47a317 Mon Sep 17 00:00:00 2001 From: Steven Armstrong Date: Tue, 15 Mar 2011 17:09:45 +0100 Subject: [PATCH 06/15] +man __package_emerge/man.text Signed-off-by: Steven Armstrong --- conf/type/__package_emerge/man.text | 58 +++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) create mode 100644 conf/type/__package_emerge/man.text diff --git a/conf/type/__package_emerge/man.text b/conf/type/__package_emerge/man.text new file mode 100644 index 00000000..002821dd --- /dev/null +++ b/conf/type/__package_emerge/man.text @@ -0,0 +1,58 @@ +cdist-type__user(7) +=================== +Steven Armstrong + + +NAME +---- +cdist-type__package_emerge - Manage packages on Gentoo Linux + + +DESCRIPTION +----------- +This cdist type allows you to install or uninstall packages on a Gentoo Linux +target. + + +REQUIRED PARAMETERS +------------------- +state:: + The state the package should be in, either "installed" or "uninstalled" + + +OPTIONAL PARAMETERS +------------------- +name:: + The name of the package to install. Default is to use the object_id as the + package name. +version:: + FIXME: not yet implemented + The version of the package to install. Default is to install the version + choosen by the local package manager. + + +EXAMPLES +-------- + +-------------------------------------------------------------------------------- +# Install the package vim on the target +__package_emerge screen --state installed + +# Same but use full qualified package name +__package_emerge app-misc/screen --state installed + +# Same but use install specific package version +# FIXME: not yet implemented +__package_emerge app-misc/screen --state installed --version 4.0.3 +-------------------------------------------------------------------------------- + + +SEE ALSO +-------- +- cdist-type(7) + + +COPYING +------- +Copyright \(C) 2011 Steven Armstrong. Free use of this software is +granted under the terms of the GNU General Public License version 3 (GPLv3). From bead47f6bf52862c7f3e5df5b2a91304f1b39009 Mon Sep 17 00:00:00 2001 From: Steven Armstrong Date: Tue, 15 Mar 2011 17:10:27 +0100 Subject: [PATCH 07/15] remove currently unhandled parameter Signed-off-by: Steven Armstrong --- conf/type/__package_emerge/parameter/optional | 1 - 1 file changed, 1 deletion(-) diff --git a/conf/type/__package_emerge/parameter/optional b/conf/type/__package_emerge/parameter/optional index a52167d3..f121bdbf 100644 --- a/conf/type/__package_emerge/parameter/optional +++ b/conf/type/__package_emerge/parameter/optional @@ -1,2 +1 @@ name -version From f5ed590e16995eb2b10da52c8b57b6d1582f68d1 Mon Sep 17 00:00:00 2001 From: Steven Armstrong Date: Tue, 15 Mar 2011 17:15:35 +0100 Subject: [PATCH 08/15] changelog++ Signed-off-by: Steven Armstrong --- doc/changelog | 3 +++ 1 file changed, 3 insertions(+) diff --git a/doc/changelog b/doc/changelog index c939b547..534f4c3e 100644 --- a/doc/changelog +++ b/doc/changelog @@ -2,6 +2,9 @@ * New type __motd * New type __addifnosuchline * Document type __issue + * New type __user + * Document type __package + * Document type __package_emerge 1.0.3: 2011-03-11 * Update regexp used for sane characters From 88e48c391e2ab3361bf76ad107c408933cb556a7 Mon Sep 17 00:00:00 2001 From: Steven Armstrong Date: Tue, 15 Mar 2011 17:19:20 +0100 Subject: [PATCH 09/15] fix borken paths in cdist-type-template Signed-off-by: Steven Armstrong --- bin/cdist-type-template | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/bin/cdist-type-template b/bin/cdist-type-template index 0391510c..cd34027c 100755 --- a/bin/cdist-type-template +++ b/bin/cdist-type-template @@ -37,7 +37,7 @@ touch "$(__cdist_type_parameter_dir "$__cdist_type")/${__cdist_name_parameter_re touch "$(__cdist_type_parameter_dir "$__cdist_type")/${__cdist_name_parameter_optional}" # Manifest -cat "$__cdist_abs_mydir/../doc/dev/header" - << eof > "$(__cdist_type_parameter_dir "$__cdist_type")/${__cdist_name_manifest}" +cat "$__cdist_abs_mydir/../doc/dev/header" - << eof > "$(__cdist_type_dir "$__cdist_type")/${__cdist_name_manifest}" # # This is the manifest, which can be used to create other objects like this: @@ -50,7 +50,7 @@ cat "$__cdist_abs_mydir/../doc/dev/header" - << eof > "$(__cdist_type_parameter_ eof # Gencode -cat "$__cdist_abs_mydir/../doc/dev/header" - << eof > "$(__cdist_type_parameter_dir "$__cdist_type")/${__cdist_name_gencode}" +cat "$__cdist_abs_mydir/../doc/dev/header" - << eof > "$(__cdist_type_dir "$__cdist_type")/${__cdist_name_gencode}" # # This file should generate code on stdout, which will be collected by cdist @@ -63,4 +63,4 @@ cat "$__cdist_abs_mydir/../doc/dev/header" - << eof > "$(__cdist_type_parameter_ eof # Explorer -mkdir -p "$(__cdist_type_parameter_dir "$__cdist_type")/${__cdist_name_explorer}" +mkdir -p "$(__cdist_type_dir "$__cdist_type")/${__cdist_name_explorer}" From 42c87edad1bafbb143822ef3f3bf43363a6d1b46 Mon Sep 17 00:00:00 2001 From: Steven Armstrong Date: Tue, 15 Mar 2011 20:52:52 +0100 Subject: [PATCH 10/15] moved __package_gentoo to gentoo branch Signed-off-by: Steven Armstrong --- conf/type/__package_emerge/gencode | 43 -------------- conf/type/__package_emerge/man.text | 58 ------------------- conf/type/__package_emerge/manifest | 36 ------------ conf/type/__package_emerge/parameter/optional | 1 - conf/type/__package_emerge/parameter/required | 1 - 5 files changed, 139 deletions(-) delete mode 100755 conf/type/__package_emerge/gencode delete mode 100644 conf/type/__package_emerge/man.text delete mode 100755 conf/type/__package_emerge/manifest delete mode 100644 conf/type/__package_emerge/parameter/optional delete mode 100644 conf/type/__package_emerge/parameter/required diff --git a/conf/type/__package_emerge/gencode b/conf/type/__package_emerge/gencode deleted file mode 100755 index 47e8bc5e..00000000 --- a/conf/type/__package_emerge/gencode +++ /dev/null @@ -1,43 +0,0 @@ -#!/bin/sh -# -# 2011 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 . -# -# -# Manage packages on gentoo. -# - -if [ -f "$__object/parameter/name" ]; then - name="$(cat "$__object/parameter/name")" -else - name="$__object_id" -fi - -state="$(cat "$__object/parameter/state")" - -case "$state" in - installed) - # FIXME: only install if not already installed - echo "emerge -q \"$name\"" - ;; - uninstalled) - # FIXME: only uninstall if currently installed - echo "emerge -q -C \"$name\"" - ;; -esac - -exit 0 diff --git a/conf/type/__package_emerge/man.text b/conf/type/__package_emerge/man.text deleted file mode 100644 index 002821dd..00000000 --- a/conf/type/__package_emerge/man.text +++ /dev/null @@ -1,58 +0,0 @@ -cdist-type__user(7) -=================== -Steven Armstrong - - -NAME ----- -cdist-type__package_emerge - Manage packages on Gentoo Linux - - -DESCRIPTION ------------ -This cdist type allows you to install or uninstall packages on a Gentoo Linux -target. - - -REQUIRED PARAMETERS -------------------- -state:: - The state the package should be in, either "installed" or "uninstalled" - - -OPTIONAL PARAMETERS -------------------- -name:: - The name of the package to install. Default is to use the object_id as the - package name. -version:: - FIXME: not yet implemented - The version of the package to install. Default is to install the version - choosen by the local package manager. - - -EXAMPLES --------- - --------------------------------------------------------------------------------- -# Install the package vim on the target -__package_emerge screen --state installed - -# Same but use full qualified package name -__package_emerge app-misc/screen --state installed - -# Same but use install specific package version -# FIXME: not yet implemented -__package_emerge app-misc/screen --state installed --version 4.0.3 --------------------------------------------------------------------------------- - - -SEE ALSO --------- -- cdist-type(7) - - -COPYING -------- -Copyright \(C) 2011 Steven Armstrong. Free use of this software is -granted under the terms of the GNU General Public License version 3 (GPLv3). diff --git a/conf/type/__package_emerge/manifest b/conf/type/__package_emerge/manifest deleted file mode 100755 index 178fa510..00000000 --- a/conf/type/__package_emerge/manifest +++ /dev/null @@ -1,36 +0,0 @@ -#!/bin/sh -# -# 2011 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 . -# -# -# __package is an abstract type which dispatches to the lower level -# __package_$name types which do the actual interaction with the packaging -# system. -# - -# TODO: depend on package gentoolkit for qpkg - -# TODO: -# if /var/cache/eix is older then /usr/portage/metadata/timestamp -# then run /usr/bin/eix-update -# -# check if package is installed: -# -# get currently installed version: -# - diff --git a/conf/type/__package_emerge/parameter/optional b/conf/type/__package_emerge/parameter/optional deleted file mode 100644 index f121bdbf..00000000 --- a/conf/type/__package_emerge/parameter/optional +++ /dev/null @@ -1 +0,0 @@ -name diff --git a/conf/type/__package_emerge/parameter/required b/conf/type/__package_emerge/parameter/required deleted file mode 100644 index ff72b5c7..00000000 --- a/conf/type/__package_emerge/parameter/required +++ /dev/null @@ -1 +0,0 @@ -state From 1518bf19353294c6b0b95e35f838b2a27a59daa3 Mon Sep 17 00:00:00 2001 From: Steven Armstrong Date: Tue, 15 Mar 2011 23:11:01 +0100 Subject: [PATCH 11/15] __user: only run commands if value has changed Signed-off-by: Steven Armstrong --- conf/type/__user/TODO | 1 - conf/type/__user/gencode | 28 +++++++++++++++++++++++++--- 2 files changed, 25 insertions(+), 4 deletions(-) diff --git a/conf/type/__user/TODO b/conf/type/__user/TODO index 5c2eec7d..fa6aeee7 100644 --- a/conf/type/__user/TODO +++ b/conf/type/__user/TODO @@ -1,3 +1,2 @@ -- gencode: compair new value with existing one in $__object/explorer/passwd, only change if nessecary - delete users diff --git a/conf/type/__user/gencode b/conf/type/__user/gencode index 7445d6f8..ca31f7d3 100755 --- a/conf/type/__user/gencode +++ b/conf/type/__user/gencode @@ -33,12 +33,34 @@ else fi +get_current_value() { + local key="$1" + local index + case "$key" in + uid) index=3;; + gid) index=4;; + comment) index=5;; + home) index=6;; + shell) index=7;; + esac + cut -d':' -f $index "$__object/explorer/passwd" +} + + set -- "$@" cd "$__object/parameter" for property in $(ls .); do - # TODO: compair new value with existing one in $__object/explorer/passwd, only change if nessecary - set -- "$@" "--$property" "$(cat "$property")" + current_value=$(get_current_value "$property") + new_value="$(cat "$property")" + if [ "$new_value" != "$current_value" ]; then + # Shedule changed properties for update + set -- "$@" "--$property" \"$new_value\" + fi done -echo $command $@ $name + +if [ $# -gt 0 ]; then + # Update changed properties + echo $command $@ $name +fi From 4432b476d08c812e9ee6221049c9ee7095143512 Mon Sep 17 00:00:00 2001 From: Steven Armstrong Date: Tue, 15 Mar 2011 23:26:24 +0100 Subject: [PATCH 12/15] __user: only set password if it changed Signed-off-by: Steven Armstrong --- conf/type/__user/explorer/shadow | 27 +++++++++++++++++++++++++++ conf/type/__user/gencode | 4 ++++ 2 files changed, 31 insertions(+) create mode 100755 conf/type/__user/explorer/shadow diff --git a/conf/type/__user/explorer/shadow b/conf/type/__user/explorer/shadow new file mode 100755 index 00000000..eab6b2b8 --- /dev/null +++ b/conf/type/__user/explorer/shadow @@ -0,0 +1,27 @@ +#!/bin/sh +# +# 2011 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 . +# +# +# Get an existing users shadow entry. +# + +name=$__object_id + +grep "^$name" /etc/shadow || true + diff --git a/conf/type/__user/gencode b/conf/type/__user/gencode index ca31f7d3..5990ac92 100755 --- a/conf/type/__user/gencode +++ b/conf/type/__user/gencode @@ -37,6 +37,10 @@ get_current_value() { local key="$1" local index case "$key" in + password) + cut -d':' -f 2 "$__object/explorer/shadow" + break + ;; uid) index=3;; gid) index=4;; comment) index=5;; From 58718f735aee1f519816ba07e4d7deca44786bb6 Mon Sep 17 00:00:00 2001 From: Steven Armstrong Date: Tue, 15 Mar 2011 23:35:55 +0100 Subject: [PATCH 13/15] use getent to get entry from shadow database Signed-off-by: Steven Armstrong --- conf/type/__user/explorer/shadow | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/conf/type/__user/explorer/shadow b/conf/type/__user/explorer/shadow index eab6b2b8..c75e36f4 100755 --- a/conf/type/__user/explorer/shadow +++ b/conf/type/__user/explorer/shadow @@ -23,5 +23,5 @@ name=$__object_id -grep "^$name" /etc/shadow || true +getent shadow "$name" || true From ec99a22db61ee537836334fdfaa57f5968325b18 Mon Sep 17 00:00:00 2001 From: Steven Armstrong Date: Tue, 15 Mar 2011 23:37:17 +0100 Subject: [PATCH 14/15] add new type __group Signed-off-by: Steven Armstrong --- conf/type/__group/TODO | 2 + conf/type/__group/explorer/group | 27 ++++++++++++ conf/type/__group/explorer/gshadow | 27 ++++++++++++ conf/type/__group/gencode | 66 ++++++++++++++++++++++++++++ conf/type/__group/man.text | 62 ++++++++++++++++++++++++++ conf/type/__group/parameter/optional | 2 + 6 files changed, 186 insertions(+) create mode 100644 conf/type/__group/TODO create mode 100755 conf/type/__group/explorer/group create mode 100755 conf/type/__group/explorer/gshadow create mode 100755 conf/type/__group/gencode create mode 100644 conf/type/__group/man.text create mode 100644 conf/type/__group/parameter/optional diff --git a/conf/type/__group/TODO b/conf/type/__group/TODO new file mode 100644 index 00000000..c20a5d21 --- /dev/null +++ b/conf/type/__group/TODO @@ -0,0 +1,2 @@ +- delete groups + diff --git a/conf/type/__group/explorer/group b/conf/type/__group/explorer/group new file mode 100755 index 00000000..4c1e6ac0 --- /dev/null +++ b/conf/type/__group/explorer/group @@ -0,0 +1,27 @@ +#!/bin/sh +# +# 2011 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 . +# +# +# Get an existing groups group entry. +# + +name=$__object_id + +getent group "$name" || true + diff --git a/conf/type/__group/explorer/gshadow b/conf/type/__group/explorer/gshadow new file mode 100755 index 00000000..51d502a1 --- /dev/null +++ b/conf/type/__group/explorer/gshadow @@ -0,0 +1,27 @@ +#!/bin/sh +# +# 2011 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 . +# +# +# Get an existing groups gshadow entry. +# + +name=$__object_id + +getent gshadow "$name" || true + diff --git a/conf/type/__group/gencode b/conf/type/__group/gencode new file mode 100755 index 00000000..527a6079 --- /dev/null +++ b/conf/type/__group/gencode @@ -0,0 +1,66 @@ +#!/bin/sh +# +# 2011 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 . +# +# +# Manage groups. +# + +name="$__object_id" + +command= +if grep -q "^$name" "$__object/explorer/group"; then + # group exists + command="groupmod" +else + # group does not exist + command="groupadd" +fi + + +get_current_value() { + local key="$1" + local index + case "$key" in + password) + cut -d':' -f 2 "$__object/explorer/gshadow" + break + ;; + gid) index=3;; + esac + cut -d':' -f $index "$__object/explorer/group" +} + + +set -- "$@" +cd "$__object/parameter" +for property in $(ls .); do + current_value=$(get_current_value "$property") + new_value="$(cat "$property")" + if [ "$new_value" != "$current_value" ]; then + # Shedule changed properties for update + set -- "$@" "--$property" \"$new_value\" + fi +done + + +if [ $# -gt 0 ]; then + # Update changed properties + echo $command $@ $name +fi + diff --git a/conf/type/__group/man.text b/conf/type/__group/man.text new file mode 100644 index 00000000..e571c7c5 --- /dev/null +++ b/conf/type/__group/man.text @@ -0,0 +1,62 @@ +cdist-type__user(7) +=================== +Steven Armstrong + + +NAME +---- +cdist-type__user - Manage users + + +DESCRIPTION +----------- +This cdist type allows you to create or modify users on the target. + + +REQUIRED PARAMETERS +------------------- +None. + + +OPTIONAL PARAMETERS +------------------- +comment:: + see usermod(8) +home:: + see above +gid:: + see above +groups:: + see above +password:: + see above +shell:: + see above +uid:: + see above + + +EXAMPLES +-------- + +-------------------------------------------------------------------------------- +# Create user account for foobar with operating system default settings +__user foobar + +# Same but with a different shell +__user foobar --shell /bin/zsh + +# Set explicit uid and home +__user foobar --uid 1001 --shell /bin/zsh --home /home/foobar +-------------------------------------------------------------------------------- + + +SEE ALSO +-------- +- cdist-type(7) + + +COPYING +------- +Copyright \(C) 2011 Steven Armstrong. Free use of this software is +granted under the terms of the GNU General Public License version 3 (GPLv3). diff --git a/conf/type/__group/parameter/optional b/conf/type/__group/parameter/optional new file mode 100644 index 00000000..4c661c8f --- /dev/null +++ b/conf/type/__group/parameter/optional @@ -0,0 +1,2 @@ +gid +password From af0b62ecef6722c3a2ec7848315c4eebdb67b946 Mon Sep 17 00:00:00 2001 From: Steven Armstrong Date: Tue, 15 Mar 2011 23:41:30 +0100 Subject: [PATCH 15/15] update man page for __group type Signed-off-by: Steven Armstrong --- conf/type/__group/man.text | 30 ++++++++++-------------------- 1 file changed, 10 insertions(+), 20 deletions(-) diff --git a/conf/type/__group/man.text b/conf/type/__group/man.text index e571c7c5..26b52111 100644 --- a/conf/type/__group/man.text +++ b/conf/type/__group/man.text @@ -1,16 +1,16 @@ -cdist-type__user(7) +cdist-type__group(7) =================== Steven Armstrong NAME ---- -cdist-type__user - Manage users +cdist-type__group - Manage groups DESCRIPTION ----------- -This cdist type allows you to create or modify users on the target. +This cdist type allows you to create or modify groups on the target. REQUIRED PARAMETERS @@ -20,34 +20,24 @@ None. OPTIONAL PARAMETERS ------------------- -comment:: - see usermod(8) -home:: - see above gid:: - see above -groups:: - see above + see groupmod(8) password:: see above -shell:: - see above -uid:: - see above EXAMPLES -------- -------------------------------------------------------------------------------- -# Create user account for foobar with operating system default settings -__user foobar +# Create a group 'foobar' with operating system default settings +__group foobar -# Same but with a different shell -__user foobar --shell /bin/zsh +# Same but with a specific gid +__group foobar --gid 1234 -# Set explicit uid and home -__user foobar --uid 1001 --shell /bin/zsh --home /home/foobar +# Same but with a gid and password +__group foobar --gid 1234 --password 'crypted-password-string' --------------------------------------------------------------------------------