Skip to content

Instantly share code, notes, and snippets.

@BohdanTkachenko
Created September 5, 2014 12:32
Show Gist options
  • Save BohdanTkachenko/75c93be5d3c92ab62ac0 to your computer and use it in GitHub Desktop.
Save BohdanTkachenko/75c93be5d3c92ab62ac0 to your computer and use it in GitHub Desktop.
This tools allows you to easily put subdirectories of some directory to 7z archives. It also tests each archive and creates md5 and sha1 sum files.
#!/bin/bash
if [ $# -ne 1 ]; then
echo "Usage: $0 <directory name>"
echo ""
echo "This tools allows you to easily put subdirectories of some directory to 7z archives."
echo "It also tests each archive and creates md5 and sha1 sum files."
exit 1
fi
mkdir -p archive/$1
for path in `find $1 -type d -d 1`
do
echo -e "\x1B[37mProcessing \x1B[33m\x1B[1m$path\x1B[0m\x1B[39m\x1B[37m:\x1B[39m"
name=`echo $path | sed "s/^$1\///"`
compressed_path="archive/$1/$name.7z"
if [ -f $compressed_path ]; then
echo -e "\t\x1B[33m\x1B[1m$compressed_path\x1B[0m\x1B[39m is already exists. \x1B[31mDeleting...\x1B[39m"
rm -rf $compressed_path
fi
echo -ne "\tcompressing to \x1B[33m\x1B[1m$compressed_path\x1B[0m\x1B[39m... "
compress=`7z -r -mx=9 a $compressed_path $path`
if [ `echo $compress | grep "Everything is Ok" | wc -l` == '1' ]; then
echo -e "\x1B[32m\x1B[1mOK\x1B[0m\x1B[39m"
else
echo -e "\x1B[31m\x1B[1mFAIL\x1B[0m\x1B[39m"
echo $compress > archive.err.log
exit 2
fi
echo -ne "\ttesting \x1B[33m\x1B[1m$compressed_path\x1B[0m\x1B[39m... "
test=`7z t $compressed_path`
if [ `echo $test | grep "Everything is Ok" | wc -l` == '1' ]; then
echo -e "\x1B[32m\x1B[1mOK\x1B[0m\x1B[39m"
else
echo -e "\x1B[31m\x1B[1mFAIL\x1B[0m\x1B[39m"
echo $compress > archive.err.log
exit
fi
done
sha1sum archive/$1/*.7z > archive/$1/sha1sum.txt
md5sum archive/$1/*.7z > archive/$1/md5sum.txt
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment