archive : remove convert.
This commit is contained in:
parent
5a2ccd5f39
commit
8a2921f0ec
|
@ -193,72 +193,6 @@ function archive_prune() {
|
|||
fi
|
||||
}
|
||||
|
||||
# Extract previously created archive with checksum validation.
|
||||
# Usage: unarchive [FILES]
|
||||
function unarchive() {
|
||||
local IFS=$'\n'
|
||||
local targets=("${@}")
|
||||
local count=0
|
||||
local total=${#}
|
||||
local failed=0
|
||||
|
||||
# set dafult value to target all supported archives.
|
||||
if [[ "${targets}" = "" ]]; then
|
||||
targets=($(ls | grep -E ${_archive_pattern}))
|
||||
total=${#targets[@]}
|
||||
fi
|
||||
|
||||
# iterate each target.
|
||||
for target in "${targets[@]}"; do
|
||||
# increment counter.
|
||||
((count++))
|
||||
|
||||
# status info.
|
||||
local status="[${count}/${total}] ${target}"
|
||||
echo -e "${color_bwhite}${status}${color_default}"
|
||||
|
||||
# extract hash from name.
|
||||
local data=($(_archive_parse "${target}"))
|
||||
local saved="${data[2]}"
|
||||
|
||||
# calculate actual hash.
|
||||
local actual=$(pv "${target}" | sha1sum | cut -d\ -f1)
|
||||
|
||||
# extract if hash matched or show error if not.
|
||||
if [[ "${saved}" = "${actual}" ]]; then
|
||||
# figure out the compression tool.
|
||||
local compressor
|
||||
case "${target##*.}" in
|
||||
"txz")
|
||||
compressor="xz -d"
|
||||
;;
|
||||
"tgz")
|
||||
compressor="gzip -d"
|
||||
;;
|
||||
esac
|
||||
|
||||
# extract.
|
||||
unset IFS
|
||||
pv "${target}" | ${compressor} | tar -xf -
|
||||
|
||||
if [[ ${?} != 0 ]]; then
|
||||
echo -e "${color_bred}${status}: Failed.${color_default}"
|
||||
((failed++))
|
||||
fi
|
||||
else
|
||||
# report validation error & continue.
|
||||
echo -e "${color_bred}${status}: Validation failed.${color_default}"
|
||||
((failed++))
|
||||
continue
|
||||
fi
|
||||
done
|
||||
|
||||
if [[ ${failed} != 0 ]]; then
|
||||
echo -e "${color_bred}Failed: ${failed}.${color_default}"
|
||||
false
|
||||
fi
|
||||
}
|
||||
|
||||
# Rename archives.
|
||||
# If no name specified, it simplifies archive's name.
|
||||
# If no archives specified, apply to all archives.
|
||||
|
@ -325,49 +259,6 @@ function archive_name() {
|
|||
fi
|
||||
}
|
||||
|
||||
# Convert old archives to a new format. *TODO: remove me after some time when there won't be any old archives.*
|
||||
function archive_convert() {
|
||||
local IFS=$'\n'
|
||||
local old_format="_[[:alnum:]]{40}.tar.[xg]z"
|
||||
local targets=($(ls | grep -E ${old_format}))
|
||||
|
||||
# add timestamp.
|
||||
for target in "${targets[@]}"; do
|
||||
local stamp=$(stat --format '%w' -- "${target}" | sed -e 's/\..*//' -e 's/:..$//' -e 's/-//g' -e 's/://' -e 's/\ //')
|
||||
local name="${target%_*}"
|
||||
local old_data="${target##*_}"
|
||||
local new_name="${name}_${stamp}-${old_data}"
|
||||
|
||||
echo "${target} -> ${new_name}"
|
||||
|
||||
mv "${target}" "${new_name}"
|
||||
done
|
||||
|
||||
# convert tar.xz and tar.gz to .tgz and .txz.
|
||||
old_format="_[0-9]{12}-[[:alnum:]]{40}.tar.[xg]z"
|
||||
targets=($(ls | grep -E ${old_format}))
|
||||
|
||||
for target in "${targets[@]}"; do
|
||||
local compression="${target##*.}"
|
||||
local new_compression
|
||||
|
||||
case "${compression}" in
|
||||
"gz")
|
||||
new_compression="tgz"
|
||||
;;
|
||||
"xz")
|
||||
new_compression="txz"
|
||||
;;
|
||||
esac
|
||||
|
||||
local new_name="${target%.tar.*}".${new_compression}
|
||||
|
||||
echo "${target} -> ${new_name}"
|
||||
|
||||
mv -- "${target}" "${new_name}"
|
||||
done
|
||||
}
|
||||
|
||||
# Delete specified or all archive files.
|
||||
# Usage: archive_rm [FILES]
|
||||
function archive_rm() {
|
||||
|
@ -445,6 +336,72 @@ function _archive_name() {
|
|||
fi
|
||||
}
|
||||
|
||||
# Extract previously created archive with checksum validation.
|
||||
# Usage: unarchive [FILES]
|
||||
function unarchive() {
|
||||
local IFS=$'\n'
|
||||
local targets=("${@}")
|
||||
local count=0
|
||||
local total=${#}
|
||||
local failed=0
|
||||
|
||||
# set dafult value to target all supported archives.
|
||||
if [[ "${targets}" = "" ]]; then
|
||||
targets=($(ls | grep -E ${_archive_pattern}))
|
||||
total=${#targets[@]}
|
||||
fi
|
||||
|
||||
# iterate each target.
|
||||
for target in "${targets[@]}"; do
|
||||
# increment counter.
|
||||
((count++))
|
||||
|
||||
# status info.
|
||||
local status="[${count}/${total}] ${target}"
|
||||
echo -e "${color_bwhite}${status}${color_default}"
|
||||
|
||||
# extract hash from name.
|
||||
local data=($(_archive_parse "${target}"))
|
||||
local saved="${data[2]}"
|
||||
|
||||
# calculate actual hash.
|
||||
local actual=$(pv "${target}" | sha1sum | cut -d\ -f1)
|
||||
|
||||
# extract if hash matched or show error if not.
|
||||
if [[ "${saved}" = "${actual}" ]]; then
|
||||
# figure out the compression tool.
|
||||
local compressor
|
||||
case "${target##*.}" in
|
||||
"txz")
|
||||
compressor="xz -d"
|
||||
;;
|
||||
"tgz")
|
||||
compressor="gzip -d"
|
||||
;;
|
||||
esac
|
||||
|
||||
# extract.
|
||||
unset IFS
|
||||
pv "${target}" | ${compressor} | tar -xf -
|
||||
|
||||
if [[ ${?} != 0 ]]; then
|
||||
echo -e "${color_bred}${status}: Failed.${color_default}"
|
||||
((failed++))
|
||||
fi
|
||||
else
|
||||
# report validation error & continue.
|
||||
echo -e "${color_bred}${status}: Validation failed.${color_default}"
|
||||
((failed++))
|
||||
continue
|
||||
fi
|
||||
done
|
||||
|
||||
if [[ ${failed} != 0 ]]; then
|
||||
echo -e "${color_bred}Failed: ${failed}.${color_default}"
|
||||
false
|
||||
fi
|
||||
}
|
||||
|
||||
# Autocomplete with archives in current dir.
|
||||
function _archive_grep() {
|
||||
_autocomplete_grep ${_archive_pattern}
|
||||
|
|
Reference in a new issue