[__download] add --download (local|remote), update manual

This commit is contained in:
ander 2020-06-28 16:38:15 +03:00
parent 26dfdf37c2
commit 85614aabd6
7 changed files with 65 additions and 12 deletions

View file

@ -0,0 +1,19 @@
#!/bin/sh -e
if [ -f "$__object/parameter/cmd-get" ]
then
cmd="$( cat "$__object/parameter/cmd-get" )"
elif command -v curl > /dev/null
then
cmd="curl -o - '%s'"
elif command -v fetch > /dev/null
then
cmd="fetch -o - '%s'"
else
cmd="wget -O - '%s'"
fi
echo "$cmd"

View file

@ -1,8 +1,10 @@
#!/bin/sh -e #!/bin/sh -e
download="$( cat "$__object/parameter/download" )"
state_is="$( cat "$__object/explorer/state" )" state_is="$( cat "$__object/explorer/state" )"
if [ "$state_is" = 'present' ] if [ "$download" != 'local' ] || [ "$state_is" = 'present' ]
then then
exit 0 exit 0
fi fi

View file

@ -1,7 +1,25 @@
#!/bin/sh -e #!/bin/sh -e
if [ -f "$__object/parameter/onchange" ] \ download="$( cat "$__object/parameter/download" )"
&& grep -Fq "$__object_id:downloaded" "$__messages_in"
state_is="$( cat "$__object/explorer/state" )"
if [ "$download" = 'remote' ] && [ "$state_is" != 'present' ]
then
cmd="$( cat "$__object/explorer/remote_cmd" )"
url="$( cat "$__object/parameter/url" )"
dst="/$__object_id"
printf "$cmd > %s\n" \
"$url" \
"$dst"
echo 'downloaded' > "$__messages_out"
fi
if [ -f "$__object/parameter/onchange" ] && [ "$state" != "present" ]
then then
cat "$__object/parameter/onchange" cat "$__object/parameter/onchange"
fi fi

View file

@ -3,26 +3,28 @@ cdist-type__download(7)
NAME NAME
---- ----
cdist-type__download - Download file to local storage and copy it to target host cdist-type__download - Download a file
DESCRIPTION DESCRIPTION
----------- -----------
You must use persistent storage in target host for destination file Persistent storage for destination file in target host must be used
(``$__object_id``) because it will be used for checksum calculation (``$__object_id``) because it will be used for checksum calculation in
in order to decide if file must be (re-)downloaded. order to decide if file must be (re-)downloaded.
By default type will try to use following locally installed utilities By default type will try to use ``wget``, ``curl`` or ``fetch`` for
for downloading (in order): ``wget``, ``curl`` or ``fetch``. downloading. If ``--download remote`` type will fallback to (and
install) ``wget``.
Environment variables like ``{http,https,ftp}_proxy`` etc can be used on If ``--download local`` (default), then environment variables like
cdist execution (``http_proxy=foo cdist config ...``). ``{http,https,ftp}_proxy`` etc can be used on cdist execution
(``http_proxy=foo cdist config ...``).
REQUIRED PARAMETERS REQUIRED PARAMETERS
------------------- -------------------
url url
URL from which to download the file. File's URL.
sum sum
Checksum of file going to be downloaded. Checksum of file going to be downloaded.
@ -35,6 +37,10 @@ onchange
OPTIONAL PARAMETERS OPTIONAL PARAMETERS
------------------- -------------------
download
If ``local`` (default), then download file to local storage and copy
it to target host. If ``remote``, then download happens in target.
cmd-get cmd-get
Command used for downloading. Command used for downloading.
Command must output to ``stdout``. Command must output to ``stdout``.

View file

@ -0,0 +1,6 @@
#!/bin/sh -e
if grep -Eq '^wget' "$__object/explorer/remote_cmd"
then
__package wget
fi

View file

@ -0,0 +1 @@
local

View file

@ -1,3 +1,4 @@
cmd-get cmd-get
cmd-sum cmd-sum
download
onchange onchange