From 8b91e3116afda0a20d4da5e0554fac9b5759c39f Mon Sep 17 00:00:00 2001 From: Nico Schottelius Date: Wed, 5 Dec 2012 23:07:21 +0100 Subject: [PATCH] create working version of __git Signed-off-by: Nico Schottelius --- cdist/conf/type/__git/explorer/state | 30 ++++++++++++++++ cdist/conf/type/__git/gencode-remote | 46 ++++++++++++++++++++++++ cdist/conf/type/__git/man.text | 30 ++++------------ cdist/conf/type/__git/manifest | 33 ++++++++++++++++- cdist/conf/type/__git/parameter/optional | 2 ++ 5 files changed, 116 insertions(+), 25 deletions(-) create mode 100755 cdist/conf/type/__git/explorer/state create mode 100644 cdist/conf/type/__git/parameter/optional diff --git a/cdist/conf/type/__git/explorer/state b/cdist/conf/type/__git/explorer/state new file mode 100755 index 00000000..e0719579 --- /dev/null +++ b/cdist/conf/type/__git/explorer/state @@ -0,0 +1,30 @@ +#!/bin/sh +# +# 2012 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 . +# +# +# Check whether repository exists +# + +destination="/$__object_id/.git" + +if [ -d "$destination" ]; then + echo present +else + echo absent +fi diff --git a/cdist/conf/type/__git/gencode-remote b/cdist/conf/type/__git/gencode-remote index 8b137891..0f665d59 100644 --- a/cdist/conf/type/__git/gencode-remote +++ b/cdist/conf/type/__git/gencode-remote @@ -1 +1,47 @@ +#!/bin/sh +# +# 2012 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 . +# +# +state_is="$(cat "$__object/explorer/state")" +state_should=present +[ -f "$__object/parameter/state" ] && state_should="$(cat "$__object/parameter/state")" + +branch=master +[ -f "$__object/parameter/branch" ] && branch="$(cat "$__object/parameter/branch")" + +source="$(cat "$__object/parameter/source")" + +destination="/$__object_id" + +[ "$state_should" = "$state_is" ] && exit 0 + +case $state_should in + present) + echo git clone --quiet --branch "$branch" "$source" "$destination" + ;; + # Handled in manifest + absent) + ;; + + *) + echo "Unknown state: $state_should" >&2 + exit 1 + ;; +esac diff --git a/cdist/conf/type/__git/man.text b/cdist/conf/type/__git/man.text index 230f43c3..5597a52d 100644 --- a/cdist/conf/type/__git/man.text +++ b/cdist/conf/type/__git/man.text @@ -10,8 +10,7 @@ cdist-type__git - Get and or keep git repositories up-to-date DESCRIPTION ----------- -This cdist type allows you to clone and keep git repositories -up-to-date. +This cdist type allows you to clone git repositories REQUIRED PARAMETERS @@ -22,38 +21,21 @@ source:: OPTIONAL PARAMETERS ------------------- -name:: - If supplied, use the name and not the object id as the package name. - state:: Either "present" or "absent", defaults to "present" branch:: - The remote branch to check out - -BOOLEAN PARAMETERS ------------------- -up-to-date:: - Whether to git merge on each run + Create this branch by checking out the remote branch of this name EXAMPLES -------- -------------------------------------------------------------------------------- -# Create hard git of /etc/shadow -__git /home/services/dokuwiki --source /etc/shadow --type hard +__git /home/services/dokuwiki --source git://github.com/splitbrain/dokuwiki.git -# Relative symbolic git -__git /etc/apache2/sites-enabled/www.test.ch \ - --source ../sites-available/www.test.ch \ - --type symbolic - -# Absolute symbolic git -__git /opt/plone --source /home/services/plone --type symbolic - -# Remove git -__git /opt/plone --state absent +# Checkout cdist, stay on branch 2.1 +__git /home/nico/cdist --source git://github.com/telmich/cdist.git --branch 2.1 -------------------------------------------------------------------------------- @@ -64,5 +46,5 @@ SEE ALSO COPYING ------- -Copyright \(C) 2011-2012 Nico Schottelius. Free use of this software is +Copyright \(C) 2012 Nico Schottelius. 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/__git/manifest b/cdist/conf/type/__git/manifest index c0eb2c23..866515d7 100644 --- a/cdist/conf/type/__git/manifest +++ b/cdist/conf/type/__git/manifest @@ -1 +1,32 @@ -__package git +#!/bin/sh +# +# 2012 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 . +# +# +# Ensure git is present +# + +__package git --state present + +state_should=present +[ -f "$__object/parameter/state" ] && state_should="$(cat "$__object/parameter/state")" + +# Let __directory handle removal of git repos +if [ "$state_should" = absent ]; then + __directory "$__object_id" --state absent +fi diff --git a/cdist/conf/type/__git/parameter/optional b/cdist/conf/type/__git/parameter/optional new file mode 100644 index 00000000..671134d6 --- /dev/null +++ b/cdist/conf/type/__git/parameter/optional @@ -0,0 +1,2 @@ +state +branch