archive : CamelCase for archive name.
This commit is contained in:
parent
6442278517
commit
7033aa65a0
|
@ -586,6 +586,14 @@ Command|Description
|
||||||
`pack <TARGET.ext> [FILES]`|Create desired file format from other files.
|
`pack <TARGET.ext> [FILES]`|Create desired file format from other files.
|
||||||
`unpack [FILES]`|Attempt to extract file content.
|
`unpack [FILES]`|Attempt to extract file content.
|
||||||
|
|
||||||
|
## Parse.
|
||||||
|
|
||||||
|
Command|Description
|
||||||
|
---|---
|
||||||
|
`parse_simplify <STRING>`|Return simplified string: only alnum, underscores and dashes.
|
||||||
|
`parse_camel <STRING>`|Return simplified CamelCase string.
|
||||||
|
`parse_alnum <STRING>`|Return string containing only alphanumeric characters.
|
||||||
|
|
||||||
## Permissions.
|
## Permissions.
|
||||||
|
|
||||||
Command|Description
|
Command|Description
|
||||||
|
|
|
@ -30,11 +30,13 @@ archive()
|
||||||
local status="[${count}/${total}] ${target}"
|
local status="[${count}/${total}] ${target}"
|
||||||
echo -e "${status}"
|
echo -e "${status}"
|
||||||
|
|
||||||
|
local name=$(parse_camel "${target}")
|
||||||
|
|
||||||
# create archive.
|
# create archive.
|
||||||
tar -c "${target}" | pv -s $(du -sb "${target}" | awk '{print $1}') | xz -9e > "${target%/*}".txz
|
tar -c "${target}" | pv -s $(du -sb "${target}" | awk '{print $1}') | xz -9e > "${name}".txz
|
||||||
|
|
||||||
# append hash to target name.
|
# append hash to target name.
|
||||||
mv "${target%/*}".txz "${target%/*}"_${date}-$(pv "${target%/*}".txz | sha1sum | cut -d\ -f1).txz
|
mv "${name}".txz "${name}"_${date}-$(pv "${name}".txz | sha1sum | cut -d\ -f1).txz
|
||||||
|
|
||||||
# Show error.
|
# Show error.
|
||||||
if [[ ${?} != 0 ]]; then
|
if [[ ${?} != 0 ]]; then
|
||||||
|
@ -76,11 +78,13 @@ archive_fast()
|
||||||
local status="[${count}/${total}] ${target}"
|
local status="[${count}/${total}] ${target}"
|
||||||
echo -e "${status}"
|
echo -e "${status}"
|
||||||
|
|
||||||
|
local name=$(parse_camel "${target}")
|
||||||
|
|
||||||
# create archive.
|
# create archive.
|
||||||
tar -c "${target}" | pv -s $(du -sb "${target}" | awk '{print $1}') | gzip -1 > "${target%/*}".tgz
|
tar -c "${target}" | pv -s $(du -sb "${target}" | awk '{print $1}') | gzip -1 > "${name}".tgz
|
||||||
|
|
||||||
# append hash to target name.
|
# append hash to target name.
|
||||||
mv "${target%/*}".tgz "${target%/*}"_${date}-$(pv "${target%/*}".tgz | sha1sum | cut -d\ -f1).tgz
|
mv "${name}".tgz "${name}"_${date}-$(pv "${name}".tgz | sha1sum | cut -d\ -f1).tgz
|
||||||
|
|
||||||
# Show error.
|
# Show error.
|
||||||
if [[ $? != 0 ]]; then
|
if [[ $? != 0 ]]; then
|
||||||
|
|
|
@ -11,6 +11,20 @@ parse_simplify()
|
||||||
-e "s/^_//" -e "s/_$//"
|
-e "s/^_//" -e "s/_$//"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
parse_camel()
|
||||||
|
{
|
||||||
|
local IFS=${IFS}_-
|
||||||
|
local parts=($(parse_simplify ${1}))
|
||||||
|
local result
|
||||||
|
|
||||||
|
for part in "${parts[@]}"; do
|
||||||
|
local word="${part^}"
|
||||||
|
result="${result}${word}"
|
||||||
|
done
|
||||||
|
|
||||||
|
echo "${result}"
|
||||||
|
}
|
||||||
|
|
||||||
# parse data keeping only alphanumeric characters.
|
# parse data keeping only alphanumeric characters.
|
||||||
# usage: parse_alnum <STRING>
|
# usage: parse_alnum <STRING>
|
||||||
parse_alnum()
|
parse_alnum()
|
||||||
|
|
Reference in a new issue