mirror of
https://github.com/koreader/koreader.git
synced 2026-11-30 01:08:07 +00:00
tools/mkrelease: support an archive as input
If the first pattern is an archive, use its contents as input (with left-over patterns interpreted relative to said contents). Useful to convert an archive to another format (complete with support for filtering-out some files, adding a manifest, or ensuring consistent modification times).
This commit is contained in:
1 parent
60eeb416bf
commit
fddc52bd38
1 file changed
+39
-6
+39
-6
@@ -130,6 +130,16 @@ case "$1" in
|
||||
esac
|
||||
output="$("${READLINK}" -f "$1")"
|
||||
shift
|
||||
|
||||
case "$1" in
|
||||
*.7z | *.zip) input_extractor=7z ;;
|
||||
*.tar | *.tar.gz | *.targz | *.tgz | *.tar.xz | *.txz | *.tar.zst | *.tzst) input_extractor=tar ;;
|
||||
esac
|
||||
if [[ -n "${input_extractor}" ]]; then
|
||||
input_archive="$1"
|
||||
shift
|
||||
fi
|
||||
|
||||
patterns=("$@")
|
||||
if [[ -n "${manifest}" ]]; then
|
||||
patterns+=("-x!${manifest}")
|
||||
@@ -197,6 +207,8 @@ if [[ -n "${debug}" ]]; then
|
||||
echo "manifest transform : ${manifest_transform}"
|
||||
echo "epoch : ${epoch}"
|
||||
echo "options : ${options[*]@Q}"
|
||||
echo "input archive : ${input_archive@Q}"
|
||||
echo "input extractor : ${input_extractor}"
|
||||
echo "patterns : ${patterns[*]@Q}"
|
||||
echo "7z executable : ${sevenzip}"
|
||||
echo "7z compress command : ${sevenzip_compress_cmd[*]@Q}"
|
||||
@@ -207,11 +219,28 @@ if [[ -n "${debug}" ]]; then
|
||||
[[ -t 0 ]] && read -srn 1
|
||||
fi
|
||||
|
||||
if [[ -n "${input_archive}" ]]; then
|
||||
# Extract input archive.
|
||||
case "${input_extractor}" in
|
||||
7z) 7z x "${input_archive}" -bd -o"${tmpdir}/contents" >/dev/null ;;
|
||||
tar) tar xf "${input_archive}" --auto-compress -C "${tmpdir}/contents" ;;
|
||||
esac
|
||||
pushd "${tmpdir}/contents" >/dev/null
|
||||
# Try to keep manifest modification time.
|
||||
if [[ -z "${epoch}" ]] && [[ -n "${manifest}" ]] && [[ -f "${manifest}" ]]; then
|
||||
manifest_epoch="$(stat -c %Y "${manifest}")"
|
||||
fi
|
||||
fi
|
||||
|
||||
# Build manifest.
|
||||
"${sevenzip_manifest_cmd[@]}" "${patterns[@]}" |
|
||||
awk "${AWK_HELPERS}"'{ reverse_entry(); print_entry($1, $2, $3) }' |
|
||||
sort -o "${tmpdir}/manifest"
|
||||
|
||||
if [[ -n "${input_archive}" ]]; then
|
||||
popd >/dev/null
|
||||
fi
|
||||
|
||||
# Extract list of paths from manifest.
|
||||
rev <"${tmpdir}/manifest" | cut -f3- -d' ' | rev >"${tmpdir}/paths"
|
||||
# Quick sanity check: no path outside the current directory.
|
||||
@@ -277,12 +306,14 @@ if [[ -r "${output}" ]]; then
|
||||
rm -rf "${output}"
|
||||
fi
|
||||
|
||||
# Make a copy of everything so we can later patch timestamps and
|
||||
# fix permissions to ensure reproducibility.
|
||||
"${TAR}" --create --no-recursion \
|
||||
${dereference:+--dereference --hard-dereference} \
|
||||
--verbatim-files-from --files-from="${tmpdir}/paths" |
|
||||
"${TAR}" --extract --directory="${tmpdir}/contents"
|
||||
if [[ -z "${input_archive}" ]]; then
|
||||
# Make a copy of everything so we can later patch timestamps and
|
||||
# fix permissions to ensure reproducibility.
|
||||
"${TAR}" --create --no-recursion \
|
||||
${dereference:+--dereference --hard-dereference} \
|
||||
--verbatim-files-from --files-from="${tmpdir}/paths" |
|
||||
"${TAR}" --extract --directory="${tmpdir}/contents"
|
||||
fi
|
||||
|
||||
cd "${tmpdir}/contents"
|
||||
|
||||
@@ -292,6 +323,8 @@ chmod -R u=rwX,og=rX .
|
||||
# Fix timestamps.
|
||||
if [[ -n "${epoch}" ]]; then
|
||||
find . -depth -print0 | xargs -0 touch --date="${epoch}"
|
||||
elif [[ -n "${manifest_epoch}" ]]; then
|
||||
touch --date="@${manifest_epoch}" "${manifest}"
|
||||
fi
|
||||
|
||||
# And create the final output.
|
||||
|
||||
Reference in new issue
Block a user