#!/bin/sh

## This simple shell-script aims to make compressing files and folders easy and lazy ;-)
## This is also for educational purposes too

## The FUNCTIONS lie here:-

scriptArt() {
echo "============= _______  ___    ___  =======  =======  ======  ======  ======"
echo "||	      |	    |  | \    / |  |     |  |     |  |	     |	     |"
echo "||	      |	    |  |  \  /  |  |------  |------  |~~~~~  |-----  |-----"
echo "||	      |	    |  |   \/   |  |	    | \	     |		  |	  |"
echo "============= |_____|  |	|  |	    |  \     |=====  ======  ======"
echo ""
}

compressIt() {
echo "There are 3 built-in Compression-Algorithms you can use in GNU+Linux"
echo ""
echo "Choose which Compression-Algorithm you want to use"
echo "--------------------------------------------------"
echo "1 = GZip  --> FASTEST compression speed"
echo "2 = BZip --> MODERATE compression-speed and archive-size"
echo "3 = XZip  --> SMALLEST archive size"
# echo ""
# echo "OR you can just enter \"a\" to ABORT the operation"
echo ""

read ALGORITHM
echo ""

case $ALGORITHM in
    1) echo "Now the extension will be \".tar.gz\""
       COMPRESS="tar -czvf"
       EXT=".tar.gz"
       ;;
    2) echo "Now the extension will be \".tar.bz2\""
       COMPRESS="tar -cjvf"
       EXT=".tar.bz2"
       ;;
    3) echo "Now the extension will be \".tar.xz\""
       COMPRESS="tar -cJvf"
       EXT=".tar.xz"
       ;;
    a) echo "aborting operation";;
    *) echo "Now Using \"BZip-compression\" Algorithm by Default"
	COMPRESS="tar -cjvf"
        EXT=".tar.bz2"
	;;
esac

echo ""
echo "---------------------------------"
echo "| Compression-Algorithm Set :-D |"
echo "---------------------------------"
echo ""
}

archiveIt() {
echo "Now select FILEs/FOLDERs you want to Compress & Archive ??"
echo "-------------------------------------------------------"

echo "Type the name of the FILE or FOLDER you want to compress/archive: "
read OBJECT

$COMPRESS $OBJECT$EXT $OBJECT
}

## main program lies here:-
clear
scriptArt
compressIt
archiveIt
