diff --git a/cdist/conf/type/__directory/gencode-local b/cdist/conf/type/__directory/gencode-local new file mode 100644 index 00000000..e8120fa0 --- /dev/null +++ b/cdist/conf/type/__directory/gencode-local @@ -0,0 +1,32 @@ +#!/bin/sh +# +# 2022 Simon Walter (simon at explicit dot technology) +# +# 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 . +# + +destination="/$__object_id" + +if [ -f "$__object/parameter/source" ]; then + source="$(cat $__object/parameter/source)" + # -rp is compatible with both scp and rsync default __remote_copy + # However, the default rsync has a --backup switch which will fill up disk + # especially with large number of files. + cat << DONE +$__remote_exec $__target_host "mkdir -p $destination" +$__remote_copy -rp "$source" "${__target_host}:$destination" +DONE +fi diff --git a/cdist/conf/type/__directory/man.rst b/cdist/conf/type/__directory/man.rst index 7755334c..b0e0048f 100644 --- a/cdist/conf/type/__directory/man.rst +++ b/cdist/conf/type/__directory/man.rst @@ -41,6 +41,9 @@ mode owner User to chown to. +source + If provided, the contents of this path will be copied to the directory. + BOOLEAN PARAMETERS ------------------ diff --git a/cdist/conf/type/__directory/manifest b/cdist/conf/type/__directory/manifest new file mode 100644 index 00000000..838a5abc --- /dev/null +++ b/cdist/conf/type/__directory/manifest @@ -0,0 +1,38 @@ +#!/bin/sh +# +# 2022 Simon Walter (simon at explicit dot technology) +# +# 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 . +# + +# FIXME: What does cdist use for unit testing? +# FIXME: Output to stderr is no longer visible by default. Is there a correct +# way to do this? + +if [ -f "$__object/parameter/source" ]; then + export source="$(cat "$__object/parameter/source")" + if [ -d "$source" ]; then + if [ "$(ls "$source" | wc -w)" -gt 0 ]; then + echo "Copying files from (--source): $source" >&2 + # See gencode-local + else + echo "No files in (--source): $source" >&2 + fi + else + echo "Directory (--source) not found: $source" >&2 + fi +fi + diff --git a/cdist/conf/type/__directory/parameter/optional b/cdist/conf/type/__directory/parameter/optional index 08798bc5..c696d592 100644 --- a/cdist/conf/type/__directory/parameter/optional +++ b/cdist/conf/type/__directory/parameter/optional @@ -2,3 +2,4 @@ state group mode owner +source