forked from ungleich-public/cdist
		
	Merge branch '__download' into 'master'
new type: __download See merge request ungleich-public/cdist!892
This commit is contained in:
		
				commit
				
					
						d59ba09d71
					
				
			
		
					 7 changed files with 127 additions and 0 deletions
				
			
		
							
								
								
									
										20
									
								
								cdist/conf/type/__download/explorer/state
									
										
									
									
									
										Executable file
									
								
							
							
						
						
									
										20
									
								
								cdist/conf/type/__download/explorer/state
									
										
									
									
									
										Executable file
									
								
							| 
						 | 
				
			
			@ -0,0 +1,20 @@
 | 
			
		|||
#!/bin/sh -e
 | 
			
		||||
 | 
			
		||||
dst="/$__object_id"
 | 
			
		||||
 | 
			
		||||
# shellcheck disable=SC2059
 | 
			
		||||
cmd="$( printf "$( cat "$__object/parameter/cmd-sum" )" "$dst" )"
 | 
			
		||||
 | 
			
		||||
sum="$( cat "$__object/parameter/sum" )"
 | 
			
		||||
 | 
			
		||||
if [ -f "$dst" ]
 | 
			
		||||
then
 | 
			
		||||
    if [ "$( eval "$cmd" )" = "$sum" ]
 | 
			
		||||
    then
 | 
			
		||||
        echo 'present'
 | 
			
		||||
    else
 | 
			
		||||
        echo 'mismatch'
 | 
			
		||||
    fi
 | 
			
		||||
else
 | 
			
		||||
    echo 'absent'
 | 
			
		||||
fi
 | 
			
		||||
							
								
								
									
										35
									
								
								cdist/conf/type/__download/gencode-local
									
										
									
									
									
										Executable file
									
								
							
							
						
						
									
										35
									
								
								cdist/conf/type/__download/gencode-local
									
										
									
									
									
										Executable file
									
								
							| 
						 | 
				
			
			@ -0,0 +1,35 @@
 | 
			
		|||
#!/bin/sh -e
 | 
			
		||||
 | 
			
		||||
state_is="$( cat "$__object/explorer/state" )"
 | 
			
		||||
 | 
			
		||||
if [ "$state_is" = 'present' ]
 | 
			
		||||
then
 | 
			
		||||
    exit 0
 | 
			
		||||
fi
 | 
			
		||||
 | 
			
		||||
url="$( cat "$__object/parameter/url" )"
 | 
			
		||||
 | 
			
		||||
cmd="$( cat "$__object/parameter/cmd-get" )"
 | 
			
		||||
 | 
			
		||||
tmp="$( mktemp )"
 | 
			
		||||
 | 
			
		||||
dst="/$__object_id"
 | 
			
		||||
 | 
			
		||||
printf "$cmd > %s\n" \
 | 
			
		||||
    "$url" \
 | 
			
		||||
    "$tmp"
 | 
			
		||||
 | 
			
		||||
if echo "$__target_host" | grep -Eq '^[0-9a-fA-F:]+$'
 | 
			
		||||
then
 | 
			
		||||
    target_host="[$__target_host]"
 | 
			
		||||
else
 | 
			
		||||
    target_host="$__target_host"
 | 
			
		||||
fi
 | 
			
		||||
 | 
			
		||||
printf '%s %s %s:%s\n' \
 | 
			
		||||
    "$__remote_copy" \
 | 
			
		||||
    "$tmp" \
 | 
			
		||||
    "$target_host" \
 | 
			
		||||
    "$dst"
 | 
			
		||||
 | 
			
		||||
echo "rm -f '$tmp'"
 | 
			
		||||
							
								
								
									
										66
									
								
								cdist/conf/type/__download/man.rst
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										66
									
								
								cdist/conf/type/__download/man.rst
									
										
									
									
									
										Normal file
									
								
							| 
						 | 
				
			
			@ -0,0 +1,66 @@
 | 
			
		|||
cdist-type__download(7)
 | 
			
		||||
=======================
 | 
			
		||||
 | 
			
		||||
NAME
 | 
			
		||||
----
 | 
			
		||||
cdist-type__download - Download file to local storage and copy it to target host
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
DESCRIPTION
 | 
			
		||||
-----------
 | 
			
		||||
You must use persistent storage in target host for destination file
 | 
			
		||||
(``$__object_id``) because it will be used for checksum calculation
 | 
			
		||||
in order to decide if file must be downloaded.
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
REQUIRED PARAMETERS
 | 
			
		||||
-------------------
 | 
			
		||||
url
 | 
			
		||||
   URL from which to download the file.
 | 
			
		||||
 | 
			
		||||
sum
 | 
			
		||||
   Checksum of downloaded file.
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
OPTIONAL PARAMETERS
 | 
			
		||||
-------------------
 | 
			
		||||
cmd-get
 | 
			
		||||
   Command used for downloading.
 | 
			
		||||
   Default is ``wget -O- '%s'``.
 | 
			
		||||
   Command must output to ``stdout``.
 | 
			
		||||
 | 
			
		||||
cmd-sum
 | 
			
		||||
   Command used for checksum calculation.
 | 
			
		||||
   Default is ``md5sum '%s' | awk '{print $1}'``.
 | 
			
		||||
   Command output and ``--sum`` parameter must match.
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
EXAMPLES
 | 
			
		||||
--------
 | 
			
		||||
 | 
			
		||||
.. code-block:: sh
 | 
			
		||||
 | 
			
		||||
    __directory /opt/cpma
 | 
			
		||||
 | 
			
		||||
    require='__directory/opt/cpma' \
 | 
			
		||||
        __download /opt/cpma/cnq3.zip \
 | 
			
		||||
            --url https://cdn.playmorepromode.com/files/cnq3/cnq3-1.51.zip \
 | 
			
		||||
            --sum 46da3021ca9eace277115ec9106c5b46
 | 
			
		||||
 | 
			
		||||
    require='__download/opt/cpma/cnq3.zip' \
 | 
			
		||||
        __unpack /opt/cpma/cnq3.zip \
 | 
			
		||||
            --move-existing-destination \
 | 
			
		||||
            --destination /opt/cpma/server
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
AUTHORS
 | 
			
		||||
-------
 | 
			
		||||
Ander Punnar <ander-at-kvlt-dot-ee>
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
COPYING
 | 
			
		||||
-------
 | 
			
		||||
Copyright \(C) 2020 Ander Punnar. 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.
 | 
			
		||||
							
								
								
									
										1
									
								
								cdist/conf/type/__download/parameter/default/cmd-get
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										1
									
								
								cdist/conf/type/__download/parameter/default/cmd-get
									
										
									
									
									
										Normal file
									
								
							| 
						 | 
				
			
			@ -0,0 +1 @@
 | 
			
		|||
wget -O- '%s'
 | 
			
		||||
							
								
								
									
										1
									
								
								cdist/conf/type/__download/parameter/default/cmd-sum
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										1
									
								
								cdist/conf/type/__download/parameter/default/cmd-sum
									
										
									
									
									
										Normal file
									
								
							| 
						 | 
				
			
			@ -0,0 +1 @@
 | 
			
		|||
md5sum '%s' | awk '{print $1}'
 | 
			
		||||
							
								
								
									
										2
									
								
								cdist/conf/type/__download/parameter/optional
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										2
									
								
								cdist/conf/type/__download/parameter/optional
									
										
									
									
									
										Normal file
									
								
							| 
						 | 
				
			
			@ -0,0 +1,2 @@
 | 
			
		|||
cmd-get
 | 
			
		||||
cmd-sum
 | 
			
		||||
							
								
								
									
										2
									
								
								cdist/conf/type/__download/parameter/required
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										2
									
								
								cdist/conf/type/__download/parameter/required
									
										
									
									
									
										Normal file
									
								
							| 
						 | 
				
			
			@ -0,0 +1,2 @@
 | 
			
		|||
url
 | 
			
		||||
sum
 | 
			
		||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue