WIP: __directory to support --source path #376

Draft
smwltr wants to merge 1 commit from smwltr/cdist:directory_source into master
4 changed files with 74 additions and 0 deletions
Showing only changes of commit a072dc9367 - Show all commits

View file

@ -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 <http://www.gnu.org/licenses/>.
#
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

View file

@ -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
------------------

View file

@ -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 <http://www.gnu.org/licenses/>.
#
# 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

View file

@ -2,3 +2,4 @@ state
group
mode
owner
source