diff --git a/cdist/conf/type/__git/explorer/group b/cdist/conf/type/__git/explorer/group new file mode 100644 index 00000000..1308c710 --- /dev/null +++ b/cdist/conf/type/__git/explorer/group @@ -0,0 +1,5 @@ +#!/bin/sh + +destination="/$__object_id/.git" + +stat --print "%G" ${destination} 2>/dev/null || exit 0 diff --git a/cdist/conf/type/__git/explorer/owner b/cdist/conf/type/__git/explorer/owner new file mode 100644 index 00000000..8c36b035 --- /dev/null +++ b/cdist/conf/type/__git/explorer/owner @@ -0,0 +1,5 @@ +#!/bin/sh + +destination="/$__object_id/.git" + +stat --print "%U" ${destination} 2>/dev/null || exit 0 diff --git a/cdist/conf/type/__git/gencode-remote b/cdist/conf/type/__git/gencode-remote index 0f665d59..bc0c66cc 100644 --- a/cdist/conf/type/__git/gencode-remote +++ b/cdist/conf/type/__git/gencode-remote @@ -20,6 +20,9 @@ # state_is="$(cat "$__object/explorer/state")" +owner_is="$(cat "$__object/explorer/owner")" +group_is="$(cat "$__object/explorer/group")" + state_should=present [ -f "$__object/parameter/state" ] && state_should="$(cat "$__object/parameter/state")" @@ -30,11 +33,31 @@ source="$(cat "$__object/parameter/source")" destination="/$__object_id" -[ "$state_should" = "$state_is" ] && exit 0 +owner="" +[ -f "$__object/parameter/owner" ] && owner="$(cat "$__object/parameter/owner")" +group="" +[ -f "$__object/parameter/group" ] && group="$(cat "$__object/parameter/group")" +mode="" +[ -f "$__object/parameter/mode" ] && mode="$(cat "$__object/parameter/mode")" + +[ "$state_should" = "$state_is" -a \ + "$owner" = "$owner_is" -a \ + "$group" = "$group_is" -a \ + -n "$mode" ] && exit 0 case $state_should in present) - echo git clone --quiet --branch "$branch" "$source" "$destination" + + if [ "$state_should" != "$state_is" ]; then + echo git clone --quiet --branch "$branch" "$source" "$destination" + fi + if [ \( -n ${owner} -a "$owner_is" != "$owner" \) -o \ + \( -n ${group} -a "$group_is" != "$group" \) ]; then + echo chown -R ${owner}:${group} ${destination} + fi + if [ -n ${mode} ]; then + echo chmod -R ${mode} ${destination} + fi ;; # Handled in manifest absent) diff --git a/cdist/conf/type/__git/manifest b/cdist/conf/type/__git/manifest index 3b52ad2d..8d6a29e4 100644 --- a/cdist/conf/type/__git/manifest +++ b/cdist/conf/type/__git/manifest @@ -26,9 +26,6 @@ __package git --state present state_should=present [ -f "$__object/parameter/state" ] && state_should="$(cat "$__object/parameter/state")" -[ -f "$__object/parameter/owner" ] && dirparams="$dirparams --owner $(cat "$__object/parameter/owner")" -[ -f "$__object/parameter/group" ] && dirparams="$dirparams --group $(cat "$__object/parameter/group")" - # Let __directory handle removal of git repos case "$state_should" in diff --git a/cdist/conf/type/__git/parameter/optional b/cdist/conf/type/__git/parameter/optional index d9684aaa..3c409162 100644 --- a/cdist/conf/type/__git/parameter/optional +++ b/cdist/conf/type/__git/parameter/optional @@ -2,3 +2,4 @@ state branch group owner +mode