Commit b1cec7e2 authored by Cédric Marie's avatar Cédric Marie

mytarc/mytarx: Add an option for no compression

When archiving audio or video files, the content is already compressed,
and there is no point in trying to compress it again. Creating a simple
.tar archive is more appropriate in that case.

In mytarc, add an option (-n) so that the archive is not compressed
(create .tar instead of .tar.xz).

In mytarx, check the extension of the archive, and extract accordingly.
Signed-off-by: Cédric Marie's avatarCédric Marie <cedric@hjuvi.fr.eu.org>
parent 790f073b
#!/bin/sh
# mytarc - Create an archive (.tar.xz file) with the content of a directory
# mytarc - Create an archive (.tar[.xz] file) with the content of a directory
# This file is part of Painted Shell - Shell configuration and scripts.
#
# Written in 2013-2019 by Cédric Marie
......@@ -17,22 +17,25 @@ print_usage()
{
command=$(basename $0)
printf "Usage: $command [OPTION]... DIRECTORY\n"
printf "Create an archive (.tar.xz[.enc] file) with the content of a directory.\n\n"
printf "Create an archive (.tar[.xz][.enc] file) with the content of a directory.\n\n"
printf "Options:\n"
printf " -h display this message\n"
printf " -n don't compress (create .tar instead of .tar.xz)\n"
printf " -t timestamp output file\n"
printf " -e encrypt output file with password\n"
printf " -s create a .sha256sum file\n"
}
option_dontcompress=0
option_timestamp=0
option_encrypt=0
option_sha256sum=0
# Get options from command line
while getopts htes OPT
while getopts hntes OPT
do
case $OPT in
h) print_usage; exit 0;;
n) option_dontcompress=1;;
t) option_timestamp=1;;
e) option_encrypt=1;;
s) option_sha256sum=1;;
......@@ -42,11 +45,18 @@ done
shift $(($OPTIND - 1))
if [ "$1" = "" -o ! -d "$1" ]; then print_usage; exit 1; fi
if [ $option_dontcompress -eq 1 ]; then
file_ext=tar
tar_opt=
else
file_ext=tar.xz
tar_opt=J
fi
dir=${1%/}
if [ $option_timestamp -eq 1 ]; then
file=$dir.`date +%F.%Hh%Mm%Ss`.tar.xz
file=$dir.`date +%F.%Hh%Mm%Ss`.${file_ext}
else
file=$dir.tar.xz
file=$dir.${file_ext}
fi
[ -e "$file" ] && printf "$file already exists\n" && exit 1
if [ $option_encrypt -eq 1 ]; then
......@@ -55,7 +65,8 @@ if [ $option_encrypt -eq 1 ]; then
else
output_file=$file
fi
tar -Jcvf $file $dir
printf "\033[1mCreate archive...\033[0m\n"
tar -${tar_opt}cvf $file $dir
if [ $option_encrypt -eq 1 ]; then
openssl aes-256-cbc -pbkdf2 -e -a -salt -in $file -out $output_file
rm -f $file
......
#!/bin/sh
# mytarx - Extract an archive (.tar.xz file)
# mytarx - Extract an archive (.tar[.xz] file)
# This file is part of Painted Shell - Shell configuration and scripts.
#
# Written in 2013-2019 by Cédric Marie
......@@ -17,7 +17,7 @@ print_usage()
{
command=$(basename $0)
printf "Usage: $command [OPTION]... FILE\n"
printf "Extract an archive (.tar.xz[.enc] file).\n\n"
printf "Extract an archive (.tar[.xz][.enc] file).\n\n"
printf "Options:\n"
printf " -h display this message\n"
}
......@@ -36,6 +36,7 @@ option_crypt=0
if [ "$1" = "" -o ! -f "$1" ]; then print_usage; exit 1; fi
if [ -f "${1}.sha256sum" ]; then
printf "\033[1mCheck sha256sum...\033[0m\n"
sha256sum -c ${1}.sha256sum || exit 1;
fi
file=${1%.enc}
......@@ -43,13 +44,24 @@ if [ "$file" != "$1" ]; then
option_crypt=1
[ -e "$file" ] && printf "$file already exists\n" && exit 1
fi
dir=${file%.tar.xz}
[ "$dir" = "$file" ] && print_usage && exit 1
dir_tar_xz=${file%.tar.xz}
dir_tar=${file%.tar}
if [ "$dir_tar_xz" != "$file" ]; then
dir=$dir_tar_xz
tar_opt=J
elif [ "$dir_tar" != "$file" ]; then
dir=$dir_tar
tar_opt=
else
print_usage
exit 1
fi
printf "\033[1mExtract archive...\033[0m\n"
dir=${dir%.*-*-*.*h*m*s}
[ -e "$dir" ] && printf "$dir already exists\n" && exit 1
if [ $option_crypt -eq 1 ]; then
openssl aes-256-cbc -pbkdf2 -d -a -in $1 -out $file
fi
tar -Jxvf $file
tar -${tar_opt}xvf $file
[ $option_crypt -eq 1 ] && rm -f $file
printf "\033[1mOutput directory:\033[0m $dir\n"
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment