Linux Compression Humanized
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

152 lines
2.7 KiB

#!/bin/bash
VERSION=0.1r7
if [ "$1" = "version" ] || [ "$1" = "--version" ] || [ "$1" = "-v" ]
then
echo "Linux Compression Humanized $VERSION"
exit 0
else
echo ""
echo "lch $VERSION"
echo "---------"
echo ""
fi
function decompressor()
{
case $1 in
*.tar)
tar -xvf $1
;;
*.tar.gz | *.tgz)
tar -xzvf $1
;;
*.tar.bz2 | *.tbz | *.tbz2 | *.tb2)
tar xjf $1
;;
*.tar.xz | *.txz)
tar -xf $1
;;
*.bz2)
bzip2 -d $1
;;
*.gz)
gzip -d $1
;;
*.zip)
unzip $1
;;
*.7z)
7za e $1
;;
*)
echo "Extension not found."
echo "For more information --help"
echo ""
;;
esac
echo ""
echo "Done"
exit 0
}
function compressor()
{
case $1 in
*.tar)
tar -cvf $1 $2
;;
*.tar.gz | *.tgz)
tar -czvf $1 $2
;;
*.tar.bz2 | *.tbz | *.tbz2 | *.tb2)
tar -c $2 | bzip2 > $1
;;
*.tar.xz | *.txz)
tar -cJf $1 $2
;;
*.bz2)
bzip2 -c $2 > $1
;;
*.gz)
gzip -c $2 > $1
;;
*.zip)
zip -r $1 $2
;;
*.7z)
7za a $1 $2
;;
*)
echo "Extent not found."
echo " For more information --help"
echo ""
;;
esac
echo ""
echo "Done"
exit 0
}
function help()
{
echo "Help:"
echo "-----"
echo ""
echo "lch [-h][-v] FILE [FILE]"
echo ""
echo "Examples:"
echo "$ lch -h -This help"
echo "$ lch -v -print version"
echo "$ lch file.zip /home/file -Compress"
echo "$ lch file.zip -Decompress"
echo ""
echo "Supported extensions:"
echo "- tar"
echo "- tar.gz"
echo "- tar.bz2"
echo "- tar.xz"
echo "- bz2"
echo "- tgz"
echo "- gz"
echo "- zip"
echo "- 7z"
echo ""
}
if [ "$1" = "--help" ] || [ "$1" = "-h" ]
then
help
exit 0
fi
if [ "$1" = "--version" ] || [ "$1" = "-v" ]
then
echo ""
echo "lch $VERSION"
echo ""
exit 0
fi
if [ -z "$1" ] || [ -n "$3" ]
then
echo "Wrong arguments"
echo "For more information --help"
echo ""
exit 0
else
if [ -n "$2" ]
then
echo "Compressor:"
echo "-----------"
echo ""
compressor $1 $2
else
echo "Decompressor:"
echo "--------------"
echo ""
decompressor $1
fi
fi