convert : add gz-xz xz-gz conversion.
This commit is contained in:
parent
069ffd08db
commit
6a28236e75
24
.README.md
24
.README.md
|
@ -401,6 +401,9 @@ Please note that colors depend on Terminal Emulator and may vary based on its se
|
||||||
|yellow|`\033[0;33m`|
|
|yellow|`\033[0;33m`|
|
||||||
|yellow (bold)|`\033[1;33m`|
|
|yellow (bold)|`\033[1;33m`|
|
||||||
|
|
||||||
|
## Convert.
|
||||||
|
`convert <FROM.gz> <TO.xz>`|Convert between different formats.
|
||||||
|
|
||||||
## Copy/paste.
|
## Copy/paste.
|
||||||
|
|
||||||
Command|Description
|
Command|Description
|
||||||
|
@ -458,13 +461,6 @@ Command|Description
|
||||||
`dcpu [SERVICE]`|Update and recreate a compose service.
|
`dcpu [SERVICE]`|Update and recreate a compose service.
|
||||||
`dcul [SERVICE]`|Start a compose service and show its logs.
|
`dcul [SERVICE]`|Start a compose service and show its logs.
|
||||||
|
|
||||||
## Pack.
|
|
||||||
|
|
||||||
Command|Description
|
|
||||||
---|---
|
|
||||||
`pack <TARGET.ext> <FILES>`|Create desired file format from other files.
|
|
||||||
`unpack [FILES]`|Attempt to extract file content.
|
|
||||||
|
|
||||||
## Environment variables.
|
## Environment variables.
|
||||||
|
|
||||||
Variable|Description
|
Variable|Description
|
||||||
|
@ -569,6 +565,13 @@ Command|Description
|
||||||
---|---
|
---|---
|
||||||
`own [USER] [FILE]`|Change ownership & permissions to specified user. Ownership changes only when root.
|
`own [USER] [FILE]`|Change ownership & permissions to specified user. Ownership changes only when root.
|
||||||
|
|
||||||
|
## Pack.
|
||||||
|
|
||||||
|
Command|Description
|
||||||
|
---|---
|
||||||
|
`pack <TARGET.ext> <FILES>`|Create desired file format from other files.
|
||||||
|
`unpack [FILES]`|Attempt to extract file content.
|
||||||
|
|
||||||
## Permissions.
|
## Permissions.
|
||||||
|
|
||||||
Command|Description
|
Command|Description
|
||||||
|
@ -583,11 +586,18 @@ Command|Description
|
||||||
`ps <PROGRAM>`|Show process info for matching [PROGRAM] name.
|
`ps <PROGRAM>`|Show process info for matching [PROGRAM] name.
|
||||||
|
|
||||||
## Recursive.
|
## Recursive.
|
||||||
|
|
||||||
Command|Description
|
Command|Description
|
||||||
---|---
|
---|---
|
||||||
`recursive <COMMAND>`|Cd into every directory recursively and run specified command in each dir.
|
`recursive <COMMAND>`|Cd into every directory recursively and run specified command in each dir.
|
||||||
`recursive1 <COMMAND>`|Cd into every directory in current directory and run specified command in each dir.
|
`recursive1 <COMMAND>`|Cd into every directory in current directory and run specified command in each dir.
|
||||||
|
|
||||||
|
## Rust.
|
||||||
|
|
||||||
|
Command|Description
|
||||||
|
---|---
|
||||||
|
`rust_book`|Open Rust book in a browser.
|
||||||
|
|
||||||
## Shopt.
|
## Shopt.
|
||||||
|
|
||||||
Shopt|Description
|
Shopt|Description
|
||||||
|
|
|
@ -117,12 +117,10 @@ archive_check()
|
||||||
done
|
done
|
||||||
|
|
||||||
# report result.
|
# report result.
|
||||||
if [[ ${count} -gt 1 ]] || [[ "${*}" = "" ]]; then
|
if [[ ${failed} -gt 0 ]]; then
|
||||||
if [[ ${failed} -gt 0 ]]; then
|
echo -e "${color_bred}Items failed to validate: ${failed}.${color_default}"
|
||||||
echo -e "${color_bred}Items failed to validate: ${failed}.${color_default}"
|
else
|
||||||
else
|
echo -e "${color_green}All successful.${color_default}"
|
||||||
echo -e "${color_green}All successful.${color_default}"
|
|
||||||
fi
|
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
51
.config/bash/module/convert.sh
Normal file
51
.config/bash/module/convert.sh
Normal file
|
@ -0,0 +1,51 @@
|
||||||
|
# Convert between different formats.
|
||||||
|
# Usage: convert <FROM.gz> <TO.xz>
|
||||||
|
convert() {
|
||||||
|
local input="${1}"
|
||||||
|
local output="${2}"
|
||||||
|
local from="${input##*.}"
|
||||||
|
local to="${output##*.}"
|
||||||
|
|
||||||
|
# Report no output.
|
||||||
|
if [[ "${to}" = "" ]]; then
|
||||||
|
echo -e "${color_bred}no output file/format.${color_default}"
|
||||||
|
return 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Report no input.
|
||||||
|
if [[ "${from}" = "" ]]; then
|
||||||
|
echo -e "${color_bred}no input file/format.${color_default}"
|
||||||
|
return 2
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Process.
|
||||||
|
case "${from}-${to}" in
|
||||||
|
"gz-xz"|"tgz-txz")
|
||||||
|
_convert_gz-xz "${input}" "${output}"
|
||||||
|
;;
|
||||||
|
"xz-gz"|"txz-tgz")
|
||||||
|
_convert_xz-gz "${input}" "${output}"
|
||||||
|
;;
|
||||||
|
*)
|
||||||
|
echo -e "${color_yellow}Conversion ${from}-${to} not supported.${color_default}"
|
||||||
|
return 3
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
|
||||||
|
if [[ $? = 0 ]]; then
|
||||||
|
echo -e "${color_green}Done.${color_default}"
|
||||||
|
else
|
||||||
|
echo -e "${color_bred}There were errors.${color_default}"
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
_convert_gz-xz() {
|
||||||
|
pv "${1}" | gzip -d | xz -9e > "${2}"
|
||||||
|
}
|
||||||
|
|
||||||
|
_convert_xz-gz() {
|
||||||
|
pv "${1}" | xz -d | gzip -1 > "${2}"
|
||||||
|
}
|
||||||
|
|
||||||
|
# Export.
|
||||||
|
export -f convert _convert_gz-xz _convert_xz-gz
|
Reference in a new issue