mirror of
https://gitlab.com/JKANetwork/jka-toolkit.git
synced 2026-02-27 07:23:48 +01:00
update jkazip
This commit is contained in:
@@ -2,18 +2,100 @@
|
||||
#JKA - ZIP
|
||||
#A script for de/compress files and folders in many formats
|
||||
#Author: JKA Network - contacto@jkanetwork.com
|
||||
|
||||
version="0.1"
|
||||
#Function decompress(); decompress the file whith the format especified
|
||||
function decompress() {
|
||||
if [ $files -eq 0 ];then
|
||||
format=$(ls $2 | cut -f2 -d".")
|
||||
format2=$(ls $2 | cut -f3 -d".")
|
||||
else
|
||||
format=$(echo $1 | cut -f1 -d".")
|
||||
format2=$(echo $1 | cut -f2 -d".")
|
||||
fi
|
||||
if [ $format = "tar" ];then
|
||||
if [ -z $format2 ];then
|
||||
tar xvf $2
|
||||
if [ $? -eq 0 ];then
|
||||
echo "$2 has been decompressed"
|
||||
fi
|
||||
elif [ $format2 = "gz" ];then
|
||||
tar xvzf $2
|
||||
if [ $? -eq 0 ];then
|
||||
echo "$2 has been decompressed"
|
||||
fi
|
||||
elif [ $format2 = "bz2" ];then
|
||||
tar xvjf $2
|
||||
if [ $? -eq 0 ];then
|
||||
echo "$2 has been decompressed"
|
||||
fi
|
||||
elif [ $format2 = "xz" ];then
|
||||
tar xvJf $2
|
||||
if [ $? -eq 0 ];then
|
||||
echo "$2 has been decompressed"
|
||||
fi
|
||||
fi
|
||||
elif [ $format = "tbz2" ];then
|
||||
tar xvjf $2
|
||||
if [ $? -eq 0 ];then
|
||||
echo "$2 has been decompressed"
|
||||
fi
|
||||
elif [ $format = "tgz" ];then
|
||||
tar xvjf $2
|
||||
if [ $? -eq 0 ];then
|
||||
echo "$2 has been decompressed"
|
||||
fi
|
||||
elif [ $format = "txz" ];then
|
||||
tar xvJf $2
|
||||
if [ $? -eq 0 ];then
|
||||
echo "$2 has been decompressed"
|
||||
fi
|
||||
elif [ $format = "7z" -o $format = "7zip" ];then
|
||||
7z e $2
|
||||
if [ $? -eq 0 ];then
|
||||
echo "$2 has been decompressed"
|
||||
fi
|
||||
elif [ $format = "zip" ];then
|
||||
unzip $2
|
||||
if [ $? -eq 0 ];then
|
||||
echo "$2 has been decompressed"
|
||||
fi
|
||||
elif [ $format = "gz" -o $format = "gzip" ];then
|
||||
gzip -dk $2
|
||||
if [ $? -eq 0 ];then
|
||||
echo "$2 has been decompressed"
|
||||
fi
|
||||
elif [ $format = "bz2" -o $format = "bzip" ];then
|
||||
bzip2 -dk $2
|
||||
if [ $? -eq 0 ];then
|
||||
echo "$2 has been decompressed"
|
||||
fi
|
||||
elif [ $format = "rar" ];then
|
||||
rar -x $2
|
||||
if [ $? -eq 0 ];then
|
||||
echo "$2 has been decompressed"
|
||||
fi
|
||||
else
|
||||
echo "Format $format unknown"
|
||||
fi
|
||||
}
|
||||
version="0.2"
|
||||
if [ -z $1 ];then
|
||||
echo "No option specified, use jkazip -h"
|
||||
elif [ $1 = "-h" ];then
|
||||
echo " synopsis: jkazip [option] [format (when compress)] [file or directory]"
|
||||
echo " synopsis: jkazip <options> <file or directory>"
|
||||
echo ""
|
||||
echo " -d, decompress file"
|
||||
echo " -c, compress file"
|
||||
echo " -f <format>, specified format whe decompress, necessary only when the name have more than one point before the file extension"
|
||||
echo " -c <format>, compress file"
|
||||
echo " -h, show help box and exit"
|
||||
echo " -v, show version"
|
||||
echo ""
|
||||
echo " The order must do \"jkazip -d [-f format] <file or directory>\" or \"jkazip -c <format> <file or directory\""
|
||||
echo ""
|
||||
echo " Examples"
|
||||
echo " jkazip -d -f \"tar.gz\" file.txt.tar.gz"
|
||||
echo " jkazip -d file.7z"
|
||||
echo " jkazip -c \"tar.xz\" directory"
|
||||
echo ""
|
||||
echo " Supported formats: tar,gzip,bzip2,xzip,7z,zip and rar"
|
||||
echo " Only one file or directory (some formats don't support directories), for more options use the each program individualy"
|
||||
echo ""
|
||||
@@ -23,56 +105,30 @@ elif [ $1 = "-d" ];then
|
||||
if [ -z $2 ];then
|
||||
echo "No file or directory specified"
|
||||
exit
|
||||
elif [ $2 = "-f" ];then
|
||||
files=1
|
||||
elif [ -d $2 ];then
|
||||
echo "The directory $2 will be decompressed"
|
||||
files=0
|
||||
echo "Directory $2 will be decompressed"
|
||||
elif [ -f $2 ];then
|
||||
echo "The file $2 will be decompressed"
|
||||
files=0
|
||||
echo "File $ will be decompressed"
|
||||
else
|
||||
echo "$2 no such file or directory"
|
||||
exit
|
||||
fi
|
||||
format=$(ls $2 | cut -f2 -d".")
|
||||
if [ $format = "tar" ];then
|
||||
format2=$(ls $2 | cut -f3 -d".")
|
||||
if [ -z $format2 ];then
|
||||
tar xvf $2
|
||||
echo "$2 has been decompressed"
|
||||
elif [ $format2 = "gz" ];then
|
||||
tar xvzf $2
|
||||
echo "$2 has been decompressed"
|
||||
elif [ $format2 = "bz2" ];then
|
||||
tar xvjf $2
|
||||
echo "$2 has been decompressed"
|
||||
elif [ $format2 = "xz" ];then
|
||||
tar xvJf $2
|
||||
echo "$2 has been decompressed"
|
||||
fi
|
||||
elif [ $format = "tbz2" ];then
|
||||
tar xvjf $2
|
||||
echo "$2 has been decompressed"
|
||||
elif [ $format = "tgz" ];then
|
||||
tar xvjf $2
|
||||
echo "$2 has been decompressed"
|
||||
elif [ $format = "txz" ];then
|
||||
tar xvJf $2
|
||||
echo "$2 has been decompressed"
|
||||
elif [ $format = "7z" ];then
|
||||
7z e $2
|
||||
echo "$2 has been decompressed"
|
||||
elif [ $format = "zip" ];then
|
||||
unzip $2
|
||||
echo "$2 has been decompressed"
|
||||
elif [ $format = "gz" ];then
|
||||
gzip -dk $2
|
||||
echo "$2 has been decompressed"
|
||||
elif [ $format = "bz2" ];then
|
||||
bzip2 -d $2
|
||||
echo "$2 has been decompressed"
|
||||
elif [ $format = "rar" ];then
|
||||
rar -x $2
|
||||
echo "$2 has been decompressed"
|
||||
if [ $files -eq 0 ];then
|
||||
decompress 0 $2
|
||||
elif [ $files -eq 1 ];then
|
||||
if [ -d $4 ];then
|
||||
echo "Directory $4 will be decompressed"
|
||||
elif [ -f $4 ];then
|
||||
echo "File $4 will be decompressed"
|
||||
else
|
||||
echo "Format $format unknown"
|
||||
echo "$4 no sush a file or directory"
|
||||
exit
|
||||
fi
|
||||
decompress $3 $
|
||||
fi
|
||||
elif [ $1 = "-c" ];then
|
||||
if [ -z $3 ];then
|
||||
@@ -90,41 +146,67 @@ elif [ $1 = "-c" ];then
|
||||
echo "No format specified"
|
||||
elif [ $2 = "tar" ] 2> /dev/null ;then
|
||||
tar cvf $3.tar $3
|
||||
if [ $? -eq 0 ];then
|
||||
echo "$3 has been compressed"
|
||||
fi
|
||||
elif [ $2 = "tar.gz" ] 2> /dev/null ;then
|
||||
tar cvzf $3.tar.gz $3
|
||||
if [ $? -eq 0 ];then
|
||||
echo "$3 has been compressed"
|
||||
fi
|
||||
elif [ $2 = "tar.bz2" ] 2> /dev/null ;then
|
||||
tar cvjf $3.tar.bz2 $3
|
||||
if [ $? -eq 0 ];then
|
||||
echo "$3 has been compressed"
|
||||
fi
|
||||
elif [ $2 = "tar.xz" ] 2> /dev/null ;then
|
||||
tar cvJf $3.tar.xz $3
|
||||
if [ $? -eq 0 ];then
|
||||
echo "$3 has been compressed"
|
||||
fi
|
||||
elif [ $2 = "tbz2" ] 2> /dev/null ;then
|
||||
tar cvjf $3.tbz2 $3
|
||||
if [ $? -eq 0 ];then
|
||||
echo "$3 has been compressed"
|
||||
fi
|
||||
elif [ $2 = "tgz" ] 2> /dev/null ;then
|
||||
tar cvjf $3.tgz $3
|
||||
if [ $? -eq 0 ];then
|
||||
echo "$3 has been compressed"
|
||||
fi
|
||||
elif [ $2 = "txz" ] 2> /dev/null ;then
|
||||
tar cvJf $3.txz $3
|
||||
if [ $? -eq 0 ];then
|
||||
echo "$3 has been compressed"
|
||||
elif [ $2 = "7z" ] 2> /dev/null ;then
|
||||
fi
|
||||
elif [ $2 = "7z" -o $2 = "7zip" ] 2> /dev/null ;then
|
||||
7z a $3.7z $3
|
||||
if [ $? -eq 0 ];then
|
||||
echo "$3 has been compressed"
|
||||
fi
|
||||
elif [ $2 = "zip" ] 2> /dev/null ;then
|
||||
zip $3.zip $3
|
||||
if [ $? -eq 0 ];then
|
||||
echo "$3 has been compressed"
|
||||
fi
|
||||
elif [ $2 = "gz" -o $2 = "gzip" ] 2> /dev/null ;then
|
||||
gzip -9k $3
|
||||
if [ $? -eq 0 ];then
|
||||
echo "$3 has been compressed"
|
||||
fi
|
||||
elif [ $2 = "bz2" -o $2 = "bzip2" ] 2> /dev/null ;then
|
||||
bzip2 $3
|
||||
bzip2 -k $3
|
||||
if [ $? -eq 0 ];then
|
||||
echo "$3 has been compressed"
|
||||
fi
|
||||
elif [ $2 = "rar" ] 2> /dev/null ;then
|
||||
rar -a $3.rar $3
|
||||
if [ $? -eq 0 ];then
|
||||
echo "$3 has been compressed"
|
||||
fi
|
||||
else
|
||||
echo "Format $2 unknown"
|
||||
fi
|
||||
else
|
||||
echo "Unknown option"
|
||||
fi
|
||||
Reference in New Issue
Block a user