Merge branch '__unpack' into 'master'
new type: __unpack See merge request ungleich-public/cdist!893
This commit is contained in:
commit
8a8a48313c
10 changed files with 306 additions and 0 deletions
37
cdist/conf/type/__unpack/explorer/state
Executable file
37
cdist/conf/type/__unpack/explorer/state
Executable file
|
@ -0,0 +1,37 @@
|
|||
#!/bin/sh -e
|
||||
|
||||
src="/$__object_id"
|
||||
|
||||
if [ -f "$__object/parameter/sum-file" ]
|
||||
then
|
||||
src_sum_was_file="$( cat "$__object/parameter/sum-file" )"
|
||||
else
|
||||
src_sum_was_file="$src.cdist__unpack_sum"
|
||||
fi
|
||||
|
||||
if [ ! -f "$src" ]
|
||||
then
|
||||
if [ -n "$__cdist_dry_run" ]
|
||||
then
|
||||
echo 'mismatch'
|
||||
else
|
||||
echo 'missing'
|
||||
fi
|
||||
else
|
||||
if [ ! -f "$src_sum_was_file" ]
|
||||
then
|
||||
echo 'mismatch'
|
||||
exit 0
|
||||
fi
|
||||
|
||||
src_sum_was="$( cat "$src_sum_was_file" )"
|
||||
|
||||
src_sum_is="$( cksum "$src" | awk '{ print $1$2 }' )"
|
||||
|
||||
if [ "$src_sum_was" = "$src_sum_is" ]
|
||||
then
|
||||
echo 'match'
|
||||
else
|
||||
echo 'mismatch'
|
||||
fi
|
||||
fi
|
75
cdist/conf/type/__unpack/gencode-remote
Executable file
75
cdist/conf/type/__unpack/gencode-remote
Executable file
|
@ -0,0 +1,75 @@
|
|||
#!/bin/sh -e
|
||||
|
||||
if grep -Eq '^(missing|match)$' "$__object/explorer/state"
|
||||
then
|
||||
exit 0
|
||||
fi
|
||||
|
||||
os="$( cat "$__global/explorer/os" )"
|
||||
|
||||
src="/$__object_id"
|
||||
|
||||
dst="$( sed 's/\/$//' "$__object/parameter/destination" )"
|
||||
|
||||
cmd=''
|
||||
|
||||
case "$src" in
|
||||
*.tar|*.tgz|*.tar.*)
|
||||
cmd="mkdir -p '$dst' && tar --directory='$dst' --extract --file='$src'"
|
||||
|
||||
if [ -f "$__object/parameter/tar-strip" ]
|
||||
then
|
||||
tar_strip="$( cat "$__object/parameter/tar-strip" )"
|
||||
|
||||
cmd="$cmd --strip-components=$tar_strip"
|
||||
fi
|
||||
;;
|
||||
*.7z)
|
||||
case "$os" in
|
||||
centos|fedora|redhat)
|
||||
cmd='7za'
|
||||
;;
|
||||
*)
|
||||
cmd='7zr'
|
||||
;;
|
||||
esac
|
||||
|
||||
cmd="$cmd e -aoa -o'$dst' '$src'"
|
||||
;;
|
||||
*.bz2)
|
||||
cmd="bunzip2 --stdout '$src' > '$dst'"
|
||||
;;
|
||||
*.gz)
|
||||
cmd="gunzip --stdout '$src' > '$dst'"
|
||||
;;
|
||||
*.lzma|*.xz)
|
||||
cmd="xz --uncompress --stdout '$src' > '$dst'"
|
||||
;;
|
||||
*.rar)
|
||||
cmd="unrar x -o+ '$src' '$dst/'"
|
||||
;;
|
||||
*.zip)
|
||||
cmd="unzip -o '$src' -d '$dst'"
|
||||
;;
|
||||
esac
|
||||
|
||||
if [ -f "$__object/parameter/backup-destination" ]
|
||||
then
|
||||
echo "if [ -e '$dst' ]; then mv '$dst' '$dst.cdist__unpack_backup_$( date +%s )'; fi"
|
||||
fi
|
||||
|
||||
echo "$cmd"
|
||||
|
||||
if [ -f "$__object/parameter/sum-file" ]
|
||||
then
|
||||
sum_file="$( cat "$__object/parameter/sum-file" )"
|
||||
else
|
||||
sum_file="$src.cdist__unpack_sum"
|
||||
fi
|
||||
|
||||
echo "cksum '$src' | awk '{ print \$1\$2 }' > '$sum_file'"
|
||||
|
||||
if [ ! -f "$__object/parameter/preserve-archive" ]
|
||||
then
|
||||
echo "rm -f '$src'"
|
||||
fi
|
79
cdist/conf/type/__unpack/man.rst
Normal file
79
cdist/conf/type/__unpack/man.rst
Normal file
|
@ -0,0 +1,79 @@
|
|||
cdist-type__unpack(7)
|
||||
=====================
|
||||
|
||||
NAME
|
||||
----
|
||||
cdist-type__unpack - Unpack archives
|
||||
|
||||
|
||||
DESCRIPTION
|
||||
-----------
|
||||
Unpack ``.tar``, ``.tgz``, ``.tar.*``, ``.7z``, ``.bz2``, ``.gz``,
|
||||
``.lzma``, ``.xz``, ``.rar`` and ``.zip`` archives. Archive type is
|
||||
detected by extension.
|
||||
|
||||
To achieve idempotency, checksum file will be created in target. See
|
||||
``--sum-file`` parameter for details.
|
||||
|
||||
|
||||
REQUIRED PARAMETERS
|
||||
-------------------
|
||||
destination
|
||||
Depending on archive format file or directory to where archive
|
||||
contents will be written.
|
||||
|
||||
|
||||
OPTIONAL PARAMETERS
|
||||
-------------------
|
||||
sum-file
|
||||
Override archive's checksum file in target. By default
|
||||
``XXX.cdist__unpack_sum`` will be used, where ``XXX`` is source
|
||||
archive path. This file must be kept in target's persistent storage.
|
||||
|
||||
tar-strip
|
||||
Tarball specific. See ``man tar`` for ``--strip-components``.
|
||||
|
||||
|
||||
OPTIONAL BOOLEAN PARAMETERS
|
||||
---------------------------
|
||||
backup-destination
|
||||
By default destination file will be overwritten. In case destination
|
||||
is directory, files from archive will be added to or overwritten in
|
||||
directory. This parameter moves existing destination to
|
||||
``XXX.cdist__unpack_backup_YYY``, where ``XXX`` is destination and
|
||||
``YYY`` current UNIX timestamp.
|
||||
|
||||
preserve-archive
|
||||
Don't delete archive after unpacking.
|
||||
|
||||
|
||||
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 md5:46da3021ca9eace277115ec9106c5b46
|
||||
|
||||
require='__download/opt/cpma/cnq3.zip' \
|
||||
__unpack /opt/cpma/cnq3.zip \
|
||||
--backup-destination \
|
||||
--preserve-archive \
|
||||
--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.
|
41
cdist/conf/type/__unpack/manifest
Executable file
41
cdist/conf/type/__unpack/manifest
Executable file
|
@ -0,0 +1,41 @@
|
|||
#!/bin/sh -e
|
||||
|
||||
os="$( cat "$__global/explorer/os" )"
|
||||
|
||||
src="/$__object_id"
|
||||
|
||||
case "$src" in
|
||||
*.7z)
|
||||
__package p7zip
|
||||
;;
|
||||
*.bz2)
|
||||
case "$os" in
|
||||
freebsd)
|
||||
# bzip2 is part of freebsd base system
|
||||
;;
|
||||
*)
|
||||
__package bzip2
|
||||
;;
|
||||
esac
|
||||
;;
|
||||
*.lzma|*.xz|*.txz)
|
||||
case "$os" in
|
||||
debian|ubuntu|devuan)
|
||||
__package xz-utils
|
||||
;;
|
||||
alpine|centos)
|
||||
__package xz
|
||||
;;
|
||||
esac
|
||||
;;
|
||||
*.rar)
|
||||
case "$os" in
|
||||
debian|ubuntu|devuan|alpine|freebsd)
|
||||
__package unrar
|
||||
;;
|
||||
esac
|
||||
;;
|
||||
*.zip)
|
||||
__package unzip
|
||||
;;
|
||||
esac
|
2
cdist/conf/type/__unpack/parameter/boolean
Normal file
2
cdist/conf/type/__unpack/parameter/boolean
Normal file
|
@ -0,0 +1,2 @@
|
|||
backup-destination
|
||||
preserve-archive
|
2
cdist/conf/type/__unpack/parameter/optional
Normal file
2
cdist/conf/type/__unpack/parameter/optional
Normal file
|
@ -0,0 +1,2 @@
|
|||
sum-file
|
||||
tar-strip
|
1
cdist/conf/type/__unpack/parameter/required
Normal file
1
cdist/conf/type/__unpack/parameter/required
Normal file
|
@ -0,0 +1 @@
|
|||
destination
|
3
cdist/conf/type/__unpack/test/README
Normal file
3
cdist/conf/type/__unpack/test/README
Normal file
|
@ -0,0 +1,3 @@
|
|||
./make-test-files.sh
|
||||
./make-init-manifest.sh | cdist config -i - localhost
|
||||
sudo find /tmp/cdist__unpack_test/ -type f -exec cat {} \; | sort
|
22
cdist/conf/type/__unpack/test/make-init-manifest.sh
Executable file
22
cdist/conf/type/__unpack/test/make-init-manifest.sh
Executable file
|
@ -0,0 +1,22 @@
|
|||
#!/bin/sh -e
|
||||
|
||||
p="$( pwd )"
|
||||
d=/tmp/cdist__unpack_test
|
||||
|
||||
echo 'export CDIST_ORDER_DEPENDENCY=1'
|
||||
|
||||
echo "__directory $d"
|
||||
|
||||
find "$p" -name 'test.*' -and -not -name '*.cdist__unpack_sum' \
|
||||
| sort \
|
||||
| while read -r l
|
||||
do
|
||||
n="$( basename "$l" )"
|
||||
|
||||
printf '__unpack %s --destination %s/%s\n' \
|
||||
"$l" \
|
||||
"$d" \
|
||||
"$n"
|
||||
done
|
||||
|
||||
echo "__clean_path $p --pattern '.+/test\..+'"
|
44
cdist/conf/type/__unpack/test/make-test-files.sh
Executable file
44
cdist/conf/type/__unpack/test/make-test-files.sh
Executable file
|
@ -0,0 +1,44 @@
|
|||
#!/bin/sh -ex
|
||||
|
||||
echo test.7z > test
|
||||
7z a test.7z test > /dev/null
|
||||
|
||||
echo test.bz2 > test
|
||||
bzip2 test
|
||||
|
||||
echo test.gz > test
|
||||
gzip test
|
||||
|
||||
echo test.lzma > test
|
||||
lzma test
|
||||
|
||||
echo test.rar > test
|
||||
rar a test.rar test > /dev/null
|
||||
|
||||
echo test.tar.bz2 > test
|
||||
tar cf test.tar test
|
||||
bzip2 test.tar
|
||||
|
||||
echo test.tar.xz > test
|
||||
tar cf test.tar test
|
||||
xz test.tar
|
||||
|
||||
echo test.tgz > test
|
||||
tar cf test.tar test
|
||||
gzip test.tar
|
||||
mv test.tar.gz test.tgz
|
||||
|
||||
echo test.tar.gz > test
|
||||
tar cf test.tar test
|
||||
gzip test.tar
|
||||
|
||||
echo test.tar > test
|
||||
tar cf test.tar test
|
||||
|
||||
echo test.xz > test
|
||||
xz test
|
||||
|
||||
echo test.zip > test
|
||||
zip test.zip test > /dev/null
|
||||
|
||||
rm test
|
Loading…
Reference in a new issue