#!/bin/sh



     ##########################################################################
     #                                                                        #
     #  Copyright (C) 2002-2003 Luc Cottyn <luc@xbone.be>                     #
     #                          Michael G. Manry <mgmanry@linuxorbit.com>     #
     #                                                                        #
     #  This program is free software; you can redistribute it and/or modify  #
     #  it under the terms of the GNU General Public License as published by  #
     #  the Free Software Foundation; either version 2 of the License, or     #
     #  (at your option) any later version.                                   #
     #                                                                        #
     #  This program is distributed in the hope that it will be useful,       #
     #  but WITHOUT ANY WARRANTY; without even the implied warranty of        #
     #  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         #
     #  GNU General Public License for more details.                          #
     #                                                                        #
     #  You should have received a copy of the GNU General Public License     #
     #  along with this program; if not, write to the Free Software           #
     #  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.             #
     #                                                                        #
     ##########################################################################



SVERSION="1.3.1"
SWARET="swaret $SVERSION"
EMAIL="xbone@xbone.be"
EMAIL2="mgmanry@linuxorbit.com"
MSN="xbone@xbone.be"
MSN2="linuxsneaker@hotmail.com"
ICQ="10527685"
ICQ2="9427006"
WWW="http://swaret.xbone.be"
USERPWD="$PWD"
export SVERSION SWARET EMAIL EMAIL2 MSN MSN2 ICQ ICQ2 WWW USERPWD

help()
{
echo "-----------------------------------------------------------

 --update
 --upgrade              [-p|-e|-a|-ap|-ae]
 --up-all               [-A]
 --upgrade KEYWORD      [-p|-e|-a|-ap|-ae]
 --up-all KEYWORD       [-A]
 --install KEYWORD      [-p|-e|-a|-ap|-ae]
 --in-all KEYWORD       [-A]
 --reinstall KEYWORD    [-p|-e|-a|-ap|-ae]
 --rein-all KEYWORD     [-A]
 --download KEYWORD     [-p|-e|-a|-ap|-ae]
 --do-all KEYWORD       [-A]
 --sources KEYWORD      [-A]
 --resume               [-p|-e|-s]
 --re-all
 --dep                  [-A]
 --dep KEYWORD          [-A]
 --remove KEYWORD       [-A]
 --list                 [-p|-e|-s|-u|-up|-ue|-i|-n|-np|-ne]
 --search KEYWORD       [-p|-e|-s|-u|-up|-ue|-i|-n|-np|-ne]
 --show KEYWORD
 --pgp                  [-i]
 --log                  [-t]
 --clear                [-l]
 --clean
 --config
 --faq
 --htus                 
 --help
 --morehelp
 --manual               [-c]
 --version

-----------------------------------------------------------
E-Mail: $EMAIL - $EMAIL2
MSN: $MSN - $MSN2
ICQ: $ICQ - $ICQ2
WWW: $WWW"
}

config()
{
if [ ! -f /usr/doc/swaret-$SVERSION/swaret.conf.new ]; then
	echo "swaret Config File Example not found!"
	exit
else	
	more /usr/doc/swaret-$SVERSION/swaret.conf.new
fi
}

faq()
{
if [ ! -f /usr/doc/swaret-$SVERSION/FAQ ]; then
	echo "swaret FAQ File not found!"
	exit
else
	more /usr/doc/swaret-$SVERSION/FAQ
fi
}

htus()
{
if [ ! -f /usr/doc/swaret-$SVERSION/HOW-TO-USE-SWARET ]; then
        echo "swaret HOW-TO-USE-SWARET File not found!"
        exit
else
        more /usr/doc/swaret-$SVERSION/HOW-TO-USE-SWARET
fi
}

morehelp()
{
if [ ! -f /usr/doc/swaret-$SVERSION/HELP ]; then
	echo "swaret HELP File not found!"
	exit
else
	more /usr/doc/swaret-$SVERSION/HELP
fi

}

case $1 in
        "--config")     
			echo "$SWARET"
                        config
			exit
                        ;;
        "--faq")        
			echo "$SWARET"
                        faq
			exit
                        ;;
        "--htus")
                        echo "$SWARET"
                        htus
                        exit
                        ;;
        "--help")       
			echo "$SWARET"
                        help
			exit
                        ;;
        "--morehelp")   
			echo "$SWARET"
                        morehelp
			exit
                        ;;
        "--manual")     
			echo "$SWARET"
			echo
                        if [[ "$2" == "-c" ]]; then
                                if [ ! -f /usr/man/man5/swaret.conf.5.gz ]; then
                                        echo "swaret.conf(5) Manual not found!"
					exit
                                fi
				if test `which man 2>/dev/null | wc -l` -eq 1; then
                                	man swaret.conf
				else
					echo "'man' is not installed!"
					echo "'man' can be found in the Slackware Packages Root slackware/ap/"
					exit
				fi
                        else    
                                if [ ! -f /usr/man/man8/swaret.8.gz ]; then
                                        echo "swaret(8) Manual not found!"
					exit
                                fi
                                if test `which man 2>/dev/null | wc -l` -eq 1; then
                                        man swaret.conf
                                else
                                        echo "'man' is not installed!"
                                        echo "'man' can be found in the Slackware Packages Root slackware/ap/"
                                        exit
                                fi
                        fi
			exit
                        ;;
	"--version")
			echo "swaret $SVERSION"
			exit
			;;
        "--update")
                   ;;
        "--upgrade")
                   ;;
        "--up-all")
                   ;;
        "--install")
                   ;;
        "--in-all")
                   ;;
        "--reinstall")
                   ;;
        "--rein-all")
                   ;;
        "--remove")
                   ;;
        "--list")
                   ;;
        "--search")
                   ;;
        "--download")
                   ;;
        "--do-all")
                   ;;
        "--sources")
                   ;;
        "--resume")
                   ;;
        "--re-all")
                   ;;
        "--dep")
                   ;;
	"--show")
                   ;;
        "--clean")
                   ;;
        "--clear")
                   ;;
        "--pgp")
                   ;;
	"--log")
		   ;;
	*)
		echo "$SWARET"
		help
		exit;
esac

HEADER()
{
	echo "$SWARET"
	echo
}

MSG()
{
        echo "$2"
        logme "$1" "$2"
}

MSGERR()
{
        echo "$2"
        logme "$1" "$2"
        exit
}

check_wget()
{
	if test `which wget 2>/dev/null | wc -l` -eq 0;
	then
        	MSG "GLOBAL" "You need 'wget' in order to use swaret $SVERSION!"
                MSGERR "GLOBAL" "'wget' can be found in the Slackware Packages Root slackware/n/"
	fi
}

check_rsync()
{
	if test `which rsync 2>/dev/null | wc -l` -eq 0;
	then
		MSG "GLOBAL" "You need 'rsync' in order to use swaret $SVERSION!"
        	MSGERR "GLOBAL" "'rsync' can be found in the Slackware Packages Root slackware/n/"
	fi
}

check_gnupg()
{
  if test `which gpg 2>/dev/null | wc -l` -eq 0;
  then
	HEADER
        MSG "GLOBAL" "You need 'gpg' in order to use swaret $SVERSION!"
        MSG "GLOBAL" "'gpg' can be found in the Slackware Package 'gnupg'"
        MSGERR "GLOBAL" "'gnupg' can be found in the Slackware Packages Root slackware/n/"
  fi
}

cleanup_quick()
{
	rm -f *.amp
	rm -f *.pmt
	rm -f *.tmp
	rm -f *.xmp
	rm -f *.zmp
	rm -f *.omp
	rm -f *.imp
	rm -f *.mmx
	rm -f *.zzx
	rm -f .cache/*.pmt
	rm -f .cache/*.tmp
	rm -f *.[0-9]
	rm -f $PACKAGES_LOGDIR/*:*
	rm -f *.list
	rm -f *.upgrade
	rm -f *.exclude
        rm -f *.only
	rm -f *.important
	rm -f *.asc
	rm -f *html*
	rm -f *uild
	rm -f *.lock
	rm -f *.corrupt*
	rm -f libraries-*
	rm -f URL
}

cleanup()
{
	cleanup_quick
	rm -f *gz
	rm -f *bz2
	rm -f $CDIR/sources/*
	copy_from_cache
}

log()
{
  if [[ "$LOG" == "1" ]]; then
    if test `cat $LF 2>/dev/null | wc -l` -eq 0; then
      echo "swaret Log File '$LF' is empty!"
    else
      if [[ "$1" == "-t" ]]; then
	echo
	tail -n15 -f $LF
	echo
	exit
      else
       	echo
	cat $LF 2>/dev/null | more
	echo
	exit
      fi
    fi
  else
    MSGERR "log()" "'LOG' not set to 1 in /etc/swaret.conf!"
  fi
}


progress()
{
        URL

        x=0
        i=1
        SIZECHECK=0
        SECRET=0

                check_procs()
                {
                        PROCS=`ps auxw | grep wget | grep -v grep | awk '{print$2}'`
                        for z in $PROCS
                        do
				cmdlineTMP=`cat /proc/$z/cmdline 2>/dev/null | grep -i "/$1" | wc -l`
				if [ -z "$cmdlineTMP" ]; then
				  cmdlineTMP=0
				fi
                                if test $cmdlineTMP -ge 1; then
                                        SECRET=1
				fi
                        done
                        if test $SECRET -eq 0
                        then
                                if [ ! -f $1 ]; then
                                        touch $1.pmt 2>/dev/null
                                        i=0
                                else
                                        SIZE=`ls -alL $1 2>/dev/null | awk '{print$5}'`
                                        if [ "$SIZE" = "0" ]; then
                                                i=0
                                        else
                                                touch $1.tmp
                                                i=0
                                        fi
                                fi
                        fi
                        SECRET=0
                }
		printf "++++ -"
		PSWAP=0
                while test $i -ne 0
                do
			sleep 1
                        if test $x -eq 0
                        then
                           check_procs $1
                           if test $i -eq 1
                           then
				printf "\b\b\b\b\b\b"
				if test $PSWAP -eq 0; then
                                printf "+    \\"
				else
				printf "   + \\"
				fi
                                x=1
                           fi
                        fi
                        if test $x -eq 1
                        then
                           check_procs $1
                           if test $i -eq 1
                           then
				printf "\b\b\b\b\b\b"
				if test $PSWAP -eq 0; then
                                printf "++   |"
				else
				printf "  ++ |"
				fi
                                x=2
                           fi
                        fi
                        if test $x -eq 2
                        then
                           check_procs $1
                           if test $i -eq 1
                           then
				printf "\b\b\b\b\b\b"
				if test $PSWAP -eq 0; then
                                printf "+++  /"
				else
				printf " +++ /"
				fi
                                x=3
                           fi
                        fi
                        if test $x -eq 3
                        then
                           check_procs $1
                           if test $i -eq 1
                           then
                                printf "\b\b\b\b\b\b"
                                if test $PSWAP -eq 0; then
				PSWAP=1
                                else
				PSWAP=0
				fi
                                printf "++++ -"
                                x=0
                           fi
                        fi
                done
		printf "\b\b\b\b\b\b      \b\b\b\b\b\b"
}

progress_rsync()
{
	URL

	x=0
	i=1
	SIZECHECK=0
	SECRET=0
  
		check_procs()
		{
                        PROCS=`ps auxw | grep rsync | grep -v grep | awk '{print$2}'`
                        for z in $PROCS
                        do
                                cmdlineTMP=`cat /proc/$z/cmdline 2>/dev/null | grep -i "/$1" | wc -l`
                                if [ -z "$cmdlineTMP" ]; then
                                  cmdlineTMP=0
                                fi
                                if test $cmdlineTMP -ge 1; then
                                        SECRET=1
                                fi
                        done
                        if test $SECRET -eq 0
                        then
				SIZE=`ls -alL .$1* 2>/dev/null | awk '{print$5}'`
				if [ -z "$SIZE" ]; then
					if [ -f $1 ]; then
						SIZE=`ls -alL $1 2>/dev/null | awk '{print$5}'`
						if [ "$SIZE" = "0" ]; then
							i=0
						else
							touch $1.tmp
							i=0
						fi
					else
						i=0
					fi
				fi
                        fi
			SECRET=0
		}
		printf "++++ -"
		PSWAP=0
                while test $i -ne 0
                do
			sleep 1
                        if test $x -eq 0
			then
			   	check_procs $1
                           if test $i -eq 1
                           then
                                printf "\b\b\b\b\b\b"
                                if test $PSWAP -eq 0; then
                                printf "+    \\"
                                else
                                printf "   + \\"
                                fi
                                x=1
			   fi
                        fi
                        if test $x -eq 1
                        then
				check_procs $1
                           if test $i -eq 1
                           then
                                printf "\b\b\b\b\b\b"
                                if test $PSWAP -eq 0; then
                                printf "++   |"
                                else
                                printf "  ++ |"
                                fi
                                x=2
			   fi
                        fi
                        if test $x -eq 2
                        then
                           	check_procs $1
                           if test $i -eq 1
                           then
                               	printf "\b\b\b\b\b\b"
                               	if test $PSWAP -eq 0; then
                               	printf "+++  /"
                               	else
                               	printf " +++ /"
                               	fi
                                x=3
			   fi
                        fi
                        if test $x -eq 3
                        then
                           	check_procs $1
                           if test $i -eq 1
                           then
                                printf "\b\b\b\b\b\b"
                                if test $PSWAP -eq 0; then
                                PSWAP=1
                                else
                                PSWAP=0
                                fi
                                printf "++++ -"
                                x=0
			   fi
                        fi
		done
		printf "\b\b\b\b\b\b      \b\b\b\b\b\b"
}

count_size()
{
	rm -f $1.tmp
	rm -f $1.pmt
        COUNT=0
        SIZE=0
        TOTAL=0
        CHECK=0
	SWAPME=0
        SECRET=0
        SIZECHECK=0
        PROCS=0
        if [[ "$2" == "-p" || "$2" == "-ap" ]]; then
                SIZE=`cat $CDIR/CHECKSUMS.patches 2>/dev/null | grep "/$1" | awk '{print$2}'`
                SWAPME=1
        fi
        if [[ "$2" == "-e" || "$2" == "-ae" ]]; then
                SIZE=`cat $CDIR/CHECKSUMS.extra 2>/dev/null | grep "/$1" | awk '{print$2}'`
                SWAPME=1
        fi
        if [[ "$2" == "-a" ]]; then
            if test $SWAPME -eq 0
            then
                SIZE=`cat $CDIR/CHECKSUMS 2>/dev/null | grep "/$1" | awk '{print$2}'`
            fi
	fi

        echo -n "         "
        while test $COUNT -ne $SIZE
        do
		sleep 1
                PROCS=`ps auxw | grep wget | grep -v grep | awk '{print$2}'`
                for z in $PROCS
                do
                        if test `cat /proc/$z/cmdline 2>/dev/null | grep -i "/$1" | wc -l` -ge 1
                        then
                                SECRET=1
                        fi
                done
                if test $SECRET -eq 0
                then
                        SIZECHECK=`ls -alL $1 2>/dev/null | awk '{print$5}'`
                        if [ -z "$SIZECHECK" ]; then
                                SIZECHECK=0
                        fi
                        if test $SIZE -ne $SIZECHECK
                        then
				printf "\b\b\b\b\b\b\b"
                                echo -n "0%/100%"
                                touch $1.pmt 
                                COUNT=$SIZE
                        fi
                fi
                if [ ! -f $1.pmt ]; then
                   if [ ! -f $1 ]; then
                        COUNT=0
                        TOTAL=$COUNT
                        printf "\b\b\b\b\b\b\b"
                        echo -n "0%/100%"
                   else
                        COUNT=`ls -alL $1 2>/dev/null | awk '{print$5}'`
                        TOTAL=`echo "$COUNT * 100 / $SIZE" | bc`
                        CHECK=`echo "$TOTAL" | wc -c`
                        if test $CHECK -eq 2
                        then
                                printf "\b\b\b\b\b\b\b"
                                echo -n "$TOTAL%/100%"
                        fi
                        if test $CHECK -eq 3
                        then
                                printf "\b\b\b\b\b\b\b\b"
                                echo -n "$TOTAL%/100%"
                        fi
                        if test $CHECK -eq 4
                        then
                                printf "\b\b\b\b\b\b\b\b\b"
                                echo -n "$TOTAL%/100%"
                                if test $TOTAL -eq 100
                                then
                                        COUNT=$SIZE
                                        touch $1.tmp
                                fi
                        fi
                   fi
                fi
                SECRET=0
        done
}

count_size_rsync()
{
	rm -f $1.tmp
	rm -f $1.pmt
	COUNT=0
	SIZE=0
	TOTAL=0
	CHECK=0
	SWAPME=0
	SECRET=0
	SIZECHECK=0
	PROCS=0
        if [[ "$2" = "-p" || "$2" = "-ap" ]]; then
                SIZE=`cat $CDIR/CHECKSUMS.patches 2>/dev/null | grep "/$1" | awk '{print$2}'`
                SWAPME=1
        fi
        if [[ "$2" = "-e" || "$2" = "-ae" ]]; then
                SIZE=`cat $CDIR/CHECKSUMS.extra 2>/dev/null | grep "/$1" | awk '{print$2}'`
                SWAPME=1
        fi
        if [[ "$2" = "-a" ]]; then
            if test $SWAPME -eq 0
            then
                SIZE=`cat $CDIR/CHECKSUMS 2>/dev/null | grep "/$1" | awk '{print$2}'`
            fi
        fi

	echo -n "         "
        while test $COUNT -ne $SIZE 
        do
		sleep 1
		PROCS=`ps auxw | grep rsync | grep -v grep | awk '{print$2}'`
		for z in $PROCS
		do
			if test `cat /proc/$z/cmdline 2>/dev/null | grep -i "/$1" | wc -l` -ge 1
			then
				SECRET=1
			fi
		done
		if test $SECRET -eq 0
		then
			SIZECHECK=`ls -alL $1 2>/dev/null | awk '{print$5}'`
			if [ -z "$SIZECHECK" ]; then
				SIZECHECK=0
			fi
			if test $SIZE -ne $SIZECHECK
			then
				printf "\b\b\b\b\b\b\b"
				echo -n "0%/100%"
				touch $1.pmt 
				COUNT=$SIZE
			fi
		fi
		if [ ! -f $1.pmt ]; then
		   CHECKIT=`ls -alL .$1* 2>/dev/null | awk '{print$5}' | wc -c`
		   if test $CHECKIT -eq 0
		   then
			   CHECKIT=`ls -alL $1 2>/dev/null | wc -l`
		   fi
	           if test $CHECKIT -eq 0
		   then
			COUNT=0
			TOTAL=$COUNT
			printf "\b\b\b\b\b\b\b"
			echo -n "0%/100%"
		   else
			COUNT=`ls -alL .$1* 2>/dev/null | awk '{print$5}'`
			if [ -z "$COUNT" ]; then
				COUNT=`ls -alL $1 2>/dev/null | awk '{print$5}'`
			fi
			TOTAL=`echo "$COUNT * 100 / $SIZE" | bc`
			CHECK=`echo "$TOTAL" | wc -c`
			if test $CHECK -eq 2
			then
				printf "\b\b\b\b\b\b\b"
				echo -n "$TOTAL%/100%"
			fi
                       	if test $CHECK -eq 3 
                    	then
				printf "\b\b\b\b\b\b\b\b"
				echo -n "$TOTAL%/100%"
                        fi
                        if test $CHECK -eq 4 
                       	then
				printf "\b\b\b\b\b\b\b\b\b"
				if test $COUNT -eq $SIZE
				then
					echo -n "100%/100%"
					touch $1.tmp
				fi
			fi
		   fi
		fi
		SECRET=0
        done
}

count_sources_size()
{
        rm -f $1.tmp
        rm -f $1.pmt
        COUNT=0
        SIZE=0
        TOTAL=0
        CHECK=0
        SWAPME=0
        SECRET=0
        SIZECHECK=0
        PROCS=0
        SIZE=`cat $CDIR/CHECKSUMS 2>/dev/null | grep "$3" | grep "/$1" | awk '{print$2}'`

        echo -n "         "
        while test $COUNT -ne $SIZE
        do
		sleep 1
                PROCS=`ps auxw | grep wget | grep -v grep | awk '{print$2}'`
                for z in $PROCS
                do
                        if test `cat /proc/$z/cmdline 2>/dev/null | grep -i "/$1" | wc -l` -ge 1
                        then
                                SECRET=1
                        fi
                done
                if test $SECRET -eq 0
                then
                        SIZECHECK=`ls -alL $1 2>/dev/null | awk '{print$5}'`
                        if [ -z "$SIZECHECK" ]; then
                                SIZECHECK=0
                        fi
                        if test $SIZE -ne $SIZECHECK
                        then
                                printf "\b\b\b\b\b\b\b"
                                echo -n "0%/100%"
                                touch $1.pmt
                                COUNT=$SIZE
                        fi
                fi
                if [ ! -f $1.pmt ]; then
                   if [ ! -f $1 ]; then
                        COUNT=0
                        TOTAL=$COUNT
                        printf "\b\b\b\b\b\b\b"
                        echo -n "0%/100%"
                   else
                        COUNT=`ls -alL $1 2>/dev/null | awk '{print$5}'`
                        TOTAL=`echo "$COUNT * 100 / $SIZE" | bc`
                        CHECK=`echo "$TOTAL" | wc -c`
                        if test $CHECK -eq 2
                        then
                                printf "\b\b\b\b\b\b\b"
                                echo -n "$TOTAL%/100%"
                        fi
                        if test $CHECK -eq 3
                        then
                                printf "\b\b\b\b\b\b\b\b"
                                echo -n "$TOTAL%/100%"
                        fi
                        if test $CHECK -eq 4
                        then
                                printf "\b\b\b\b\b\b\b\b\b"
                                echo -n "$TOTAL%/100%"
                                if test $TOTAL -eq 100
                                then
                                        COUNT=$SIZE
                                        touch $1.tmp
                                fi
                        fi
                   fi
                fi
                SECRET=0
        done
}

count_sources_size_rsync()
{
        rm -f $1.tmp
        rm -f $1.pmt
        COUNT=0
        SIZE=0
        TOTAL=0
        CHECK=0
        SWAPME=0
        SECRET=0
        SIZECHECK=0
        PROCS=0
        SIZE=`cat $CDIR/CHECKSUMS 2>/dev/null | grep "$3" | grep "/$1" | awk '{print$2}'`

        echo -n "         "     
        while test $COUNT -ne $SIZE  
        do
		sleep 1
                PROCS=`ps auxw | grep rsync | grep -v grep | awk '{print$2}'`
                for z in $PROCS
                do
                        if test `cat /proc/$z/cmdline 2>/dev/null | grep -i "/$1" | wc -l` -ge 1
                        then
                                SECRET=1
                        fi
                done
                if test $SECRET -eq 0
                then
                        SIZECHECK=`ls -alL $1 2>/dev/null | awk '{print$5}'`
                        if [ -z "$SIZECHECK" ]; then
                                SIZECHECK=0
                        fi
                        if test $SIZE -ne $SIZECHECK
                        then
                                printf "\b\b\b\b\b\b\b"
                                echo -n "0%/100%"
                                touch $1.pmt
                                COUNT=$SIZE
                        fi
                fi
                if [ ! -f $1.pmt ]; then
                   CHECKIT=`ls -alL .$1* 2>/dev/null | awk '{print$5}' | wc -c`
                   if test $CHECKIT -eq 0
                   then
                           CHECKIT=`ls -alL $1 2>/dev/null | wc -l`
                   fi
                   if test $CHECKIT -eq 0
                   then
                        COUNT=0
                        TOTAL=$COUNT
                        printf "\b\b\b\b\b\b\b"
                        echo -n "0%/100%"
                   else
                        COUNT=`ls -alL .$1* 2>/dev/null | awk '{print$5}'`
                        if [ -z "$COUNT" ]; then
                                COUNT=`ls -alL $1 2>/dev/null | awk '{print$5}'`
                        fi
                        TOTAL=`echo "$COUNT * 100 / $SIZE" | bc`
                        CHECK=`echo "$TOTAL" | wc -c`
                        if test $CHECK -eq 2
                        then
                                printf "\b\b\b\b\b\b\b"
                                echo -n "$TOTAL%/100%"
                        fi
                        if test $CHECK -eq 3
                        then
                                printf "\b\b\b\b\b\b\b\b"
                                echo -n "$TOTAL%/100%"
                        fi
                        if test $CHECK -eq 4
                        then
                                printf "\b\b\b\b\b\b\b\b\b"
                                if test $COUNT -eq $SIZE
                                then
                                        echo -n "100%/100%"
                                        touch $1.tmp
                                fi
                        fi
                   fi
                fi
                SECRET=0
        done
}

wget_file()
{
	wget $PF -t $RETRIES -T $TIMEOUT $Q -c "$1/$2" 2>/dev/null &
}

wget_file_s()
{
        wget $PF -t $RETRIES -T $TIMEOUT $Q -c "$1/$2" 
}

wget_file_buildscript()
{
        wget $PF -t $RETRIES -T $TIMEOUT $Q -c "$1/$2" 2>/dev/null 
}

rsync_file()
{
	rsync --timeout=$TIMEOUT $Q --existing "$1/$2" . 2>/dev/null &
}

rsync_file_s()
{
	rsync --timeout=$TIMEOUT $Q --existing "$1/$2" .
}

rsync_file_buildscript()
{
        rsync --timeout=$TIMEOUT $Q --existing "$1/$2" . 2>/dev/null 
}

copy_file()
{
	cp "$1/$2" $CDIR/ 2>/dev/null
}
touch_it()
{
                                        if test `ls -alL $CDIR/$1 2>/dev/null | wc -l` -eq 1; then
                                            if test `ls -alL $CDIR/$1 2>/dev/null | awk '{print$5}'` -eq $SIZEPKGTMP
                                            then
                                                touch $1.tmp 2>/dev/null
                                            else
                                                rm -f $1.tmp 2>/dev/null
                                            fi
                                        else
                                            rm -f $1.tmp 2>/dev/null
                                        fi
}

checksum_package()
{
  if [[ "$MD5CHECK" == "1" ]]; then
    if [ ! -f $1.md5.lock ]; then
	SHORTPKG=`echo $1 | sed s/'.tgz'//`
	CHKSM_PACKAGE=`cat $CDIR/.cache/CHECKSUMS.md5 2>/dev/null | grep "/$1" | awk '{print$1}'`
	CHK_CHKSM_PACKAGE=`md5sum $CDIR/$1 2>/dev/null | awk '{print$1}'`
	if [[ "$CHKSM_PACKAGE" != "$CHK_CHKSM_PACKAGE" ]]; then
		MSG "checksum_package()" "=> <MD5CHECK> Package $SHORTPKG is CORRUPTED!"
		touch $CDIR/$1.corrupted 2>/dev/null
	else
		MSG "checksum_package()" "=> <MD5CHECK> Package $SHORTPKG is OK!"
		touch $1.md5.lock 2>/dev/null
	fi
    fi
  fi
}

checksum_patch()
{
  if [[ "$MD5CHECK" == "1" ]]; then
    if [ ! -f $1.md5.lock ]; then
	SHORTPKG=`echo $1 | sed s/'.tgz'//`
        CHKSM_PATCH=`cat $CDIR/CHECKSUMS.md5.patches 2>/dev/null | grep "/$1" | awk '{print$1}'`
        CHK_CHKSM_PATCH=`md5sum $CDIR/$1 2>/dev/null | awk '{print$1}'`
        if [[ "$CHKSM_PATCH" != "$CHK_CHKSM_PATCH" ]]; then
                MSG "checksum_patch()" "=> <MD5CHECK> Patch $SHORTPKG is CORRUPTED!"
		touch $CDIR/$1.corrupted 2>/dev/null
        else
                MSG "checksum_patch()" "=> <MD5CHECK> Patch $SHORTPKG is OK!"
		touch $1.md5.lock 2>/dev/null
        fi
    fi
  fi
}

checksum_extra()
{
  if [[ "$MD5CHECK" == "1" ]]; then
    if [ ! -f $1.md5.lock ]; then
	SHORTPKG=`echo $1 | sed s/'.tgz'//`
        CHKSM_EXTRA=`cat $CDIR/CHECKSUMS.md5.extra 2>/dev/null | grep "/$1" | awk '{print$1}'`
        CHK_CHKSM_EXTRA=`md5sum $CDIR/$1 2>/dev/null | awk '{print$1}'`
        if [[ "$CHKSM_EXTRA" != "$CHK_CHKSM_EXTRA" ]]; then
                MSG "checksum_extra()" "=> <MD5CHECK> Extra Package $SHORTPKG is CORRUPTED!"
		touch $CDIR/$1.corrupted 2>/dev/null
        else
                MSG "checksum_extra()" "=> <MD5CHECK> Extra Package $SHORTPKG is OK!"
		touch $1.md5.lock 2>/dev/null
        fi
    fi
  fi
}

checksum_source()
{
  if [[ "$MD5CHECK" == "1" ]]; then
    if [ ! -f $1.md5.lock ]; then
        SHORTPKGTMP=`echo $1 | sed s/'.tar.gz'//`
        SHORTPKGTMP=`echo $SHORTPKGTMP | sed s/'.gz'//`
	SHORTPKGTMP=`echo $SHORTPKGTMP | sed s/'.tar.bz2'//`
	SHORTPKGTMP=`echo $SHORTPKGTMP | sed s/'.bz2'//`
        CHKSM_SOURCES=`cat $CDIR/CHECKSUMS.md5.sources 2>/dev/null | grep "$2" | grep "/$1" | awk '{print$1}'`
        CHK_CHKSM_SOURCES=`md5sum $CDIR/$1 2>/dev/null | awk '{print$1}'`
        if [[ "$CHKSM_SOURCES" != "$CHK_CHKSM_SOURCES" ]]; then
                MSG "checksum_source()" "=> <MD5CHECK> Source $SHORTPKGTMP is CORRUPTED!"
		touch $CDIR/$1.corrupted 2>/dev/null
        else
                MSG "checksum_source()" "=> <MD5CHECK> Source $SHORTPKGTMP is OK!"
		touch $1.md5.lock 2>/dev/null
        fi
    fi
  fi
}

check_for_broken_packages()
{
   PACKAGES_URL=`cat URL 2>/dev/null | awk '{ if(NR == '$2') print $1 }'`
   SHORTPKG=`echo $1 | sed s/'.tgz'//`
   MAX=`cat URL 2>/dev/null | wc -l`
   rm -f $1.tmp 2>/dev/null
   COUNT=0
   CHECKME=0
   COUNTER=$2
   COUNT=`ls $CDIR/*.tgz 2>/dev/null | wc -l | awk '{print$1}'`
   SHORTPKGTMP=`echo $1 | sed s/'.tgz'//`
   if [ ! -z $PACKAGES_URL ]; then
     if test $COUNT -ge 1
     then
        CHECK1=`cat .cache/CHECKSUMS 2>/dev/null | grep "/$1" | awk '{print$2}'`
        CHECK2=`ls -alL $1 2>/dev/null | awk '{print$5}'`
	CHECKFIX=`cat .cache/CHECKSUMS 2>/dev/null | grep "/$1" | wc -l`
        CHECK_BROKEN_PKGS=`cat .cache/CHECKSUMS 2>/dev/null | grep "/$1" | awk '{print$3}' | sed s/'.\/'//`
        if test $CHECKFIX -ne 0
        then
           if test $CHECK1 -ne $CHECK2
           then
		if [[ "$3" == "1" ]]; then
			if [[ "$SWAPME" == "0" ]]; then
				printf "\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b"
				SWAPME=1
			fi
		fi
        	SIZEPKGTMP=`cat .cache/CHECKSUMS 2>/dev/null | grep "/$1" | awk '{print$2}'`
		SIZEPKG=`echo $SIZEPKGTMP / 1024 | bc`
		export AZERTYCHK=1
		MSG "check_for_broken_packages()" "[ $PACKAGES_URL ]"
		echo $QS "### Resuming broken Package $SHORTPKG ($SIZEPKG kB)... "
		if test `echo $PACKAGES_URL | grep rsync | wc -l` -ge 1
		then
                                if [ ! -z $Q ]; then
					rsync_file "$PACKAGES_URL" "$CHECK_BROKEN_PKGS"
                                        count_size_rsync $1 "-a" 
                                else
					rsync_file_s "$PACKAGES_URL" "$CHECK_BROKEN_PKGS"
					touch_it "$1"
                                fi
                else
                                if [ ! -z $Q ]; then
					wget_file "$PACKAGES_URL" "$CHECK_BROKEN_PKGS"
                                        count_size $1 "-a"
                                else
					wget_file_s "$PACKAGES_URL" "$CHECK_BROKEN_PKGS"
					touch_it "$1"
                                fi
		fi
                if [ -f $1.tmp ]; then
                        CHECK1=`cat .cache/CHECKSUMS 2>/dev/null | grep "/$1" | awk '{print$2}'`
                        CHECK2=`ls -alL $1 2>/dev/null | awk '{print$5}'`
			if [ "$CHECK1" == "$CHECK2" ]; then
				FPKGSW=1
				FPKGTSIZE=`echo "$FPKGTSIZE + $SIZEPKG" | bc`
				FPKGC=`echo "$FPKGC + 1" | bc`
				if [ ! -z $Q ]; then
                                	echo " DONE!"
				fi
				logme "check_for_broken_packages()" "### Resuming broken Package $SHORTPKG ($SIZEPKG kB)... DONE!"
				touch $1.tmp
				CHECKME=1
                        else
				if [ ! -z $Q ]; then
                                	echo " FAILED!"
				fi
				logme "check_for_broken_packages()" "### Resuming broken Package $SHORTPKG ($SIZEPKG kB)... FAILED!"
				rm -f $1.tmp
				RECORDS=`cat URL 2>/dev/null | wc -l`
				COUNTER=`expr $COUNTER + 1`
				if test $COUNTER -ne `expr $RECORDS + 1`
				then
				    check_for_broken_packages $1 $COUNTER
			        fi
			fi
		else
			if [ ! -z $Q ]; then	
				echo " FAILED!"
			fi
			logme "check_for_broken_packages()" "### Resuming broken Package $SHORTPKG ($SIZEPKG kB)... FAILED!"
			rm -f $1.tmp 2>/dev/null
			RECORDS=`cat URL 2>/dev/null | wc -l`
                              COUNTER=`expr $COUNTER + 1`
                              if test $COUNTER -ne `expr $RECORDS + 1`
                              then
                                    check_for_broken_packages $1 $COUNTER
                              fi
                fi
	   else
		touch $1.tmp 2>/dev/null
           fi
        fi
     fi
   fi
   if [[ "$CHECKME" == "1" ]]; then
   CHECK1=`cat .cache/CHECKSUMS 2>/dev/null | grep "/$1" | awk '{print$2}'`
   CHECK2=`ls -alL $1 2>/dev/null | awk '{print$5}'`
   if [ "$CHECK1" == "$CHECK2" ]; then
	GETPKG="$CHECK_BROKEN_PKGS"
	PACKAGES_URL="$PACKAGES_URL"
	checksum_package $1
	pgp_check_remote "check_for_broken_packages()" "-a" "-a" "$1"
   fi
   fi
   COUNTER=1
}

check_for_broken_patches()
{
   PATCHES_URL=`cat URL 2>/dev/null | awk '{ if(NR == '$2') print $1 }'`
   SHORTPKG=`echo $1 | sed s/'.tgz'//`
   MAX=`cat URL 2>/dev/null | wc -l`
   rm -f $1.tmp 2>/dev/null
   COUNT=0
   CHECKME=0
   COUNTER=$2
   COUNT=`ls $CDIR/*.tgz 2>/dev/null | wc -l | awk '{print$1}'`
   SHORTPKGTMP=`echo $1 | sed s/'.tgz'//`
   if [ ! -z $PATCHES_URL ]; then
     if test $COUNT -ge 1
     then
        CHECK1=`cat CHECKSUMS.patches 2>/dev/null | grep "/$1" | awk '{print$2}'`
        CHECK2=`ls -alL $1 2>/dev/null | awk '{print$5}'`
        CHECKFIX=`cat CHECKSUMS.patches 2>/dev/null | grep "/$1" | wc -l`
        CHECK_BROKEN_PKGS=`cat CHECKSUMS.patches 2>/dev/null | grep "/$1" | awk '{print$3}' | sed s/'.\/'//`
        if test $CHECKFIX -ne 0
        then
           if test $CHECK1 -ne $CHECK2
           then
                if [[ "$3" == "1" ]]; then
                        if [[ "$SWAPME" == "0" ]]; then
                                printf "\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b"
                                SWAPME=1
                        fi
                fi
        	SIZEPKGTMP=`cat CHECKSUMS 2>/dev/null | grep "/$1" | awk '{print$2}'`
		SIZEPKG=`echo $SIZEPKGTMP / 1024 | bc`
                export AZERTYCHK=1
		MSG "check_for_broken_patches()" "[ $PATCHES_URL ]"
		echo $QS "### Resuming broken Patch $SHORTPKG ($SIZEPKG kB)... "
                if test `echo $PATCHES_URL | grep rsync | wc -l` -ge 1
                then
                                if [ ! -z $Q ]; then
					rsync_file "$PATCHES_URL" "$CHECK_BROKEN_PKGS"
                                        count_size_rsync $1 "-p"
                                else
					rsync_file_s "$PATCHES_URL" "$CHECK_BROKEN_PKGS"
					touch_it "$1"
                                fi
                else
                                if [ ! -z $Q ]; then
					wget_file "$PATCHES_URL" "$CHECK_BROKEN_PKGS"
                                        count_size $1 "-p"
                                else
					wget_file_s "$PATCHES_URL" "$CHECK_BROKEN_PKGS"
					touch_it "$1"
                                fi
                fi
                if [ -f $1.tmp ]; then
                        CHECK1=`cat CHECKSUMS.patches 2>/dev/null | grep "/$1" | awk '{print$2}'`
                        CHECK2=`ls -alL $1 2>/dev/null | awk '{print$5}'`
                        if [ "$CHECK1" == "$CHECK2" ]; then
                                FPKGSW=1
                                FPKGTSIZE=`echo "$FPKGTSIZE + $SIZEPKG" | bc`
                                FPKGC=`echo "$FPKGC + 1" | bc`
				if [ ! -z $Q ]; then
                                	echo " DONE!"
				fi
				logme "check_for_broken_patches()" "### Resuming broken Patch $SHORTPKG ($SIZEPKG kB)... DONE!"
                                touch $1.tmp
				CHECKME=1
                        else
				if [ ! -z $Q ]; then
                                	echo " FAILED!"
				fi
				logme "check_for_broken_patches()" "### Resuming broken Patch $SHORTPKG ($SIZEPKG kB)... FAILED!"	
                                rm -f $1.tmp
				RECORDS=`cat URL 2>/dev/null | wc -l`
                                  COUNTER=`expr $COUNTER + 1`
                                  if test $COUNTER -ne `expr $RECORDS + 1`
                                  then
                                    check_for_broken_patches $1 $COUNTER
                                  fi
                        fi
                else
			if [ ! -z $Q ]; then
				echo " FAILED!"
			fi
			logme "check_for_broken_patches()" "### Resuming broken Patch $SHORTPKG ($SIZEPKG kB)... FAILED!" 
                        rm -f $1.tmp
			RECORDS=`cat URL 2>/dev/null | wc -l`
                              COUNTER=`expr $COUNTER + 1`
                              if test $COUNTER -ne `expr $RECORDS + 1`
                              then
                                    check_for_broken_patches $1 $COUNTER
                              fi
                fi
           else
                touch $1.tmp 2>/dev/null
           fi
        fi
     fi
   fi
   if [[ "$CHECKME" == "1" ]];then
   CHECK1=`cat CHECKSUMS.patches 2>/dev/null | grep "/$1" | awk '{print$2}'`
   CHECK2=`ls -alL $1 2>/dev/null | awk '{print$5}'`
   if [ "$CHECK1" == "$CHECK2" ]; then
	GETPKG="$CHECK_BROKEN_PKGS"
	PACKAGES_URL="$PATCHES_URL"
        checksum_patch $1
	pgp_check_remote "check_for_broken_patches()" "-p" "-ap" "$1"
   fi
   fi
   COUNTER=1
}

check_for_broken_extra()
{
   EXTRA_URL=`cat URL 2>/dev/null | awk '{ if(NR == '$2') print $1 }'`
   SHORTPKG=`echo $1 | sed s/'.tgz'//`
   MAX=`cat URL 2>/dev/null | wc -l`
   rm -f $1.tmp
   COUNT=0
   CHECKME=0
   COUNTER=$2
   COUNT=`ls $CDIR/*[t-z] 2>/dev/null | wc -l | awk '{print$1}'`
   SHORTPKGTMP=`echo $1 | sed s/'.tgz'//`
   if [ ! -z $EXTRA_URL ]; then
     if test $COUNT -ge 1
     then
        CHECK1=`cat CHECKSUMS.extra 2>/dev/null | grep "/$1" | awk '{print$2}'`
        CHECK2=`ls -alL $1 2>/dev/null | awk '{print$5}'`
        CHECKFIX=`cat CHECKSUMS.extra 2>/dev/null | grep "/$1" | wc -l`
        CHECK_BROKEN_PKGS=`cat CHECKSUMS.extra 2>/dev/null | grep "/$1" | awk '{print$3}' | sed s/'.\/'//`
        if test $CHECKFIX -ne 0
        then
           if test $CHECK1 -ne $CHECK2
           then
                if [[ "$3" == "1" ]]; then
                        if [[ "$SWAPME" == "0" ]]; then
				printf "\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b"
                                SWAPME=1
                        fi
                fi
        	SIZEPKGTMP=`cat CHECKSUMS 2>/dev/null | grep "/$1" | awk '{print$2}'`
		SIZEPKG=`echo $SIZEPKGTMP / 1024 | bc`
                export AZERTYCHK=1
                MSG "check_for_broken_extra()" "[ $EXTRA_URL ]"
		echo $QS "### Resuming broken Extra Package $SHORTPKG ($SIZEPKG kB)... "
                if test `echo $EXTRA_URL | grep rsync | wc -l` -ge 1
                then
                                if [ ! -z $Q ]; then
					rsync_file "$EXTRA_URL" "$CHECK_BROKEN_PKGS"
                                        count_size_rsync $1 "-e"
                                else
					rsync_file_s "$EXTRA_URL" "$CHECK_BROKEN_PKGS"
					touch_it "$1"
                                fi
                else
                                if [ ! -z $Q ]; then
					wget_file "$EXTRA_URL" "$CHECK_BROKEN_PKGS"
                                        count_size $1 "-e"
				else
					wget_file_s "$EXTRA_URL" "$CHECK_BROKEN_PKGS"
					touch_it "$1"
                                fi
                fi
                if [ -f $1.tmp ]; then
                        CHECK1=`cat CHECKSUMS.extra 2>/dev/null | grep "/$1" | awk '{print$2}'`
                        CHECK2=`ls -alL $1 2>/dev/null | awk '{print$5}'`
                        if [ "$CHECK1" == "$CHECK2" ]; then
                                FPKGSW=1
                                FPKGTSIZE=`echo "$FPKGTSIZE + $SIZEPKG" | bc`
                                FPKGC=`echo "$FPKGC + 1" | bc`
				if [ ! -z $Q ]; then
                                	echo " DONE!"
				fi
				logme "check_for_broken_extra()" "### Resuming broken Extra Package $SHORTPKG ($SIZEPKG kB)... DONE!"
                                touch $1.tmp 2>/dev/null
				CHECKME=1
                        else
				if [ ! -z $Q ]; then
                                	echo " FAILED!"
				fi
				logme "check_for_broken_extra()" "### Resuming broken Extra Package $SHORTPKG ($SIZEPKG kB)... FAILED!"
                                rm -f $1.tmp 2>/dev/null
				RECORDS=`cat URL 2>/dev/null | wc -l`
                                  COUNTER=`expr $COUNTER + 1`
                                  if test $COUNTER -ne `expr $RECORDS + 1`
                                  then
                                    check_for_broken_extra $1 $COUNTER
                                  fi
                        fi
                else
			if [ ! -z $Q ]; then
				echo " FAILED!"
			fi
			logme "check_for_broken_extra()" "### Resuming broken Extra Package $SHORTPKG ($SIZEPKG kB)... FAILED!" 
                        rm -f $1.tmp 2>/dev/null
			RECORDS=`cat URL 2>/dev/null | wc -l`
                              COUNTER=`expr $COUNTER + 1`
                              if test $COUNTER -ne `expr $RECORDS + 1`
                              then
                                    check_for_broken_extra $1 $COUNTER
                              fi
                fi
           else
                touch $1.tmp 2>/dev/null
           fi
        fi
     fi
   fi
   if [[ "$CHECKME" == "1" ]];then
   CHECK1=`cat CHECKSUMS.extra 2>/dev/null | grep "/$1" | awk '{print$2}'`
   CHECK2=`ls -alL $1 2>/dev/null | awk '{print$5}'`
   if [ "$CHECK1" == "$CHECK2" ]; then
	GETPKG="$CHECK_BROKEN_PKGS"
	PACKAGES_URL="$EXTRA_URL"
        checksum_extra $1
	pgp_check_remote "check_for_broken_extra()" "-e" "-ae" "$1"
   fi
   fi
   COUNTER=1
}

check_for_broken_sources()
{
   SOURCES_URL=`cat URL 2>/dev/null | awk '{ if(NR == '$2') print $1 }'`
   SHORTPKG=`echo $1 | sed s/'.tar.gz'//`
   SHORTPKG=`echo $SHORTPKG | sed s/'.gz'//`
   SHORTPKG=`echo $SHORTPKG | sed s/'.tar.bz2'//`
   SHORTPKG=`echo $SHORTPKG | sed s/'.bz2'//`
   MAX=`cat URL 2>/dev/null | wc -l`
   rm -f $1.tmp 2>/dev/null
   COUNT=0
   CHECKME=0
   COUNTER=$2
   COUNT=`ls $CDIR/*.*z* 2>/dev/null | wc -l | awk '{print$1}'`
   SHORTPKGTMP=`echo $1 | sed s/'.tar.gz'//`
   SHORTPKGTMP=`echo $SHORTPKGTMP | sed s/'.gz'//`
   SHORTPKGTMP=`echo $SHORTPKGTMP | sed s/'.tar.bz2'//`
   SHORTPKGTMP=`echo $SHORTPKGTMP | sed s/'.bz2'//`
   CHECK_BROKEN_PKGS=`cat CHECKSUMS.sources 2>/dev/null | grep "$4" | awk '{print$3}' | grep "/" | sed s/'.\/'// | grep "/$1"`
   if [ ! -z $SOURCES_URL ]; then
     if test $COUNT -ge 1
     then
        CHECK1=`cat CHECKSUMS.sources 2>/dev/null | grep "$CHECK_BROKEN_PKGS" | grep "/$1" | awk '{print$2}'`
        CHECK2=`ls -alL $1 2>/dev/null | awk '{print$5}'`
        CHECKFIX=`cat CHECKSUMS.sources 2>/dev/null | grep "/$1" | wc -l`
        if test $CHECKFIX -ne 0
        then
           if test $CHECK1 -ne $CHECK2
           then
                if [[ "$3" == "1" ]]; then
                        if [[ "$SWAPME" == "0" ]]; then
                                printf "\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b"
                                SWAPME=1
                        fi
                fi
                SIZEPKGTMP=`cat CHECKSUMS.sources 2>/dev/null | grep "$CHECK_BROKEN_PKGS" | grep "/$1" | awk '{print$2}'`
                SIZEPKG=`echo $SIZEPKGTMP / 1024 | bc`
                export AZERTYCHK=1
                MSG "check_for_broken_sources()" "[ $SOURCES_URL ]"
		if test $SIZEPKG -eq 0; then
                echo $QS "### Resuming broken Source $SHORTPKG ($SIZEPKGTMP B)... "
		else
		echo $QS "### Resuming broken Source $SHORTPKG ($SIZEPKG kB)... "
		fi
                if test `echo $SOURCES_URL | grep rsync | wc -l` -ge 1
                then
                                if [ ! -z $Q ]; then
					rsync_file "$SOURCES_URL" "$CHECK_BROKEN_PKGS"
                                        count_sources_size_rsync $1 "-a" "$CHECK_BROKEN_PKGS"
                                else
					rsync_file_s "$SOURCES_URL" "$CHECK_BROKEN_PKGS"
					touch_it "$1"
                                fi
                else
                                if [ ! -z $Q ]; then
					wget_file "$SOURCES_URL" "$CHECK_BROKEN_PKGS"
                                        count_sources_size $1 "-a" "$CHECK_BROKEN_PKGS"
                                else
					wget_file_s "$SOURCES_URL" "$CHECK_BROKEN_PKGS"
					touch_it "$1"
                                fi
                fi              
                if [ -f $1.tmp ]; then
                        CHECK1=`cat CHECKSUMS.sources 2>/dev/null | grep "$CHECK_BROKEN_PKGS" | grep "/$1" | awk '{print$2}'`
                        CHECK2=`ls -alL $1 2>/dev/null | awk '{print$5}'`
                        if [ "$CHECK1" == "$CHECK2" ]; then
                                FPKGSW=1
                                FPKGTSIZE=`echo "$FPKGTSIZE + $SIZEPKG" | bc`
                                FPKGC=`echo "$FPKGC + 1" | bc`
                                if [ ! -z $Q ]; then
                                        echo " DONE!"
				else
					echo
                                fi
				if test $SIZEPKG -eq 0; then
				logme "check_for_broken_sources()" "### Resuming broken Source $SHORTPKG ($SIZEPKGTMP B)... DONE!"
				else
				logme "check_for_broken_sources()" "### Resuming broken Source $SHORTPKG ($SIZEPKG kB)... DONE!"	
				fi
									BSWAP=0
                                                                        if test `echo $SOURCES_URL | grep rsync | wc -l` -ge 1
                                                                        then
BSPATH=`cat $CDIR/CHECKSUMS.sources 2>/dev/null | grep "/$1" | sed s/'$1'// | awk '{print$3}'`
BSLIST=`cat $CDIR/CHECKSUMS.sources 2>/dev/null | grep $BSPATH | grep -i build | awk '{print$3}' | sed s/.//`
BUILDSLIST="$BSLIST"
                                                for b in $BUILDSLIST
                                                do
                                                  if test $BSWAP -eq 0; then
                                                    echo -n "### Fetching Build Script for $SHORTPKG... "
                                                    BSWAP=1
                                                  fi
                                                  rsync_file_buildscript "$SOURCES_URL" "$b"
                                                  BFILENAME=`echo $b | sed -e "s/.*\///g"`
                                                  mv $CDIR/$BFILENAME $CDIR/sources/$SHORTPKG-$BFILENAME 2>/dev/null
                                                done
											    if test $BSWAP -eq 1; then
                                                                                            	echo "DONE!"
												logme "check_for_broken_sources()" "### Fetching Build Script for $SHORTPKG... DONE!"
											    fi
                                                                        else
BSPATH=`cat $CDIR/CHECKSUMS.sources 2>/dev/null | grep "/$1" | sed s/'$1'// | awk '{print$3}'`
BSLIST=`cat $CDIR/CHECKSUMS.sources 2>/dev/null | grep $BSPATH | grep -i build | awk '{print$3}' | sed s/.//`
BUILDSLIST="$BSLIST"
                                                for b in $BUILDSLIST
                                                do
                                                  if test $BSWAP -eq 0; then
                                                    echo -n "### Fetching Build Script for $SHORTPKG... "
                                                    BSWAP=1
                                                  fi
                                                  wget_file_buildscript "$SOURCES_URL" "$b"
                                                  BFILENAME=`echo $b | sed -e "s/.*\///g"`
                                                  mv $CDIR/$BFILENAME $CDIR/sources/$SHORTPKG-$BFILENAME 2>/dev/null
                                                done
											    if test $BSWAP -eq 1; then
                                                                                            	echo "DONE!"
												logme "check_for_broken_sources()" "### Fetching Build Script for $SHORTPKG... DONE!"
											    fi
                                                                        fi
                                touch $1.tmp
				checksum_source $1 "$4"
				mv $1 $CDIR/sources/ 2>/dev/null
				CHECKME=1
                        else
                                if [ ! -z $Q ]; then
                                        echo " FAILED!"
                                fi
				if test $SIZEPKG -eq 0; then
                                logme "check_for_broken_sources()" "### Resuming broken Source $SHORTPKG ($SIZEPKGTMP B)... FAILED!"
				else
				logme "check_for_broken_sources()" "### Resuming broken Source $SHORTPKG ($SIZEPKG kB)... FAILED!"
				fi
                                rm -f $1.tmp
                                RECORDS=`cat URL 2>/dev/null | wc -l`
                                  COUNTER=`expr $COUNTER + 1`
                                  if test $COUNTER -ne `expr $RECORDS + 1`
                                  then
                                    check_for_broken_sources $1 $COUNTER "" "$4"
                                  fi
                        fi
                else
                        if [ ! -z $Q ]; then    
                                echo " FAILED!"
                        fi
			if test $SIZEPKG -eq 0; then
                        logme "check_for_broken_sources()" "### Resuming broken Source $SHORTPKG ($SIZEPKGTMP B)... FAILED!"
			else
			logme "check_for_broken_sources()" "### Resuming broken Source $SHORTPKG ($SIZEPKG kB)... FAILED!"
			fi
                        rm -f $1.tmp
                        RECORDS=`cat URL 2>/dev/null | wc -l`
                              COUNTER=`expr $COUNTER + 1`
                              if test $COUNTER -ne `expr $RECORDS + 1`
                              then
                                    check_for_broken_sources $1 $COUNTER "" "$4"
                              fi
                fi
           else
                touch $1.tmp
           fi
        fi
     fi
   fi
   if [[ "$CHECKME" == "1" ]];then
   CHECK1=`cat CHECKSUMS.sources 2>/dev/null | grep "$CHECK_BROKEN_PKGS" | grep "/$1" | awk '{print$2}'`
   CHECK2=`ls -alL $1 2>/dev/null | awk '{ print $5 }'`
   if [ "$CHECK1" == "$CHECK2" ]; then
        checksum_source $1 "$CHECK_BROKEN_PKGS" 
   fi
   fi
   COUNTER=1
}

res_local_pat()
{
   SWAPME=0
   if test `cat /etc/swaret.conf | grep -v "#" | grep "^ROOT=" | grep "file:" | wc -l` -ge 1; then
    ROOTS=`cat /etc/swaret.conf | grep -v "#" | grep "^ROOT=" | grep "file:" | cut -f2 -d'=' | sed s/'file:'//`
    for R in $ROOTS
    do
     SHORTPKG=`echo $1 | sed s/'.tgz'//`
     rm -f $1.tmp 2>/dev/null
     SIZEPKGTMP=`cat CHECKSUMS 2>/dev/null | grep "/$1" | awk '{print$2}'`
     SIZEPKG=`echo $SIZEPKGTMP / 1024 | bc`
     PKGPATH=`cat CHECKSUMS 2>/dev/null | grep "/$1" | awk '{print$3}' | sed s/'.'//`
     SIZEPKGL=`ls -alL $CDIR/$1 2>/dev/null | awk '{print$5}'`
     if test $SIZEPKGL -ne $SIZEPKGTMP; then
                if [[ "$3" == "1" ]]; then
                        if [[ "$SWAPME" == "0" ]]; then
                                printf "\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b"
                                SWAPME=1
                        fi
                fi
		AZERTYCHK=1
     MSG "res_local_pat()" "[ file:$R ]"
     echo -n "### Resuming broken Patch $SHORTPKG ($SIZEPKG kB)... " 
     copy_file "$R" "$PKGPATH"
     if [ ! -f $CDIR/$1 ]; then
        echo "FAILED!"
	logme "res_local_pat()" "### Resuming broken Patch $SHORTPKG ($SIZEPKG kB)... FAILED!"
     else
        if [ -f $CDIR/$1 ]; then
          SIZEPKGTMP=`cat CHECKSUMS 2>/dev/null | grep "/$1" | awk '{print$2}'`
          SIZEPKGL=`ls -alL $CDIR/$1 2>/dev/null | awk '{print$5}'`
          if test $SIZEPKGL -eq $SIZEPKGTMP; then
                FPKGSW=1
                FPKGTSIZE=`echo "$FPKGTSIZE + $SIZEPKG" | bc`
                FPKGC=`echo "$FPKGC + 1" | bc`
                echo "DONE!"
                logme "res_local_pat()" "### Resuming broken Patch $SHORTPKG ($SIZEPKG kB)... DONE!"
		PACKAGE="$PKGPATH"
		RR="$R"
                checksum_patch $1
        	pgp_check_local "res_local_pat()" "-p" "-ap" "$1"
                break
	  else
		echo "FAILED!"
		logme "res_local_pat()" "### Resuming broken Patch $SHORTPKG ($SIZEPKG kB)... FAILED!"
          fi
	else
	  	echo "FAILED!"
		logme "res_local_pat()" "### Resuming broken Patch $SHORTPKG ($SIZEPKG kB)... FAILED!"
        fi
     fi
     fi
    done
   fi
}

res_local_ext()
{
   SWAPME=0
   if test `cat /etc/swaret.conf | grep -v "#" | grep "^ROOT=" | grep "file:" | wc -l` -ge 1; then
    ROOTS=`cat /etc/swaret.conf | grep -v "#" | grep "^ROOT=" | grep "file:" | cut -f2 -d'=' | sed s/'file:'//`
    for R in $ROOTS
    do
     SHORTPKG=`echo $1 | sed s/'.tgz'//`
     rm -f $1.tmp 2>/dev/null
     SIZEPKGTMP=`cat CHECKSUMS 2>/dev/null | grep "/$1" | awk '{print$2}'`
     SIZEPKG=`echo $SIZEPKGTMP / 1024 | bc`
     PKGPATH=`cat CHECKSUMS 2>/dev/null | grep "/$1" | awk '{print$3}' | sed s/'.'//`
     SIZEPKGL=`ls -alL $CDIR/$1 2>/dev/null | awk '{print$5}'`
     if test $SIZEPKGL -ne $SIZEPKGTMP; then
                if [[ "$3" == "1" ]]; then
                        if [[ "$SWAPME" == "0" ]]; then
                                printf "\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b"
                                SWAPME=1
                        fi
                fi
                AZERTYCHK=1
     MSG "res_local_ext()" "[ file:$R ]"
     echo -n "### Resuming broken Extra Package $SHORTPKG ($SIZEPKG kB)... "
     copy_file "$R" "$PKGPATH"
     if [ ! -f $CDIR/$1 ]; then
        echo "FAILED!"
        logme "res_local_ext()" "### Resuming broken Extra Package $SHORTPKG ($SIZEPKG kB)... FAILED!"
     else
        if [ -f $CDIR/$1 ]; then
          SIZEPKGTMP=`cat CHECKSUMS 2>/dev/null | grep "/$1" | awk '{print$2}'`
          SIZEPKGL=`ls -alL $CDIR/$1 2>/dev/null | awk '{print$5}'`
          if test $SIZEPKGL -eq $SIZEPKGTMP; then
                FPKGSW=1
                FPKGTSIZE=`echo "$FPKGTSIZE + $SIZEPKG" | bc`
                FPKGC=`echo "$FPKGC + 1" | bc`
                echo "DONE!"
                logme "res_local_ext()" "### Resuming broken Extra Package $SHORTPKG ($SIZEPKG kB)... DONE!"
		PACKAGE="$PKGPATH"
		RR="$R"
                checksum_extra $1
		pgp_check_local "res_local_ext()" "-e" "-ae" "$1"
                break
	  else
		echo "FAILED!"
		logme "res_local_ext()" "### Resuming broken Extra Package $SHORTPKG ($SIZEPKG kB)... FAILED!"
          fi
	else
		echo "FAILED!"
		logme "res_local_ext()" "### Resuming broken Extra Package $SHORTPKG ($SIZEPKG kB)... FAILED!"
        fi
     fi
     fi
    done
   fi
}

res_local_pac() 
{
   SWAPME=0
   if test `cat /etc/swaret.conf | grep -v "#" | grep "^ROOT=" | grep "file:" | wc -l` -ge 1; then
    ROOTS=`cat /etc/swaret.conf | grep -v "#" | grep "^ROOT=" | grep "file:" | cut -f2 -d'=' | sed s/'file:'//`
    for R in $ROOTS
    do
     SHORTPKG=`echo $1 | sed s/'.tgz'//`
     rm -f $1.tmp 2>/dev/null
     SIZEPKGTMP=`cat CHECKSUMS 2>/dev/null | grep "/$1" | awk '{print$2}'`
     SIZEPKG=`echo $SIZEPKGTMP / 1024 | bc`
     PKGPATH=`cat CHECKSUMS 2>/dev/null | grep "/$1" | awk '{print$3}' | sed s/'.'//`
     SIZEPKGL=`ls -alL $CDIR/$1 2>/dev/null | awk '{print$5}'`
     if test $SIZEPKGL -ne $SIZEPKGTMP; then
                if [[ "$3" == "1" ]]; then
                        if [[ "$SWAPME" == "0" ]]; then
                                printf "\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b"
                                SWAPME=1
                        fi
                fi
                AZERTYCHK=1
     MSG "res_local_pac()" "[ file:$R ]"
     echo -n "### Resuming broken Package $SHORTPKG ($SIZEPKG kB)... "
     copy_file "$R" "$PKGPATH"
     if [ ! -f $CDIR/$1 ]; then
	echo "FAILED!"
        logme "res_local_pac()" "### Resuming broken Package $SHORTPKG ($SIZEPKG kB)... FAILED!"
     else
        if [ -f $CDIR/$1 ]; then
	  SIZEPKGTMP=`cat CHECKSUMS 2>/dev/null | grep "/$1" | awk '{print$2}'`
	  SIZEPKGL=`ls -alL $CDIR/$1 2>/dev/null | awk '{print$5}'`
	  if test $SIZEPKGL -eq $SIZEPKGTMP; then
                FPKGSW=1
                FPKGTSIZE=`echo "$FPKGTSIZE + $SIZEPKG" | bc`
                FPKGC=`echo "$FPKGC + 1" | bc`
          	echo "DONE!"
          	logme "res_local_pac()" "### Resuming broken Package $SHORTPKG ($SIZEPKG kB)... DONE!"
		PACKAGE="$PKGPATH"
		RR="$R"
		checksum_package $1
		pgp_check_local "res_local_pac()" "-a" "-a" "$1"
		break
	  else
		echo "FAILED!"
		logme "res_local_pac()" "### Resuming broken Package $SHORTPKG ($SIZEPKG kB)... FAILED!"
	  fi
	else
		echo "FAILED!"
		logme "res_local_pac()" "### Resuming broken Package $SHORTPKG ($SIZEPKG kB)... FAILED!"
        fi
     fi
     fi
    done
   fi
}

res_local_sources()
{
   SWAPME=0
   if test `cat /etc/swaret.conf | grep -v "#" | grep "^ROOT=" | grep "file:" | wc -l` -ge 1; then
    ROOTS=`cat /etc/swaret.conf | grep -v "#" | grep "^ROOT=" | grep "file:" | cut -f2 -d'=' | sed s/'file:'//`
    for R in $ROOTS
    do
     SHORTPKG=`echo $1 | sed s/'.tar.gz'//`
     SHORTPKG=`echo $SHORTPKG | sed s/'.gz'//`
     SHORTPKG=`echo $SHORTPKG | sed s/'.tar.bz2'//`
     SHORTPKG=`echo $SHORTPKG | sed s/'.bz2'//`
     rm -f $1.tmp 2>/dev/null
     SIZEPKGTMP=`cat CHECKSUMS.sources 2>/dev/null | grep "$2" | grep "/$1" | awk '{print$2}'`
     SIZEPKG=`echo $SIZEPKGTMP / 1024 | bc`
     PKGPATH=`cat CHECKSUMS 2>/dev/null | grep "$2" | grep "/$1" | awk '{print$3}' | sed s/'.'//`
     SIZEPKGL=`ls -alL $CDIR/$1 2>/dev/null | awk '{print$5}'`
     if test $SIZEPKGL -ne $SIZEPKGTMP; then
                if [[ "$3" == "1" ]]; then
                        if [[ "$SWAPME" == "0" ]]; then
                                printf "\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b"
                                SWAPME=1
                        fi
                fi
                AZERTYCHK=1
     MSG "res_local_sources()" "[ file:$R ]"
     if test $SIZEPKG -eq 0; then
        echo -n "### Resuming broken Source $SHORTPKG ($SIZEPKGTMP B)... "
     else
        echo -n "### Resuming broken Source $SHORTPKG ($SIZEPKG kB)... "
     fi
     copy_file "$R" "$PKGPATH"
     if [ ! -f $CDIR/$1 ]; then
	echo "FAILED!"
        if test $SIZEPKG -eq 0; then
                logme "res_local_sources()" "### Resuming broken Source $SHORTPKG ($SIZEPKGTMP B)... FAILED!"
        else
                logme "res_local_sources()" "### Resuming broken Source $SHORTPKG ($SIZEPKG kB)... FAILED!"
        fi
     else
        if [ -f $CDIR/$1 ]; then
          SIZEPKGTMP=`cat CHECKSUMS 2>/dev/null | grep "/$1" | awk '{print$2}'`
          SIZEPKGL=`ls -alL $CDIR/$1 2>/dev/null | awk '{print$5}'`
          if test $SIZEPKGL -eq $SIZEPKGTMP; then
                FPKGSW=1
                FPKGTSIZE=`echo "$FPKGTSIZE + $SIZEPKGL" | bc`
                FPKGC=`echo "$FPKGC + 1" | bc`
                echo "DONE!"
          	if test $SIZEPKG -eq 0; then
                	logme "res_local_sources()" "### Resuming broken Source $SHORTPKG ($SIZEPKGTMP B)... DONE!"
          	else
                	logme "res_local_sources()" "### Resuming broken Source $SHORTPKG ($SIZEPKG kB)... DONE!"
          	fi
											    BSWAP=0
BSPATH=`cat $CDIR/CHECKSUMS.sources 2>/dev/null | grep "/$1" | sed s/$1// | awk '{print$3}'`
BSLIST=`cat $CDIR/CHECKSUMS.sources 2>/dev/null | grep $BSPATH | grep -i build | awk '{print$3}' | sed s/.//`
BUILDSLIST="$BSLIST"
                                                for b in $BUILDSLIST
                                                do
                                                  if test $BSWAP -eq 0; then
                                                    echo -n "### Copying Build Script for $SHORTPKG... "
                                                    BSWAP=1
                                                  fi
                                                  copy_file "$R" "$b"
                                                  BFILENAME=`echo $b | sed -e "s/.*\///g"`
                                                  mv $CDIR/$BFILENAME $CDIR/sources/$SHORTPKG-$BFILENAME 2>/dev/null
                                                done
											    if test $BSWAP -eq 1; then
                                                                                            	echo "DONE!"
												logme "res_local_sources()" "### Copying Build Script for $SHORTPKG... DONE!"
											    fi
	    PACKAGE="$PKGPATH"
	    checksum_source $1 "$PKGPATH"
            mv $1 $CDIR/sources/ 2>/dev/null
            break
	  else
		echo "FAILED!"
        	if test $SIZEPKG -eq 0; then
                	logme "res_local_sources()" "### Resuming broken Source $SHORTPKG ($SIZEPKGTMP B)... FAILED!"
        	else
                	logme "res_local_sources()" "### Resuming broken Source $SHORTPKG ($SIZEPKG kB)... FAILED!"
        	fi
	  fi
	else
		echo "FAILED!"
                if test $SIZEPKG -eq 0; then
                        logme "res_local_sources()" "### Resuming broken Source $SHORTPKG ($SIZEPKGTMP B)... FAILED!"
                else
                        logme "res_local_sources()" "### Resuming broken Source $SHORTPKG ($SIZEPKG kB)... FAILED!"
                fi
        fi
     fi
     fi
    done
   fi
}

URL()
{
	rm -f URL 2>/dev/null
	if [ ! -f /etc/swaret.conf ]; then
                MSG "URL()" "swaret Config File (/etc/swaret.conf) not found!"
		MSG "URL()" "Copy /usr/doc/swaret-$SVERSION/swaret.conf.new to"
		MSGERR "URL()" "/etc/swaret.conf, edit and start swaret."
	fi
	X=0
	NROOT=0
	CHKROOT=0
	CHECK=`cat /etc/swaret.conf 2>/dev/null | grep "^ROOT=" | grep -v "#" | wc -l`
        DCHECK=`cat /etc/swaret.conf 2>/dev/null | grep "^DEP_ROOT=" | grep -v "#" | wc -l`
	ROOTS=`cat /etc/swaret.conf 2>/dev/null | grep "^ROOT=" | sed s/'"'//\g | grep -v "#"`
	DROOTS=`cat /etc/swaret.conf 2>/dev/null | grep "^DEP_ROOT=" | sed s/'"'//\g | grep -v "#"`
	if test `cat /etc/swaret.conf 2>/dev/null | grep "^ROOT=" | grep -v "#" | grep "http:" | wc -l` -ge 1
	then
		check_wget
	fi
	if test `cat /etc/swaret.conf 2>/dev/null | grep "^ROOT=" | grep -v "#" | grep "ftp:" | wc -l` -ge 1
	then
		check_wget
	fi
	if test `cat /etc/swaret.conf 2>/dev/null | grep "^ROOT=" | grep -v "#" | grep "rsync:" | wc -l` -ge 1
	then
		check_rsync
	fi
        if test $DCHECK -eq 0
        then
	  if [[ "$VDEPENDENCY" == "1" ]]; then
		HEADER
                MSGERR "URL()" "Please fix "\'DEP_ROOT\'" in /etc/swaret.conf!"
	  fi
        fi
	if test $CHECK -eq 0
	then
		HEADER
        	MSGERR "URL()" "Please, fix "\'ROOT\'" in /etc/swaret.conf!"
	else
		HC=0
		for i in $ROOTS
		do
			if [[ ! "$i" = "ROOT=" ]]; then
				CHKROOT=`echo $i | cut -f2 -d'=' | grep ftp: | wc -l`
				if test $CHKROOT -eq 1
				then
					X=1
                                        echo $i | cut -f2 -d'=' >> URL 2>/dev/null
					NROOT=`expr $NROOT + 1`
				fi
				CHKROOT=`echo $i | cut -f2 -d'=' | grep http: | wc -l`
				if test $CHKROOT -eq 1
				then
					X=1
                                        echo $i | cut -f2 -d'=' >> URL 2>/dev/null
					NROOT=`expr $NROOT + 1`
				fi
				CHKROOT=`echo $i | cut -f2 -d'=' | grep rsync: | wc -l`
				if test $CHKROOT -eq 1
				then
					X=1
					echo $i | cut -f2 -d'=' >> URL 2>/dev/null
					NROOT=`expr $NROOT + 1`
				fi
                                CHKROOT=`echo $i | cut -f2 -d'=' | grep "file:" | wc -l`
                                if test $CHKROOT -ge 1
                                then
					HC=`cat /etc/swaret.conf | grep -v "#" | grep "^ROOT=" | grep http: | wc -l`
					if test $HC -ge 1
					then
						lf_errr
					fi
                                        HC=`cat /etc/swaret.conf | grep -v "#" | grep "^ROOT=" | grep ftp: | wc -l`
                                        if test $HC -ge 1
                                        then
						lf_errr
                                        fi
                                        HC=`cat /etc/swaret.conf | grep -v "#" | grep "^ROOT=" | grep rsync: | wc -l`
                                        if test $HC -ge 1
                                        then
						lf_errr
                                        fi
					CPURLC=`cat /etc/swaret.conf | grep -v "#" | grep "^ROOT=" | grep "file:" | wc -l`
					if test $CPURLC -ge 1
					then
                                        	echo $i | sed s/'file:'// | cut -f2 -d'=' >> URL 2>/dev/null
						X=1
					else
						HEADER
                                        	MSGERR "URL()" "Please, fix "\'ROOT\'" in /etc/swaret.conf!"
					fi
                                fi
				if test $X -ne 1
				then
					HEADER
					MSGERR "URL()" "Please, fix "\'ROOT\'" in /etc/swaret.conf!"
				fi
			fi
			X=0
		done
		HC=0
		if [[ "$VDEPENDENCY" == "1" ]]; then
		for i in $DROOTS
		do
			CHKROOT=`echo $i | cut -f2 -d'=' | grep "file:" | wc -l`
                        if test $CHKROOT -ge 1; then
					HC=`cat /etc/swaret.conf | grep -v "#" | grep "^DEP_ROOT=" | grep http: | wc -l`
			                if test $HC -ge 1
                                        then
                                                lfd_errr
                                        fi
                                        HC=`cat /etc/swaret.conf | grep -v "#" | grep "^DEP_ROOT=" | grep ftp: | wc -l`
                                        if test $HC -ge 1
                                        then
                                                lfd_errr
                                        fi
                                        HC=`cat /etc/swaret.conf | grep -v "#" | grep "^DEP_ROOT=" | grep rsync: | wc -l`
                                        if test $HC -ge 1
                                        then
                                                lfd_errr
                                        fi
			fi
		done
		fi
	fi
	if test `cat /etc/swaret.conf 2>/dev/null | grep "RSYNC_PROXY=" | grep -v "#" | wc -l` -eq 1
	then
		RPROXY=`cat /etc/swaret.conf 2>/dev/null | grep "RSYNC_PROXY=" | grep -v "#" | cut -f2 -d'='`
		RPASSWORD=`cat /etc/swaret.conf 2>/dev/null | grep "RSYNC_PASSWORD=" | grep -v "#" | cut -f2 -d'='`
		RSYNC_PROXY=$RPROXY
		RSYNC_PASSWORD=$RPASSWORD
	fi
	if test `cat /etc/swaret.conf 2>/dev/null | grep "RSYNC_PROXY=" | grep -v "#" | wc -l` -gt 1
	then
		HEADER
		MSGERR "URL()" "Please, fix "\'RSYNC_PROXY\'" in /etc/swaret.conf!"
	fi
	if test `cat /etc/swaret.conf 2>/dev/null | grep "RSYNC_PASSWORD=" | grep -v "#" | wc -l` -gt 1
	then
		HEADER
		MSGERR "URL()" "Please, fix "\'RSYNC_PASSWORD\'" in /etc/swaret.conf!"
	fi
	export NROOT RSYNC_PROXY RSYNC_PASSWORD
	cat URL 2>/dev/null | uniq > URL.tmp 2>/dev/null
	mv URL.tmp URL 2>/dev/null
}

remove_incomplete()
{
        if [[ "$VPACKAGES" = "1" ]]; then
		echo -n "=> Verifying Packages List Files... "
                if [ -f $CDIR/CHECKSUMS ]; then
                        for i in `cat $CDIR/CHECKSUMS.md5 2>/dev/null | awk '{print$2}'`
                        do
                                if test `cat $CDIR/CHECKSUMS 2>/dev/null | grep "$i" | wc -l` -eq 0; then
                                        cat $CDIR/CHECKSUMS.md5 2>/dev/null | grep -v "$i" > $CDIR/CHECKSUMS.md5.tmp 2>/dev/null
                                        mv $CDIR/CHECKSUMS.md5.tmp $CDIR/CHECKSUMS.md5 2>/dev/null
                                fi
                        done
                fi
		echo "DONE!"
        fi
        if [[ "$VPATCHES" = "1" ]]; then
		echo -n "=> Verifying Patches List Files... "
                if [ -f $CDIR/CHECKSUMS.patches ]; then 
                        for i in `cat $CDIR/CHECKSUMS.md5.patches 2>/dev/null | awk '{print$2}'`
                        do
                                if test `cat $CDIR/CHECKSUMS.patches 2>/dev/null | grep "$i" | wc -l` -eq 0; then
                                        cat $CDIR/CHECKSUMS.md5.patches 2>/dev/null | grep -v "$i" > $CDIR/CHECKSUMS.md5.patches.tmp 2>/dev/null
                                        mv $CDIR/CHECKSUMS.md5.patches.tmp $CDIR/CHECKSUMS.md5.patches 2>/dev/null
                                fi
                        done
                fi
		echo "DONE!"
        fi
        if [[ "$VEXTRA" = "1" ]]; then
		echo -n "=> Verifying Extra Packages List Files... "
                if [ -f $CDIR/CHECKSUMS.extra ]; then
                        for i in `cat $CDIR/CHECKSUMS.md5.extra 2>/dev/null | awk '{print$2}'`
                        do
                                if test `cat $CDIR/CHECKSUMS.extra 2>/dev/null | grep "$i" | wc -l` -eq 0; then
                                        cat $CDIR/CHECKSUMS.md5.extra 2>/dev/null | grep -v "$i" > $CDIR/CHECKSUMS.md5.extra.tmp 2>/dev/null
                                        mv $CDIR/CHECKSUMS.md5.extra.tmp $CDIR/CHECKSUMS.md5.extra 2>/dev/null 
                                fi
                        done
                fi
		echo "DONE!"
        fi
        if [[ "$SOURCES" = "1" ]]; then
                echo -n "=> Verifying Sources List Files... "
                if [ -f $CDIR/CHECKSUMS.sources ]; then
                        for i in `cat $CDIR/CHECKSUMS.md5.sources 2>/dev/null | awk '{print$2}'`
                        do
                                if test `cat $CDIR/CHECKSUMS.sources 2>/dev/null | grep "$i" | wc -l` -eq 0; then
                                        cat $CDIR/CHECKSUMS.md5.sources 2>/dev/null | grep -v "$i" > $CDIR/CHECKSUMS.md5.sources.tmp 2>/dev/null
                                        mv $CDIR/CHECKSUMS.md5.sources.tmp $CDIR/CHECKSUMS.md5.sources 2>/dev/null
                                fi
                        done
                fi
                echo "DONE!"
        fi
	copy_to_cache
}

update_lists()
{
	rm -f $CDIR/.cache/* 2>/dev/null
	rm -f $CDIR/*CHECKSUMS* 2>/dev/null

	URL

	if test $1 -eq `expr $NROOT + 1`
	then
		break
	fi
	
	BSWAP=0
	SIZE=0
	COUNTER=0
        PACKAGES_URL=`cat URL | awk '{ if(NR == '$1') print $1 }' | cut -f2 -d'='`
	export PACKAGES_URL
	if [ ! -z $PACKAGES_URL ]; then
		CHECKSUMS_URL="$PACKAGES_URL/FILELIST.TXT"
		CHECKSUMS_MD5_URL="$PACKAGES_URL/CHECKSUMS.md5"
		export CHECKSUMS_URL CHECKSUMS_MD5_URL
	
		MSG "update_lists()" "[ $PACKAGES_URL ]"
		echo -n "### Fetching Slackware Linux ($VERSION) CHECKSUMS List File... "
		if test `echo $PACKAGES_URL | grep rsync | wc -l` -ge 1
		then
			rsync --timeout=$TIMEOUT $Q $CHECKSUMS_MD5_URL CHECKSUMS.md5 2>/dev/null &
			progress_rsync CHECKSUMS.md5
			if [ -f CHECKSUMS.md5.tmp ]; then
				echo "DONE!"
				logme "update_lists()" "### Fetching Slackware Linux ($VERSION) CHECKSUMS List File... DONE!"
			else
				rm -f CHECKSUMS.md5* 2>/dev/null
				echo "FAILED!"
				BSWAP=1
				logme "update_lists()" "### Fetching Slackware Linux ($VERSION) CHECKSUMS List File... FAILED!"
			fi
		else
			wget $PF -t $RETRIES -T $TIMEOUT $Q $CHECKSUMS_MD5_URL 2>/dev/null &
			progress CHECKSUMS.md5
			if [ -f CHECKSUMS.md5.tmp ]; then
				echo "DONE!"
				logme "update_lists()" "### Fetching Slackware Linux ($VERSION) CHECKSUMS List File... DONE!"
			else
				rm -f CHECKSUMS.md5* 2>/dev/null
				echo "FAILED!"
				BSWAP=1
				logme "update_lists()" "### Fetching Slackware Linux ($VERSION) CHECKSUMS List File... FAILED!"
			fi
		fi
 		echo -n "### Fetching Slackware Linux ($VERSION) FILELIST List File... "
 		if test `echo $PACKAGES_URL | grep rsync | wc -l` -ge 1
		then
			rsync --timeout=$TIMEOUT $Q $CHECKSUMS_URL CHECKSUMS 2>/dev/null &
			progress_rsync CHECKSUMS 
			if [ -f CHECKSUMS.tmp ]; then
				echo "DONE!"
				logme "update_lists()" "### Fetching Slackware Linux ($VERSION) FILELIST List File... DONE!"
			else
				rm -f CHECKSUMS* 2>/dev/null
			        echo "FAILED!"
				BSWAP=1
				logme "update_lists()" "### Fetching Slackware Linux ($VERSION) FILELIST List File... FAILED!"
			fi
		else
			wget $PF -t $RETRIES -T $TIMEOUT $Q $CHECKSUMS_URL 2>/dev/null &
                        progress FILELIST.TXT
                        if [ -f FILELIST.TXT.tmp ]; then
				mv FILELIST.TXT CHECKSUMS 2>/dev/null
				mv FILELIST.TXT.tmp CHECKSUMS.tmp 2>/dev/null
				echo "DONE!"
				logme "update_lists()" "### Fetching Slackware Linux ($VERSION) FILELIST List File... DONE!"
                        else
                                rm -f CHECKSUMS* 2>/dev/null
				rm -f FILELIST* 2>/dev/null
                                echo "FAILED!"
				BSWAP=1
				logme "update_lists()" "### Fetching Slackware Linux ($VERSION) FILELIST List File... FAILED!"
                        fi
		fi

		if [[ "$SOURCES" == "1" ]]; then
			cp $CDIR/CHECKSUMS $CDIR/CHECKSUMS.sources 2>/dev/null
			cp $CDIR/CHECKSUMS.md5 $CDIR/CHECKSUMS.md5.sources 2>/dev/null
		fi

                if [[ "$VPATCHES" == "1" ]]; then
		 if [ ! -f CHECKSUMS.md5 ]; then
			MSG "update_lists()" "=> Creating CHECKSUMS List File for Patches... FAILED!"
		 else
			MSG "update_lists()" "=> Creating CHECKSUMS List File for Patches... DONE!"
             		cat CHECKSUMS.md5 | grep "patches/" | grep tgz$ > CHECKSUMS.md5.patches.pmt
             		mv CHECKSUMS.md5.patches.pmt CHECKSUMS.md5.patches 2>/dev/null
		 fi
		fi
                if [[ "$VPATCHES" == "1" ]]; then
		 if [ ! -f CHECKSUMS ]; then
			MSG "update_lists()" "=> Creating FILELIST List File for Patches... FAILED!"
		 else
                        MSG "update_lists()" "=> Creating FILELIST List File for Patches... DONE!"
                        cat CHECKSUMS | grep "patches/" | grep tgz$ | awk '{ print "x " $5 " " $9 }' > CHECKSUMS.patches.pmt 2>/dev/null
                        mv CHECKSUMS.patches.pmt CHECKSUMS.patches 2>/dev/null
		  fi
                fi
                if [[ "$VEXTRA" == "1" ]]; then
		 if [ ! -f CHECKSUMS.md5 ]; then
			MSG "update_lists()" "=> Creating CHECKSUMS List File for Extra Packages... FAILED!"
		 else
                	MSG "update_lists()" "=> Creating CHECKSUMS List File for Extra Packages... DONE!"
                	cat CHECKSUMS.md5 | grep "extra/" | grep tgz$ > CHECKSUMS.md5.extra.pmt 2>/dev/null
                	mv CHECKSUMS.md5.extra.pmt CHECKSUMS.md5.extra 2>/dev/null
		 fi
		fi
                if [[ "$VEXTRA" == "1" ]]; then
		 if [ ! -f CHECKSUMS ]; then
		 	MSG "update_lists()" "=> Creating FILELIST List File for Extra Packages... FAILED!"
		 else
                        MSG "update_lists()" "=> Creating FILELIST List File for Extra Packages... DONE!"
                        cat CHECKSUMS | grep "extra/" | grep tgz$ | awk '{ print "x " $5 " " $9 }' > CHECKSUMS.extra.pmt 2>/dev/null
                        mv CHECKSUMS.extra.pmt CHECKSUMS.extra 2>/dev/null
		 fi
                fi
                if [[ "$VPACKAGES" == "1" ]]; then
		 if [ ! -f CHECKSUMS.md5 ]; then
		 	MSG "update_lists()" "=> Creating CHECKSUMS List File for Packages... FAILED!"
		 else
               		MSG "update_lists()" "=> Creating CHECKSUMS List File for Packages... DONE!"
               		cat CHECKSUMS.md5 | grep "slackware/" | grep tgz$ > CHECKSUMS.md5.pmt 2>/dev/null
               		mv CHECKSUMS.md5.pmt CHECKSUMS.md5 2>/dev/null
		 fi
		fi
		if [[ "$VPACKAGES" == "1" ]]; then
		 if [ ! -f CHECKSUMS ]; then
		 	MSG "update_lists()" "=> Creating FILELIST List File for Packages... FAILED!"
		 else
			MSG "update_lists()" "=> Creating FILELIST List File for Packages... DONE!"
			cat CHECKSUMS | grep "slackware/" | grep tgz$ | awk '{ print "x " $5 " " $9 }' > CHECKSUMS.pmt 2>/dev/null
			mv CHECKSUMS.pmt CHECKSUMS 2>/dev/null
		 fi
		fi
                if [[ "$SOURCES" == "1" ]]; then
                 if [ ! -f CHECKSUMS.md5.sources ]; then
                        MSG "update_lists()" "=> Creating CHECKSUMS List File for Sources... FAILED!"
                 else
                        MSG "update_lists()" "=> Creating CHECKSUMS List File for Sources... DONE!"
			cat CHECKSUMS.md5.sources | grep -v "lrwx" | grep -w "./patches/source" | grep gz$ >> CHECKSUMS.md5.sources.pmt
			cat CHECKSUMS.md5.sources | grep -v "lrwx" | grep -w "./patches/source" | grep bz2$ >> CHECKSUMS.md5.sources.pmt
			cat CHECKSUMS.md5.sources | grep -v "lrwx" | grep -w "./extra/source" | grep gz$ >> CHECKSUMS.md5.sources.pmt
			cat CHECKSUMS.md5.sources | grep -v "lrwx" | grep -w "./extra/source" | grep bz2$ >> CHECKSUMS.md5.sources.pmt
			cat CHECKSUMS.md5.sources | grep -v "lrwx" | grep -w "./source" | grep gz$ >> CHECKSUMS.md5.sources.pmt	
			cat CHECKSUMS.md5.sources | grep -v "lrwx" | grep -w "./source" | grep bz2$ >> CHECKSUMS.md5.sources.pmt
			cat CHECKSUMS.md5.sources.pmt 2>/dev/null | grep - > CHECKSUMS.md5.sources.tmp
			cat CHECKSUMS.md5.sources.pmt 2>/dev/null | grep _ >> CHECKSUMS.md5.sources.tmp
                        cat CHECKSUMS.md5.sources.tmp | grep -v "\.sh" | uniq > CHECKSUMS.md5.sources 2>/dev/null
                 fi
                fi
                if [[ "$SOURCES" == "1" ]]; then
                 if [ ! -f CHECKSUMS.sources ]; then 
                        MSG "update_lists()" "=> Creating FILELIST List File for Sources... FAILED!"
                 else   
                        MSG "update_lists()" "=> Creating FILELIST List File for Sources... DONE!"
                        cat CHECKSUMS.sources | grep -w "./patches/source" | grep -v "lrwx" | grep gz$ | awk '{ print "x " $5 " " $9 }' >> CHECKSUMS.sources.pmt
                        cat CHECKSUMS.sources | grep -w "./patches/source" | grep -v "lrwx" | grep bz2$ | awk '{ print "x " $5 " " $9 }' >> CHECKSUMS.sources.pmt
                        cat CHECKSUMS.sources | grep -w "./extra/source" | grep -v "lrwx" | grep gz$ | awk '{ print "x " $5 " " $9 }' >> CHECKSUMS.sources.pmt
                        cat CHECKSUMS.sources | grep -w "./extra/source" | grep -v "lrwx" | grep bz2$ | awk '{ print "x " $5 " " $9 }' >> CHECKSUMS.sources.pmt
                        cat CHECKSUMS.sources | grep -w "./source" | grep -v "lrwx" | grep gz$ | awk '{ print "x " $5 " " $9 }' >> CHECKSUMS.sources.pmt 
                        cat CHECKSUMS.sources | grep -w "./source" | grep -v "lrwx" | grep bz2$ | awk '{ print "x " $5 " " $9 }' >> CHECKSUMS.sources.pmt
			cat CHECKSUMS.sources | grep -v "lrwx" | grep "source" | grep -i build | awk '{ print "x " $5 " " $9 }' >> CHECKSUMS.sources.pmt
			cat CHECKSUMS.sources.pmt 2>/dev/null | grep -vi build | grep - > CHECKSUMS.sources.tmp
			cat CHECKSUMS.sources.pmt 2>/dev/null | grep -vi build | grep _ >> CHECKSUMS.sources.tmp
			cat CHECKSUMS.sources.pmt 2>/dev/null | grep -i build >> CHECKSUMS.sources.tmp
                        cat CHECKSUMS.sources.tmp | uniq | grep -v "\.sh" > CHECKSUMS.sources 2>/dev/null
                 fi
                fi 

		if [ "$BSWAP" = "1" ]; then
                                        RECORDS=`cat URL 2>/dev/null | wc -l`
                                        COUNTER=`expr $1 + 1`
                                        if test $COUNTER -ne `expr $RECORDS + 1`
                                        then
                                                update_lists $COUNTER
                                        fi
                fi
		if test `ls CHECKSUMS.md5* 2>/dev/null | wc -l` -ge 1; then
			copy_to_cache
			break
		fi
	fi														        
	if [ "$BSWAP" = "0" ]; then
		if [ ! -f $CDIR/URL.lock ]; then
			remove_incomplete
			touch $CDIR/URL.lock
			break
		fi
	fi
}

update_from_local_lists()
{
        rm -f $CDIR/.cache/* 2>/dev/null
        rm -f $CDIR/*CHECKSUMS* 2>/dev/null

	URL
        ROOTS=`cat URL 2>/dev/null | cut -f2 -d'='`
	CPURLC=`cat URL 2>/dev/null | wc -l`

	for R in $ROOTS
	do
	  BSWAP=0
	  MSG "update_from_local_lists()" "[ $R ]"
	  if test $CPURLC -eq 0; then
		MSG "update_from_local_list()" "### Copying Slackware Linux ($VERSION) CHECKSUMS List File... FAILED!"
		MSG "update_from_local_list()" "### Copying Slackware Linux ($VERSION) FILELIST List File... FAILED!"
		BSWAP=1
	  else
        	export R 
        	if [ -z $R ]; then
			MSG "update_from_local_list()" "### Copying Slackware Linux ($VERSION) CHECKSUMS List File... FAILED!"
			MSG "update_from_local_list()" "### Copying Slackware Linux ($VERSION) FILELIST List File... FAILED!"
			BSWAP=1
		else
			if [ -f $R/CHECKSUMS.md5 ]; then
				cp $R/CHECKSUMS.md5 . 2>/dev/null
			fi
			if [ -f $R/FILELIST.TXT ]; then
				cp $R/FILELIST.TXT CHECKSUMS 2>/dev/null
			fi
			if [ -f CHECKSUMS.md5 ]; then
				MSG "update_from_local_list()" "### Copying Slackware Linux ($VERSION) CHECKSUMS List File... DONE!"
			else
				MSG "update_from_local_list()" "### Copying Slackware Linux ($VERSION) CHECKSUMS List File... FAILED!"
				BSWAP=1
			fi
			if [ -f CHECKSUMS ]; then
				MSG "update_from_local_list()" "### Copying Slackware Linux ($VERSION) FILELIST List File... DONE!"
			else
				MSG "update_from_local_list()" "### Copying Slackware Linux ($VERSION) FILELIST List File... FAILED!"
				BSWAP=1
			fi

                	if [[ "$SOURCES" == "1" ]]; then
                        	cp $CDIR/CHECKSUMS $CDIR/CHECKSUMS.sources 2>/dev/null
                        	cp $CDIR/CHECKSUMS.md5 $CDIR/CHECKSUMS.md5.sources 2>/dev/null
                	fi     

                        if [[ $VPATCHES == 1 ]]; then
				if [ -f CHECKSUMS.md5 ]; then
                                        MSG "update_from_local_list()" "=> Creating CHECKSUMS List File for Patches... DONE!"
                                        cat CHECKSUMS.md5 2>/dev/null | grep "patches/" | grep tgz$ > CHECKSUMS.md5.patches.pmt 2>/dev/null
                                        mv CHECKSUMS.md5.patches.pmt CHECKSUMS.md5.patches 2>/dev/null
				else
					MSG "update_from_local_list()" "=> Creating CHECKSUMS List File for Patches... FAILED!"
				fi
                        fi 
                        if [[ $VPATCHES = 1 ]]; then
				if [ -f CHECKSUMS ]; then
                                        MSG "update_from_local_list()" "=> Creating FILELIST List File for Patches... DONE!"
                                        cat CHECKSUMS 2>/dev/null | grep "patches/" | grep tgz$ | awk '{ print "x " $5 " " $9 }' > CHECKSUMS.patches.pmt 2>/dev/null
                                        mv CHECKSUMS.patches.pmt CHECKSUMS.patches 2>/dev/null
				else	
					MSG "update_from_local_list()" "=> Creating FILELIST List File for Patches... FAILED!"
				fi
			fi
                        if [[ $VEXTRA = 1 ]]; then
				if [ -f CHECKSUMS.md5 ]; then
                                        MSG "update_from_local_list()" "=> Creating CHECKSUMS List File for Extra Packages... DONE!"
                                        cat CHECKSUMS.md5 2>/dev/null | grep "extra/" | grep tgz$ > CHECKSUMS.md5.extra.pmt 2>/dev/null
                                        mv CHECKSUMS.md5.extra.pmt CHECKSUMS.md5.extra 2>/dev/null
				else
					MSG "update_from_local_list()" "=> Creating CHECKSUMS List File for Extra Packages... FAILED!"
				fi
                        fi
                        if [[ $VEXTRA = 1 ]]; then
				if [ -f CHECKSUMS ]; then
                                        MSG "update_from_local_list()" "=> Creating FILELIST List File for Extra Packages... DONE!"
                                        cat CHECKSUMS 2>/dev/null | grep "extra/" | grep tgz$ | awk '{ print "x " $5 " " $9 }' > CHECKSUMS.extra.pmt 2>/dev/null
                                        mv CHECKSUMS.extra.pmt CHECKSUMS.extra 2>/dev/null
				else
					MSG "update_from_local_list()" "=> Creating FILELIST List File for Extra Packages... FAILED!"
				fi
			fi
                        if [[ $VPACKAGES = 1 ]]; then
				if [ -f CHECKSUMS.md5 ]; then
                                        MSG "update_from_local_list()" "=> Creating CHECKSUMS List File for Packages... DONE!"
                                        cat CHECKSUMS.md5 2>/dev/null | grep "slackware/" | grep tgz$ > CHECKSUMS.md5.pmt 2>/dev/null
                                        mv CHECKSUMS.md5.pmt CHECKSUMS.md5 2>/dev/null
				else
					MSG "update_from_local_list()" "=> Creating CHECKSUMS List File for Packages... FAILED!"
				fi
                        fi
                        if [[ $VPACKAGES = 1 ]]; then
				if [ -f CHECKSUMS ]; then
                                        MSG "update_from_local_list()" "=> Creating FILELIST List File for Packages... DONE!"
                                        cat CHECKSUMS 2>/dev/null | grep "slackware/" | grep tgz$ | awk '{ print "x " $5 " " $9 }' > CHECKSUMS.pmt 2>/dev/null
                                        mv CHECKSUMS.pmt CHECKSUMS 2>/dev/null
				else
					MSG "update_from_local_list()" "=> Creating FILELIST List File for Packages... FAILED!"
				fi
			fi
                if [[ "$SOURCES" == "1" ]]; then
                 if [ ! -f CHECKSUMS.md5.sources ]; then
                        MSG "update_from_local_list()" "=> Creating CHECKSUMS List File for Sources... FAILED!"
                 else
                        MSG "update_from_local_list()" "=> Creating CHECKSUMS List File for Sources... DONE!"
                        cat CHECKSUMS.md5.sources | grep -v "lrwx" | grep -w "./patches/source" | grep gz$ >> CHECKSUMS.md5.sources.pmt
                        cat CHECKSUMS.md5.sources | grep -v "lrwx" | grep -w "./patches/source" | grep bz2$ >> CHECKSUMS.md5.sources.pmt
                        cat CHECKSUMS.md5.sources | grep -v "lrwx" | grep -w "./extra/source" | grep gz$ >> CHECKSUMS.md5.sources.pmt
                        cat CHECKSUMS.md5.sources | grep -v "lrwx" | grep -w "./extra/source" | grep bz2$ >> CHECKSUMS.md5.sources.pmt
                        cat CHECKSUMS.md5.sources | grep -v "lrwx" | grep -w "./source" | grep gz$ >> CHECKSUMS.md5.sources.pmt
                        cat CHECKSUMS.md5.sources | grep -v "lrwx" | grep -w "./source" | grep bz2$ >> CHECKSUMS.md5.sources.pmt
                        cat CHECKSUMS.md5.sources.pmt 2>/dev/null | grep - > CHECKSUMS.md5.sources.tmp
                        cat CHECKSUMS.md5.sources.pmt 2>/dev/null | grep _ >> CHECKSUMS.md5.sources.tmp
                        cat CHECKSUMS.md5.sources.tmp | grep -v "\.sh" | sort | uniq > CHECKSUMS.md5.sources 2>/dev/null
                 fi
                fi
                if [[ "$SOURCES" == "1" ]]; then
                 if [ ! -f CHECKSUMS.sources ]; then
                        MSG "update_from_local_lists()" "=> Creating FILELIST List File for Sources... FAILED!"
                 else   
                        MSG "update_from_local_lists()" "=> Creating FILELIST List File for Sources... DONE!"
                        cat CHECKSUMS.sources | grep -w "./patches/source" | grep -v "lrwx" | grep gz$ | awk '{ print "x " $5 " " $9 }' >> CHECKSUMS.sources.pmt    
                        cat CHECKSUMS.sources | grep -w "./patches/source" | grep -v "lrwx" | grep bz2$ | awk '{ print "x " $5 " " $9 }' >> CHECKSUMS.sources.pmt   
                        cat CHECKSUMS.sources | grep -w "./extra/source" | grep -v "lrwx" | grep gz$ | awk '{ print "x " $5 " " $9 }' >> CHECKSUMS.sources.pmt      
                        cat CHECKSUMS.sources | grep -w "./extra/source" | grep -v "lrwx" | grep bz2$ | awk '{ print "x " $5 " " $9 }' >> CHECKSUMS.sources.pmt     
                        cat CHECKSUMS.sources | grep -w "./source" | grep -v "lrwx" | grep gz$ | awk '{ print "x " $5 " " $9 }' >> CHECKSUMS.sources.pmt            
                        cat CHECKSUMS.sources | grep -w "./source" | grep -v "lrwx" | grep bz2$ | awk '{ print "x " $5 " " $9 }' >> CHECKSUMS.sources.pmt           
			cat CHECKSUMS.sources | grep "source" | grep -v "lrwx" | grep -i build | awk '{ print "x " $5 " " $9 }' >> CHECKSUMS.sources.pmt
                        cat CHECKSUMS.sources.pmt 2>/dev/null | grep -vi build | grep - > CHECKSUMS.sources.tmp
                        cat CHECKSUMS.sources.pmt 2>/dev/null | grep -vi build | grep _ >> CHECKSUMS.sources.tmp
                        cat CHECKSUMS.sources.pmt 2>/dev/null | grep -i build >> CHECKSUMS.sources.tmp
                        cat CHECKSUMS.sources.tmp | grep -v "\.sh" | sort | uniq > CHECKSUMS.sources 2>/dev/null
                 fi     
                fi 
			if test `ls CHECKSUMS.md5* 2>/dev/null | wc -l` -ge 1; then 
                        	copy_to_cache
                	fi
		fi
	  fi
          if [ "$BSWAP" = "0" ]; then
                if [ ! -f $CDIR/URL.lock ]; then
                        remove_incomplete
                        touch $CDIR/URL.lock
			break
                fi
          fi
	done
}

check_for_settings()
{
        if [ ! -f /etc/swaret.conf ]; then
                MSG "check_for_settings()" "swaret Config File (/etc/swaret.conf) not found!"
                MSG "check_for_settings()" "Copy /usr/doc/swaret-$SVERSION/swaret.conf.new to"
                MSGERR "check_for_settings()" "/etc/swaret.conf, edit and start swaret."
        else
		eval $( grep -v "^#" /etc/swaret.conf | grep "=" | cut -f1 -d'#' | sed s/'"'//\g | sed s/''\'//\g | sed 's/=\(.*\)$/="\1"/' | sed s/'  '//\g | sed s/' \"'/'\"'/\g ) 
		if [ -z $PACKAGES_LOGDIR ]; then
                        export PACKAGES_LOGDIR="/var/log/packages/"
                fi
		if [ -z $REMOVED_PACKAGES_LOGDIR ]; then
                        export REMOVED_PACKAGES_LOGDIR="/var/log/removed_packages/"
                fi
		if [ -z $FORCE_PATH ]; then
                        export PATH="$PATH:/bin:/usr/bin:/usr/local/bin:/sbin:/usr/sbin:/usr/local/sbin"
                fi
		if [ -z $PACKAGES ]; then
			export VPACKAGES=1
		else
			export VPACKAGES="$PACKAGES"
		fi
                if [ -z $PATCHES ]; then
                        export VPATCHES=1
		else
			export VPATCHES="$PATCHES"
                fi
                if [ -z $EXTRA ]; then
                        export VEXTRA=1
		else
			export VEXTRA="$EXTRA"
                fi
		if [ -z $DEPENDENCY ]; then
                        export VDEPENDENCY="1"
                else
                        export VDEPENDENCY="$DEPENDENCY"
		fi
		if [ -z $NIC ]; then
                        export NIC="eth0"
                fi
		if [ -z $TIMEOUT ]; then
			export TIMEOUT="25"
		fi
		if [ -z $RETRIES ]; then
			export RETRIES="5"
		fi
		if [ -z $DESC ]; then
			export DESC="NO"
		fi
		if [ -z $OFFSET ]; then
                        export OFFSET="20"
                fi
		if [ -z $DINTERACTIVE ]; then
                        export DINTERACTIVE="1"
                fi
		if [ -z $CACHE_DIR ]; then
			export CDIR="/var/swaret/"	
		else
                        export CDIR="$CACHE_DIR"
                fi
		if [ -z $LOG ]; then
			export LOG="1"
		fi
		if [ -z $LOG_FILE ]; then
                        export LF="/var/log/swaret"
		else
			export LF="$LOG_FILE"
                fi
		if [ -z $WARNINGS ]; then
			export WARNINGS="1"
		fi
		if [ -z $INFORMATION ]; then
			export INFORMATION="1"
		fi
		if [ -z $DEP_INSTALL ]; then
			export DEP_INSTALL="1"
                fi
                if [ -z $DEP_UPGRADE ]; then
                        export DEP_UPGRADE="1" 
                fi
                if [ -z $DEP_REINSTALL ]; then
                        export DEP_REINSTALL="1" 
                fi
		if [ -z $PASSIVE_FTP ]; then
			export PF="--passive-ftp"
		else
			if [[ "$PASSIVE_FTP" == "1" ]]; then
				export PF="--passive-ftp"
			else
				export PF=""
			fi
		fi
		if [ -z $DINTERFACE ]; then
			export Q="-q"
			export QS="-n"
		else
			if [[ "$DINTERFACE" == "1" ]]; then
				export Q=""
				export QS=""
			else
				export Q="-q"
                        	export QS="-n"
			fi
                fi
		if [ -z $MD5CHECK ]; then
			export MD5CHECK="1"
		fi
		if [ -z $SOURCES ]; then
			export SOURCES="1"
		fi
		if [ -z $PGPCHECK ]; then
			export PGPCHECK="1"
		fi
		if [[ "$PGPCHECK" = "1" ]]; then
			check_gnupg
		fi
	fi
	mkdir $CDIR/ 2>/dev/null
        mkdir $CDIR/.cache 2>/dev/null
	mkdir $CDIR/sources 2>/dev/null 
	chown -R root.root $CDIR/ 2>/dev/null
	chown root.root /etc/swaret.conf 2>/dev/null
	chown root.root /var/log/swaret 2>/dev/null
	chown root.root /usr/man/man8/swaret.8.gz 2>/dev/null
	chown root.root /usr/man/man5/swaret.conf.5.gz 2>/dev/null
	chown root.root /usr/doc/swaret-$VERSION/* 2>/dev/null
	chmod -R 700 $CDIR/ 2>/dev/null
	chmod 644 /etc/swaret.conf 2>/dev/null
	chmod 644 /var/log/swaret 2>/dev/null
	chmod 644 /usr/man/man8/swaret.8.gz 2>/dev/null
	chmod 644 /usr/man/man5/swaret.conf.5.gz 2>/dev/null
	chmod 644 /usr/doc/swaret-$VERSION/* 2>/dev/null
	cd $CDIR/
}

check_log_settings() 
{
                if [[ "$LOG" = "1" ]]; then
                        if [ ! -f $LF ]; then
                                touch $LF 2>/dev/null
                        fi
                        chmod 644 $LF 2>/dev/null
                fi
}

check_for_network()
{

	if test `ifconfig | grep -c $NIC` -eq 0
	then
		MSG "check_for_network()" "Network Connection down!"
		echo
		MSGERR "check_for_network()" "Please, take a look to 'NIC' in /etc/swaret.conf!"
	fi
		
}

check_for_version()
{
	if [ ! -f /etc/swaret.conf ]; then
                MSG "check_for_version()" "swaret Config File (/etc/swaret.conf) not found!"
                MSG "check_for_version()" "Copy /usr/doc/swaret-$SVERSION/swaret.conf.new to"
                MSGERR "check_for_version()" "/etc/swaret.conf, edit and start swaret."
	fi

	URL
	COUNTVALIDVERSION=0
	COUNTVALIDROOT=0
	CHECK=`cat /etc/swaret.conf 2>/dev/null | grep "^ROOT=" | grep -v "#" | wc -l`
	if test $CHECK -eq 0
	then
        	MSG "check_for_version()" "Please, fix "\'ROOT\'" in /etc/swaret.conf!"
        	exit
	else
        	GET_VERSION=`cat /etc/swaret.conf 2>/dev/null | grep "VERSION=" | grep -v "#" | cut -f2 -d'='`
		if test `cat /etc/swaret.conf 2>/dev/null | grep "VERSION=" | grep -v "#" | cut -f2 -d'=' | wc -c` -eq 4 
		then
			VERSION=$GET_VERSION
			export VERSION
		fi
        	if test `cat /etc/swaret.conf 2>/dev/null | grep "VERSION=" | grep -v "#" | cut -f2 -d'=' | wc -c` -eq 8 
        	then
                	VERSION=$GET_VERSION
			export VERSION
        	fi
		if [ -z "$VERSION" ]; then
	        	MSGERR "check_for_version()" "Please, fix "\'VERSION\'" in /etc/swaret.conf!"
		fi
	fi
}

check_size_pkg()
{
	CACHED_PKG_SIZE=`ls -alL $CDIR/$1 2>/dev/null | awk '{print$5}'`
	if test `cat $CDIR/.cache/CHECKSUMS 2>/dev/null | grep "/$1" | wc -l` -eq 1; then
		REAL_PKG_SIZE=`cat $CDIR/.cache/CHECKSUMS 2>/dev/null | grep "/$1" | awk '{print$2}'`
	fi
        if test `cat $CDIR/.cache/CHECKSUMS.extra 2>/dev/null | grep "/$1" | wc -l` -eq 1; then
                REAL_PKG_SIZE=`cat $CDIR/.cache/CHECKSUMS.extra 2>/dev/null | grep "/$1" | awk '{print$2}'`
        fi
        if test `cat $CDIR/.cache/CHECKSUMS.patches 2>/dev/null | grep "/$1" | wc -l` -eq 1; then
                REAL_PKG_SIZE=`cat $CDIR/.cache/CHECKSUMS.patches 2>/dev/null | grep "/$1" | awk '{print$2}'`
        fi
	if [[ "$CACHED_PKG_SIZE" != "$REAL_PKG_SIZE" ]]; then
		touch $CDIR/$1.corrupted 2>/dev/null
	fi 
}

check_package_files()
{
        if [ ! -f CHECKSUMS.md5 ]; then
                if [ ! -f CHECKSUMS ]; then
                        MSG "check_package_files()" "CHECKSUMS List File for Packages and FILELIST List File for Packages not found!"
                else
                        MSG "check_package_files()" "CHECKSUMS List File for Packages not found!"
                fi
		if [[ "$VPACKAGES" != "1" ]]; then
			MSG "check_package_files()" "Please, fix "\'PACKAGES\'" in /etc/swaret.conf!"
		else
                	echo "Please, swaret --update!"
		fi
                exit 
        fi
        if [ ! -f CHECKSUMS ]; then
                if [ ! -f CHECKSUMS.md5 ]; then
                        MSG "check_package_files()" "CHECKSUMS List File for Packages and FILELIST List File for Packages not found!"
                else
                        MSG "check_package_files()" "FILELIST List File for Packages not found!"
                fi
                if [[ "$VPACKAGES" != "1" ]]; then
                        MSG "check_package_files()" "Please, fix "\'PACKAGES\'" in /etc/swaret.conf!"
		else
                	echo "Please, swaret --update!"
		fi
                exit
        fi
}

check_patch_files()
{
        if [ ! -f CHECKSUMS.md5.patches ]; then
                if [ ! -f CHECKSUMS.patches ]; then
                        MSG "check_patch_files()" "CHECKSUMS List File for Patches and FILELIST List File for Patches not found!"
                else
                        MSG "check_patch_files()" "CHECKSUMS List File for Patches not found!"
		fi
                if [[ "$VPATCHES" != "1" ]]; then
                        MSG "check_patch_files()" "Please, fix "\'PATCHES\'" in /etc/swaret.conf!"
		else
                	echo "Please, swaret --update!"
		fi
                exit
        fi
        if [ ! -f CHECKSUMS.patches ]; then
                if [ ! -f CHECKSUMS.md5.patches ]; then
                        MSG "check_patch_files()" "CHECKSUMS List File for Patches and FILELIST List File for Patches not found!"
                else
                        MSG "check_patch_files()" "FILELIST List File for Patches not found!"
                fi
                if [[ "$VPATCHES" != "1" ]]; then
                        MSG "check_patch_files()" "Please, fix "\'PATCHES\'" in /etc/swaret.conf!"
                else
                        echo "Please, swaret --update!" 
                fi
                exit
        fi
}

check_extra_files()
{
        if [ ! -f CHECKSUMS.md5.extra ]; then
                if [ ! -f CHECKSUMS.extra ]; then
                        MSG "check_extra_files()" "CHECKSUMS List File for Extra Packages and FILELIST List File for Extra Packages not found!"
                else
                        MSG "check_extra_files()" "CHECKSUMS List File for Extra Packages not found!"
                fi
                if [[ "$VEXTRA" != "1" ]]; then
                        MSG "check_extra_files()" "Please, fix "\'EXTRA\'" in /etc/swaret.conf!"
                else
                        echo "Please, swaret --update!"
                fi
                exit
        fi
        if [ ! -f CHECKSUMS.extra ]; then
                if [ ! -f CHECKSUMS.md5.extra ]; then
                        MSG "check_extra_files()" "CHECKSUMS List File for Extra Packages and FILELIST List File for Packages not found!"
                else
                        MSG "check_extra_files()" "FILELIST List File for Extra Packages not found!"
                fi
                if [[ "$VEXTRA" != "1" ]]; then
                        MSG "check_extra_files()" "Please, fix "\'EXTRA\'" in /etc/swaret.conf!"
                else
                        echo "Please, swaret --update!"
                fi
                exit
        fi
}

check_source_files()
{
        if [ ! -f CHECKSUMS.md5.sources ]; then
                if [ ! -f CHECKSUMS.sources ]; then
                        MSG "check_source_files()" "CHECKSUMS List File for Sources and FILELIST List File for Sources not found!"
                else
                        MSG "check_source_files()" "CHECKSUMS List File for Sources not found!"
                fi
                if [[ "$SOURCES" != "1" ]]; then
                        MSG "check_source_files()" "Please, fix "\'SOURCES\'" in /etc/swaret.conf!"
                else
                        echo "Please, swaret --update!"
                fi
                exit
        fi
        if [ ! -f CHECKSUMS.sources ]; then
                if [ ! -f CHECKSUMS.md5.sources ]; then
                        MSG "check_source_files()" "CHECKSUMS List File for Sources and FILELIST List File for Sources not found!"
                else
                        MSG "check_source_files()" "FILELIST List File for Sources not found!"
                fi
                if [[ "$SOURCES" != "1" ]]; then
                        MSG "check_source_files()" "Please, fix "\'SOURCES\'" in /etc/swaret.conf!"
                else
                        echo "Please, swaret --update!"
                fi
                exit
        fi
}

swap_to_patches()
{
  cp CHECKSUMS.md5.patches CHECKSUMS.md5 2>/dev/null
  cp CHECKSUMS.patches CHECKSUMS 2>/dev/null
}

swap_to_extra()
{
  cp CHECKSUMS.md5.extra CHECKSUMS.md5 2>/dev/null
  cp CHECKSUMS.extra CHECKSUMS 2>/dev/null
}

swap_to_sources()
{
  cp CHECKSUMS.md5.sources CHECKSUMS.md5 2>/dev/null
  cp CHECKSUMS.sources CHECKSUMS 2>/dev/null
}

clean_cache()
{
  rm -rf $CDIR/.cache 2>/dev/null
}

copy_to_cache()
{
  if [ ! -d $CDIR/.cache ]; then
	mkdir -p $CDIR/.cache 2>/dev/null
	chmod 700 $CDIR/.cache 2>/dev/null
	chown root.root $CDIR/.cache 2>/dev/null
  fi
  cp -f $CDIR/CHECKSUMS $CDIR/.cache/ 2>/dev/null
  cp -f $CDIR/CHECKSUMS.md5 $CDIR/.cache/ 2>/dev/null 
  cp -f $CDIR/CHECKSUMS.patches $CDIR/.cache/ 2>/dev/null
  cp -f $CDIR/CHECKSUMS.md5.patches $CDIR/.cache/ 2>/dev/null
  cp -f $CDIR/CHECKSUMS.extra $CDIR/.cache/ 2>/dev/null
  cp -f $CDIR/CHECKSUMS.md5.extra $CDIR/.cache/ 2>/dev/null
  cp -f $CDIR/CHECKSUMS.sources $CDIR/.cache/ 2>/dev/null
  cp -f $CDIR/CHECKSUMS.md5.sources $CDIR/.cache/ 2>/dev/null
}

copy_from_cache()
{
  if [ -d .cache ]; then
     if [ -f .cache/CHECKSUMS.md5 ] && [ -f .cache/CHECKSUMS ]; then
        cp .cache/CHECKSUMS.md5 . 2>/dev/null
        cp .cache/CHECKSUMS . 2>/dev/null
     fi
     if [ -f .cache/CHECKSUMS.md5.patches ] && [ -f .cache/CHECKSUMS.patches ]; then
        cp .cache/CHECKSUMS.md5.patches . 2>/dev/null
        cp .cache/CHECKSUMS.patches . 2>/dev/null
     fi
     if [ -f .cache/CHECKSUMS.md5.extra ] && [ -f .cache/CHECKSUMS.extra ]; then
        cp .cache/CHECKSUMS.md5.extra . 2>/dev/null
        cp .cache/CHECKSUMS.extra . 2>/dev/null
     fi
     if [ -f .cache/CHECKSUMS.md5.sources ] && [ -f .cache/CHECKSUMS.sources ]; then
        cp .cache/CHECKSUMS.md5.sources . 2>/dev/null
        cp .cache/CHECKSUMS.sources . 2>/dev/null
     fi
  fi
}

make_patches_list()
{
     rm -f CHECKSUMS.md5.patches.tmp 2>/dev/null
     rm -f CHECKSUMS.md5.patches.pmt 2>/dev/null
     cat $CDIR/CHECKSUMS.md5.patches 2>/dev/null | sed -e "s/.*\///g" | grep ".tgz$" >> CHECKSUMS.md5.patches.tmp 2>/dev/null
     cat CHECKSUMS.md5.patches.tmp | sort | uniq > CHECKSUMS.md5.patches.pmt 2>/dev/null
     cp CHECKSUMS.md5.patches.pmt CHECKSUMS.md5.patches.tmp 2>/dev/null 2>/dev/null
}

make_extra_list()
{
     rm -f CHECKSUMS.md5.extra.tmp 2>/dev/null
     rm -f CHECKSUMS.md5.extra.pmt 2>/dev/null
     cat $CDIR/CHECKSUMS.md5.extra 2>/dev/null | sed -e "s/.*\///g" | grep ".tgz$" >> CHECKSUMS.md5.extra.tmp 2>/dev/null
     cat CHECKSUMS.md5.extra.tmp | sort | uniq > CHECKSUMS.md5.extra.pmt 2>/dev/null
     cp CHECKSUMS.md5.extra.pmt CHECKSUMS.md5.extra.tmp 2>/dev/null 2>/dev/null
}

lf_errr()
{
						HEADER
                                                MSG "lf_errr()" "When using Local Files, you may not use other Protocols!"
                                                MSG "lf_errr()" "Please, comment or remove the ROOT Variables in /etc/swaret.conf"
                                                MSGERR "lf_errr()" "which contains Protocols like http and/or ftp and/or rsync!"
}

lfd_errr()
{
                                                HEADER
                                                MSG "lfd_errr()" "When using Local Files, you may not use other Protocols!"
                                                MSG "lfd_errr()" "Please, comment or remove the DEP_ROOT Variables in /etc/swaret.conf"
                                                MSGERR "lfd_errr()" "which contains Protocols like http and/or ftp and/or rsync!"
}

logme()
{
  if [[ "$LOG" = "1" ]]; then
    check_log_settings
    date=`date`
    echo "$date: [ $1 ] - $2" >> $LF 2>/dev/null
  fi
}

dependency_check()
{
                FPKGSW=0
                FPKGTSIZE=0
                FPKGC=0

                        for i in `cat /etc/swaret.conf 2>/dev/null | grep "^ONLY" | grep -v "#" | sed s/'"'//\g | sed s/','/' '/\g | cut -f2 -d'='`
                        do
                                for x in $i
                                do
                                        echo $x >> $CDIR/swaret.only 2>/dev/null
                                done
                        done
                        for i in `cat /etc/swaret.conf 2>/dev/null | grep "^EXCLUDE" | grep -v "#" | sed s/'"'//\g | sed s/','/' '/\g | cut -f2 -d'='`
                        do
                                for x in $i
                                do
                                        echo $x >> $CDIR/swaret.exclude 2>/dev/null
                                done
                        done

			dget_pkg()
			{
			SHORTPKG=`echo $1 | sed s/'.tgz'//`
			if [ -f $1 ]; then
				SIZEPKGTMP=`ls -alL $1 2>/dev/null | awk '{print$5}'`
				SIZEPKG=`echo $SIZEPKGTMP / 1024 | bc`
				TRIGVAR=""
                                if test `cat .cache/CHECKSUMS 2>/dev/null | grep "/$1" | wc -l` -ge 1; then
                                  cp .cache/CHECKSUMS $CDIR/CHECKSUMS 2>/dev/null
				  TRIGVAR=slackware
                                fi
                                if test `cat .cache/CHECKSUMS.patches 2>/dev/null | grep "/$1" | wc -l` -ge 1; then
                                  cp .cache/CHECKSUMS.patches $CDIR/CHECKSUMS 2>/dev/null
				  TRIGVAR=patches
                             	fi 
                                if test `cat .cache/CHECKSUMS.extra 2>/dev/null | grep "/$1" | wc -l` -ge 1; then
                                  cp .cache/CHECKSUMS.extra $CDIR/CHECKSUMS 2>/dev/null
                                  TRIGVAR=extra
                                fi
				if [[ "$TRIGVAR" = "patches" ]]; then
					MSG "dget_pkg()" "Patch $SHORTPKG ($SIZEPKG kB) found in $CDIR!"
					check_for_broken_patches $1 1
				fi
				if [[ "$TRIGVAR" = "extra" ]]; then
					MSG "dget_pkg()" "Extra Package $SHORTPKG ($SIZEPKG kB) found in $CDIR!"
					check_for_broken_extra $1 1
				fi
				if [[ "$TRIGVAR" = "slackware" ]]; then
					MSG "dget_pkg()" "Package $SHORTPKG ($SIZEPKG kB) found in $CDIR!"
					check_for_broken_packages $1 1
				fi
			else
				PACKAGES_URL=`cat URL 2>/dev/null | awk '{ if(NR == '$2') print $1 }'`
				TRIGVAR=""
				if test `cat .cache/CHECKSUMS.patches 2>/dev/null | grep "/$1" | wc -l` -ge 1; then
					PACKAGE=`cat .cache/CHECKSUMS.patches 2>/dev/null | grep "/$1" | awk '{print$3}' | grep "/" | sed s/.//`
					cp .cache/CHECKSUMS.patches CHECKSUMS 2>/dev/null
					TRIGVAR=patches
				fi
				if test `cat .cache/CHECKSUMS.extra 2>/dev/null | grep "/$1" | wc -l` -ge 1; then
				        PACKAGE=`cat .cache/CHECKSUMS.extra 2>/dev/null | grep "/$1" | awk '{print$3}' | grep "/" | sed s/.//`
					cp .cache/CHECKSUMS.extra CHECKSUMS 2>/dev/null
					TRIGVAR=extra
				fi
				if test `cat .cache/CHECKSUMS 2>/dev/null | grep "/$1" | wc -l` -ge 1; then
                                        PACKAGE=`cat .cache/CHECKSUMS 2>/dev/null | grep "/$1" | grep / | awk '{print$3}' | sed s/.//`
					cp .cache/CHECKSUMS CHECKSUMS 2>/dev/null
					TRIGVAR=slackware
				fi
				SIZEPKGTMP=`cat CHECKSUMS 2>/dev/null | grep "/$1" | awk '{print$2}'`
				SIZEPKG=`echo $SIZEPKGTMP / 1024 | bc`
				if [ ! -z $PACKAGES_URL ]; then
                                        MSG "dget_pkg()" "[ $PACKAGES_URL ]"
					echo $QS "### Fetching $SHORTPKG ($SIZEPKG kB)... "
					if test `echo $PACKAGES_URL | grep rsync | wc -l` -ge 1
					then
                                            if [ ! -z $Q ]; then
							rsync_file "$PACKAGES_URL" "$PACKAGE"
						    if test `cat $CDIR/.cache/CHECKSUMS 2>/dev/null | grep "/$1" | wc -l` -ge 1; then
							cp $CDIR/.cache/CHECKSUMS $CDIR/CHECKSUMS 2>/dev/null
						    fi
                                                    if test `cat $CDIR/.cache/CHECKSUMS.extra 2>/dev/null | grep "/$1" | wc -l` -ge 1; then
                                                        cp $CDIR/.cache/CHECKSUMS.extra $CDIR/CHECKSUMS 2>/dev/null
                                                    fi
                                                    if test `cat $CDIR/.cache/CHECKSUMS.patches 2>/dev/null| grep "/$1" | wc -l` -ge 1; then
                                                        cp $CDIR/.cache/CHECKSUMS.patches $CDIR/CHECKSUMS 2>/dev/null
                                                    fi
                                                    count_size_rsync $1 $3
                                            else
							rsync_file_s "$PACKAGES_URL" "$PACKAGE"
                                                    if test `ls -alL $CDIR/$1 2>/dev/null | wc -l` -eq 1; then
                                                        if test `ls -alL $CDIR/$1 2>/dev/null | awk '{print$5}'` -eq $SIZEPKGTMP
                                                        then
                                                            touch $1.tmp 2>/dev/null
                                                        else
                                                            rm -f $1.tmp 2>/dev/null
                                                        fi
                                                    else
                                                        rm -f $1.tmp 2>/dev/null
                                                    fi
                                            fi
                        	        else
                                            if [ ! -z $Q ]; then
							wget_file "$PACKAGES_URL" "$PACKAGE"
                                                    if test `cat $CDIR/.cache/CHECKSUMS 2>/dev/null | grep "/$1" | wc -l` -ge 1; then
                                                        cp $CDIR/.cache/CHECKSUMS $CDIR/CHECKSUMS 2>/dev/null
                                                    fi
                                                    if test `cat $CDIR/.cache/CHECKSUMS.extra 2>/dev/null| grep "/$1" | wc -l` -ge 1; then
                                                        cp $CDIR/.cache/CHECKSUMS.extra $CDIR/CHECKSUMS 2>/dev/null
                                                    fi
                                                    if test `cat $CDIR/.cache/CHECKSUMS.patches 2>/dev/null | grep "/$1" | wc -l` -ge 1; then
                                                        cp $CDIR/.cache/CHECKSUMS.patches $CDIR/CHECKSUMS 2>/dev/null
                                                    fi
                                                    count_size $1 $3
                                            else
							wget_file_s "$PACKAGES_URL" "$PACKAGE"
                                                    if test `ls -alL $CDIR/$1 2>/dev/null | wc -l` -eq 1; then
                                                        if test `ls -alL $CDIR/$1 2>/dev/null | awk '{print$5}'` -eq $SIZEPKGTMP
                                                        then
                                                            touch $1.tmp 2>/dev/null
                                                        else
                                                            rm -f $1.tmp 2>/dev/null
                                                        fi
                                                    else
                                                        rm -f $1.tmp 2>/dev/null
                                                    fi
                                            fi
					fi
                                        if [ -f $1.tmp ]; then
						FPKGSW=1
						FPKGTSIZE=`echo "$FPKGTSIZE + $SIZEPKG" | bc`
						FPKGC=`echo "$FPKGC + 1" | bc`
						if [ ! -z $Q ]; then
                                                	echo " DONE!"
						fi
						logme "dget_pkg()" "### Fetching $SHORTPKG ($SIZEPKG kB)... DONE!"
						if test `cat .cache/CHECKSUMS.patches 2>/dev/null | grep "/$1" | wc -l` -ge 1; then
							checksum_patch $1
							GETPKG="$PACKAGE"
							pgp_check_remote "dependency_check()" "-p" "-ap" "$1"
						fi
						if test `cat .cache/CHECKSUMS.extra 2>/dev/null | grep "/$1" | wc -l` -ge 1; then
							checksum_extra $1
							GETPKG="$PACKAGE"
							pgp_check_remote "dependency_check()" "-e" "-ae" "$1"
						fi
						if test `cat .cache/CHECKSUMS 2>/dev/null | grep "/$1" | wc -l` -ge 1; then
							checksum_package $1
							GETPKG="$PACKAGE"
							pgp_check_remote "dependency_check()" "-a" "-a" "$1"
						fi
						DONE=0
                                        else
						if [ ! -z $Q ]; then
                                                	echo " FAILED!"
						fi
						logme "dget_pkg()" "### Fetching $SHORTPKG ($SIZEPKG kB)... FAILED!"
                                                rm -f $1.tmp 2>/dev/null
						RECORDS=`cat URL 2>/dev/null | wc -l`
							COUNTER=`expr $COUNTER + 1`
							if test $COUNTER -ne `expr $RECORDS + 1`
							then
								dget_pkg $1 $COUNTER $3
							fi
					fi
					DONE=0
				fi
			fi
			}

                        cget_pkg()
                        {
                              SHORTPKG=`echo $1 | sed s/'.tgz'//`
                              if [ ! -f $1 ]; then
				ROOTS=`cat /etc/swaret.conf | grep -v "#" | grep "^ROOT=" | grep "file:" | cut -f2 -d'=' | sed s/'file:'//`
				for RR in $ROOTS
				do
				  TRIGVAR=""
				  if test `cat .cache/CHECKSUMS.patches 2>/dev/null | grep "/$1" | wc -l` -ge 1; then
                                        PACKAGE=`cat .cache/CHECKSUMS.patches 2>/dev/null | grep "/$1" | awk '{print$3}' | grep "/" | sed s/.//`
					TRIGVAR=patches
                                  fi
				  if test `cat .cache/CHECKSUMS.extra 2>/dev/null | grep "/$1" | wc -l` -ge 1; then
                                        PACKAGE=`cat .cache/CHECKSUMS.extra 2>/dev/null | grep "/$1" | awk '{print$3}' | grep "/" | sed s/.//`
					TRIGVAR=extra
                                  fi
				  if test `cat .cache/CHECKSUMS 2>/dev/null | grep "/$1" | wc -l` -ge 1; then
                                        PACKAGE=`cat .cache/CHECKSUMS 2>/dev/null | grep "/$1" | grep / | awk '{print$3}' | sed s/.//`
					TRIGVAR=slackware
                                  fi
                                  if [ ! -z $RR ]; then
                                        SIZEPKGTMP=`cat CHECKSUMS 2>/dev/null | grep "/$1" | awk '{print$2}'`
                                        SIZEPKG=`echo $SIZEPKGTMP / 1024 | bc`
                                        MSG "dependency_check()" "[ file:$RR ]"
                                        echo -n "### Copying $SHORTPKG ($SIZEPKG kB)... "
					if test `cat .cache/CHECKSUMS.patches 2>/dev/null | grep "/$1" | wc -l` -ge 1; then
						copy_file "$RR" "$PACKAGE"
                                        fi
					if test `cat .cache/CHECKSUMS.extra 2>/dev/null | grep "/$1" | wc -l` -ge 1; then
						copy_file "$RR" "$PACKAGE"
                                        fi
					if test `cat .cache/CHECKSUMS 2>/dev/null | grep "/$1" | wc -l` -ge 1; then
						copy_file "$RR" "$PACKAGE"
                                        fi
                                        if [ -f $1 ]; then
                                                echo "DONE!"
                                                logme "dependency_check()" "### Copying $SHORTPKG ($SIZEPKG kB)... DONE!"
						if test `cat .cache/CHECKSUMS.patches 2>/dev/null | grep "/$1" | wc -l` -ge 1; then
                                                        checksum_patch $1
							pgp_check_local "dependency_check()" "-p" "-ap" "$1"
                                                fi
						if test `cat .cache/CHECKSUMS.extra 2>/dev/null | grep "/$1" | wc -l` -ge 1; then
                                                        checksum_extra $1
							pgp_check_local "dependency_check()" "-e" "-ae" "$1"
                                                fi
						if test `cat .cache/CHECKSUMS 2>/dev/null | grep "/$1" | wc -l` -ge 1; then
                                                        checksum_package $1
							pgp_check_local "dependency_check()" "-a" "-a" "$1"
                                                fi
                                                DONE=0
						break
                                        else
                                                echo "FAILED!"
                                                logme "dependency_check()" "### Copying $SHORTPKG ($SIZEPKG kB)... FAILED!"
                                        fi
                                  else
                                        SIZEPKGTMP=`cat CHECKSUMS 2>/dev/null | grep "/$1" | awk '{print$2}'`
                                        SIZEPKG=`echo $SIZEPKGTMP / 1024 | bc`
                                        MSG "dependency_check()" "### Copying $SHORTPKG ($SIZEPKG kB)... FAILED!"
                                  fi
				done
                              else
                                        SIZEPKGTMP=`cat CHECKSUMS 2>/dev/null | grep "/$1" | awk '{print$2}'`
                                        SIZEPKG=`echo $SIZEPKGTMP / 1024 | bc`
					if test `cat .cache/CHECKSUMS.patches 2>/dev/null | grep "/$1" | wc -l` -ge 1; then
                                                MSG "dependency_check()" "Patch $SHORTPKG ($SIZEPKG kB) found in $CDIR!"
                                                res_local_pat $1
                                        fi
					if test `cat .cache/CHECKSUMS.extra 2>/dev/null | grep "/$1" | wc -l` -ge 1; then
                                                MSG "dependency_check()" "Extra Package $SHORTPKG ($SIZEPKG kB) found in $CDIR!"
						res_local_ext $1
                                        fi
					if test `cat .cache/CHECKSUMS 2>/dev/null | grep "/$1" | wc -l` -ge 1; then
                                                MSG "dependency_check()" "Package $SHORTPKG ($SIZEPKG kB) found in $CDIR!"
						res_local_pac $1
                                        fi
                              fi
                          }

	CSWAP=0
	if [[ "$WARNINGS" = "1" ]]; then
		echo "WARNING: This will take some time. Be patient!"
		echo
	fi
        echo -n "%%% Verifying Dependencies... "
        TARFILES=`cat $CDIR/TARFILES.tmp 2>/dev/null`
	TARFILESN=`cat $CDIR/TARFILES.tmp 2>/dev/null | wc -l`
	echo -n "+++++++++++"
	COUNTER=0
        SWAPME=0
	COUNTME=0
	for i in 0 1 2 3 4 5 6 7 8 9 
	do
		PSWAP[$i]=0
	done
        for i in $TARFILES
        do
		COUNTER=`expr $COUNTER + 1`
		TCOUNTER=`expr $COUNTER \* 10 / $TARFILESN`
		if test $TCOUNTER -ge 0; then
			if test $TCOUNTER -le 10; then
				case $TCOUNTER in 
                                        "0")
                                                if test ${PSWAP[0]} -eq 0; then
                                                        printf "\b "
                                                        PSWAP[0]=1;
                                                fi
                                                ;;
                                        "1")
                                                if test ${PSWAP[1]} -eq 0; then
                                                        printf "\b\b  "
                                                        PSWAP[1]=1;
                                                fi
                                                ;;
                                        "2")
                                                if test ${PSWAP[2]} -eq 0; then
                                                        printf "\b\b\b   "
                                                        PSWAP[2]=1;
                                                fi
                                                ;;
                                        "3")
                                                if test ${PSWAP[3]} -eq 0; then
                                                        printf "\b\b\b\b    "
                                                        PSWAP[3]=1;
                                                fi
                                                ;;
                                        "4")
                                                if test ${PSWAP[4]} -eq 0; then
                                                        printf "\b\b\b\b\b     "
                                                        PSWAP[4]=1;
                                                fi
                                                ;;
                                        "5")
                                                if test ${PSWAP[5]} -eq 0; then
                                                        printf "\b\b\b\b\b\b      "
                                                        PSWAP[5]=1;
                                                fi
                                                ;;
                                        "6")
                                                if test ${PSWAP[6]} -eq 0; then
                                                        printf "\b\b\b\b\b\b\b       "
                                                        PSWAP[6]=1;
                                                fi
                                                ;;
                                        "7")
                                                if test ${PSWAP[7]} -eq 0; then
                                                        printf "\b\b\b\b\b\b\b\b        "
                                                        PSWAP[7]=1;
                                                fi
                                                ;;
                                        "8")
                                                if test ${PSWAP[8]} -eq 0; then
                                                        printf "\b\b\b\b\b\b\b\b\b         "
                                                        PSWAP[8]=1;
                                                fi
                                                ;;
                                        "9")
                                                if test ${PSWAP[9]} -eq 0; then
                                                        printf "\b\b\b\b\b\b\b\b\b\b          "
                                                        PSWAP[9]=1;
                                                fi
                                                ;;
				esac
			fi
		fi
		if test $COUNTME -eq 0; then
			printf "\b\\"
		fi
                if test $COUNTME -eq 1; then
                        printf "\b|"
                fi
                if test $COUNTME -eq 2; then
                        printf "\b/"
                fi
                if test $COUNTME -eq 3; then
                        printf "\b-"
		fi			
		PKG=`echo $i | awk -F : '{print$1}' | sed s/'.tgz'//`
		FILEP=`echo $i | awk -F : '{print$2}'`		
                if [ `ldd /$FILEP 2> /dev/null | grep "not found" -c` -gt 0 ]; then
                        SWAPME=1
                        ldd /$FILEP | grep "not found" | awk '{print$1}' | sort -u | sed -e 's/.*/'$PKG':&/' >> $CDIR/MISSINGDEPS.tmp 2>/dev/null
                fi
		if test $COUNTME -eq 4; then
			COUNTME=0
		else
			COUNTME=`expr $COUNTME + 1`
		fi
        done
        rm -f $CDIR/TARFILES.tmp
        if [ "$SWAPME" = "0" ]; then
		printf "\b\b\b\b\b\b\b\b\b\b\b"
                echo "Libraries resolved successfully!"
		logme "dependency_check()" "=> Verifying Dependencies... Libraries resolved sucessfully!"
		echo
		exit
        else
		CSWAP=0
		printf "\b\b\b\b\b\b\b\b\b\b\b"
                echo "Missing Libraries!"
		logme "dependency_check()" "=> Verifying Dependencies... Missing Libraries!"
		echo 
                if [ ! -f $CDIR/libraries-$VERSION.tmp ]; then
                        DROOTS=`cat /etc/swaret.conf 2>/dev/null | grep "^DEP_ROOT=" | sed s/'"'//\g | grep -v "#" | cut -f2 -d'='`
                        for i in $DROOTS
                        do
			  if test `echo $i | grep file: | wc -l` -ge 1; then
				MSG "dependency_check()" "[ $i ]"
				echo -n "### Copying Slackware Linux ($VERSION) libraries-$VERSION List File... "
				DEP_URL=`echo $i | sed s/'file:'//`
				cp $DEP_URL/libraries-$VERSION $CDIR/libraries-$VERSION.tmp 2>/dev/null
				if [ -f $CDIR/libraries-$VERSION.tmp ]; then
					echo "DONE!"
					logme "dependency_check()" "### Copying Slackware Linux ($VERSION) libraries-$VERSION List File... DONE!"
					break
				else
					echo "FAILED!"
					logme "dependency_check()" "### Copying Slackware Linux ($VERSION) libraries-$VERSION List File... FAILED!"
				fi
				CSWAP=1
			  else
				CSWAP=1
				MSG "dependency_check()" "[ $i ]"
				echo -n "### Fetching Slackware Linux ($VERSION) libraries-$VERSION List File... "
                                DEP_URL=`echo $i | sed s/'file:'//`
				if test `echo $DEP_URL | grep rsync: | wc -l` -ge 1
				then
					rsync --timeout=$TIMEOUT -q $DEP_URL/libraries-$VERSION $CDIR/libraries-$VERSION 2>/dev/null
				else
					wget $PF -t $RETRIES -T $TIMEOUT -q --directory-prefix=$CDIR $DEP_URL\libraries-$VERSION 2>/dev/null 
				fi
                        	if [ -f $CDIR/libraries-$VERSION ]; then
                                	mv $CDIR/libraries-$VERSION $CDIR/libraries-$VERSION.tmp 2>/dev/null
					if [ ! -z $Q ]; then
                                		echo "DONE!"
					fi
					logme "dependency_check()" "### Fetching Slackware Linux ($VERSION) libraries-$VERSION List File... DONE"
					break
                        	else
					if [ ! -z $Q ]; then
                                		echo "FAILED!"
					fi
					logme "dependency_check()" "### Fetching Slackware Linux ($VERSION) libraries-$VERSION List File... FAILED!"
				fi
			  fi
			done
                fi
		if test $CSWAP -eq 1; then
			echo
		fi
                MISSINGDEPENDENCIES=`cat $CDIR/MISSINGDEPS.tmp 2>/dev/null | sort -u`
                CSWAP=0
		SWAP=0
                for i in $MISSINGDEPENDENCIES
                do
			PKG=`echo $i | awk -F : '{print$1}'`
			LIB=`echo $i | awk -F : '{print$2}'`
			PACKAGE=`grep $LIB $CDIR/libraries-$VERSION.tmp 2>/dev/null | cut -f1 -d':' | sed s/'.tgz'/''/''`
                        if [ "$PACKAGE" = "" ]; then
                                MSG "dependency_check()" "% $LIB from $PKG not found!"
				logme "dependency_check()" "Search for $LIB, needed by $PKG"
				echo "Search for $LIB, needed by $PKG" >> $CDIR/MPKGS.list 2>/dev/null
				CSWAP=1
                        else
				SWAP=1
                                CSWAP=1
				RSWAP=0
				for x in $i
				do
					for z in $PACKAGE
					do
						SHORTME=`echo $z | sed -e s/-[0-9].*//`
						MSG "dependency_check()" "% $PKG ($LIB) requires at least $z!"
						if test `grep "$SHORTME-" $CDIR/.cache/CHECKSUMS 2>/dev/null | wc -l` -ge 1; then
							
							for M in `grep "$SHORTME-" $CDIR/.cache/CHECKSUMS 2>/dev/null | awk '{print$3}'`
							do
								basename $M >> $CDIR/MISSINGPACKAGES.tmp
							done
							RSWAP=1
						fi
						if test `grep "$SHORTME-" $CDIR/CHECKSUMS.patches 2>/dev/null | wc -l` -ge 1; then
							for M in `grep "$SHORTME-" $CDIR/.cache/CHECKSUMS.patches 2>/dev/null | awk '{print$3}'`
                                                        do
                                                                basename $M >> $CDIR/MISSINGPACKAGES.tmp
                                                        done
							RSWAP=1
						  fi
						if test `grep "$SHORTME-" $CDIR/CHECKSUMS.extra 2>/dev/null | wc -l` -ge 1; then
							for M in `grep "$SHORTME-" $CDIR/.cache/CHECKSUMS.extra 2>/dev/null | awk '{print$3}'`
                                                        do
                                                                basename $M >> $CDIR/MISSINGPACKAGES.tmp
                                                        done
							RSWAP=1
						fi
						if test $RSWAP -eq 0; then
							touch $CDIR/$z.omp 2>/dev/null
						fi
						RSWAP=0
					done
				done
                        fi
                done
		if test $CSWAP -eq 1; then
			if test $SWAP -eq 1; then
				echo
			fi
		fi
                rm -f $CDIR/MISSINGDEPS.tmp 2>/dev/null
                PACKAGES=`sort -u $CDIR/MISSINGPACKAGES.tmp 2>/dev/null`
                if [[ $SWAP = 1 ]]; then
			XDL=0
			SWAP=0
			for i in $PACKAGES
			do
                                iSHORT=`echo $i | sed s/'.tgz'//`
                                if [ ! -f $PACKAGES_LOGDIR/$iSHORT ]; then
				  if [[ "$DEP_REINSTALL" != "1" ]]; then
                                        XDL=1
				  fi
                                fi
			        if [[ "$DEP_REINSTALL" = "1" ]]; then
				    	XDL=1
 				fi
			done
			if test $XDL -eq 1; then
				if test `cat /etc/swaret.conf | grep -v "#" | grep "^ROOT=" | grep "file:" | wc -l` -ge 1; then
					echo "Making a List of available Packages to Copy..."
				else
					echo "Making a List of available Packages to Download..."
				fi
				z=0
				xCOUNTER=0
				zCOUNTER=0
				for i in $PACKAGES
				do
					xCOUNTER=`expr $xCOUNTER + 1`
				done
                                for i in $PACKAGES
                                do
					iSHORT=`echo $i | sed s/'.tgz'//`
					if [ ! -f $PACKAGES_LOGDIR/$iSHORT ]; then
					  if [[ "$DEP_REINSTALL" != "1" ]]; then
					    SIZEPKGTMP=`cat .cache/CHECKSUMS* 2>/dev/null | grep "x " | grep -v source | grep "/$i" | awk '{print$2}'`
					    SIZEPKG=`echo $SIZEPKGTMP / 1024 | bc`
						echo "$iSHORT ($SIZEPKG kB)  "
						zCOUNTER=`expr $zCOUNTER + 1`
						if [[ "$zCOUNTER" != "$xCOUNTER" ]]; then
							ls_break "Packages"
						fi
					  fi
					fi
				        if [[ "$DEP_REINSTALL" = "1" ]]; then
                                            SIZEPKGTMP=`cat .cache/CHECKSUMS* 2>/dev/null | grep "x " | grep -v source | grep "/$i" | awk '{print$2}'`
                                            SIZEPKG=`echo $SIZEPKGTMP / 1024 | bc`
                                                echo "$iSHORT ($SIZEPKG kB)  "
						zCOUNTER=`expr $zCOUNTER + 1`
						if [[ "$zCOUNTER" != "$xCOUNTER" ]]; then
                                                        ls_break "Packages"
                                                fi
					fi
				done
			fi
			echo
			if [[ "$DEP_REINSTALL" != "1" ]]; then  
                          for i in $PACKAGES
                          do
                             if test `cat /etc/swaret.conf 2>/dev/null | grep -v "#" | grep "^ROOT=" | grep "file:" | wc -l` -ge 1; then
                                DSHORTPKG=`echo $i | sed s/'.tgz'//`
				if test `cat .cache/CHECKSUMS.patches 2>/dev/null | grep "/$i" | wc -l` -ge 1; then
                                        if [ -f $PACKAGES_LOGDIR/$DSHORTPKG ]; then
					   if [ ! -f $CDIR/$DSHORTPKG.zmp ]; then
                                                MSG "dependency_check()" "Patch $DSHORTPKG is already installed!"
						touch $CDIR/$DSHORTPKG.xmp 2>/dev/null
                                                SWAP=1
						CSWAP=1
					   fi
                                        fi
                                fi
				if test `cat .cache/CHECKSUMS.extra 2>/dev/null | grep "/$i" | wc -l` -ge 1; then
                                        if [ -f $PACKAGES_LOGDIR/$DSHORTPKG ]; then
					   if [ ! -f $CDIR/$DSHORTPKG.zmp ]; then
                                                MSG "dependency_check()" "Extra Package $DSHORTPKG is already installed!"
						touch $CDIR/$DSHORTPKG.xmp 2>/dev/null
                                                SWAP=1
						CSWAP=1
					   fi
                                        fi
                                fi
				if test `cat .cache/CHECKSUMS 2>/dev/null | grep "/$i" | wc -l` -ge 1; then
                                        if [ -f $PACKAGES_LOGDIR/$DSHORTPKG ]; then
					   if [ ! -f $CDIR/$DSHORTPKG.zmp ]; then
                                                MSG "dependency_check()" "Package $DSHORTPKG is already installed!"
						touch $CDIR/$DSHORTPKG.xmp 2>/dev/null
						CSWAP=1
					   fi
                                        fi
                                fi
                             else
				DSHORTPKG=`echo $i | sed s/'.tgz'//`
				if test `cat .cache/CHECKSUMS.patches 2>/dev/null | grep "/$i" | wc -l` -ge 1; then
                                        if [ -f $PACKAGES_LOGDIR/$DSHORTPKG ]; then
					   if [ ! -f $CDIR/$DSHORTPKG.zmp ]; then
                                                MSG "dependency_check()" "Patch $DSHORTPKG is already installed!"
						touch $CDIR/$DSHORTPKG.xmp 2>/dev/null
                                                SWAP=1
					   fi
                                        fi
                                fi
				if test `cat .cache/CHECKSUMS.extra 2>/dev/null | grep "/$i" | wc -l` -ge 1; then
                                        if [ -f $PACKAGES_LOGDIR/$DSHORTPKG ]; then
					   if [ ! -f $CDIR/$DSHORTPKG.zmp ]; then
                                                MSG "dependency_check()" "Extra Package $DSHORTPKG is already installed!"
						touch $CDIR/$DSHORTPKG.xmp 2>/dev/null
                                                SWAP=1
					   fi
                                        fi
                                fi
				if test `cat .cache/CHECKSUMS 2>/dev/null | grep "/$i" | wc -l` -ge 1; then
                                        if [ -f $PACKAGES_LOGDIR/$DSHORTPKG ]; then
					   if [ ! -f $CDIR/$DSHORTPKG.zmp ]; then
                                                MSG "dependency_check()" "Package $DSHORTPKG is already installed!"
						touch $CDIR/$DSHORTPKG.xmp 2>/dev/null
					   fi
                                        fi
                                fi
                             fi
                          done
			fi
			if [[ "$DEP_REINSTALL" != "1" ]]; then
                          for i in $PACKAGES
                          do
			    DSHORTPKG=`echo $i | sed s/'.tgz'//`
			    if [ ! -f $REMOVED_PACKAGES_LOGDIR/$DSHORTPKG ]; then
			     if [ ! -f $PACKAGES_LOGDIR/$DSHORTPKG ]; then
                               if test `cat /etc/swaret.conf 2>/dev/null | grep -v "#" | grep "^ROOT=" | grep "file:" | wc -l` -ge 1; then
				if test `cat .cache/CHECKSUMS.patches 2>/dev/null | grep "/$i" | wc -l` -ge 1; then
                                        if [ ! -f $CDIR/$DSHORTPKG.xmp ]; then
                                                cget_pkg "$i" 
                                        fi
                                fi
				if test `cat .cache/CHECKSUMS.extra 2>/dev/null | grep "/$i" | wc -l` -ge 1; then
                                        if [ ! -f $CDIR/$DSHORTPKG.xmp ]; then
                                                cget_pkg "$i" 
                                        fi
                                fi
				if test `cat .cache/CHECKSUMS 2>/dev/null | grep "/$i" | wc -l` -ge 1; then
                                        if [ ! -f $CDIR/$DSHORTPKG.xmp ]; then
                                                cget_pkg "$i"
                                        fi
                                fi
                               else
				if test `cat .cache/CHECKSUMS.patches 2>/dev/null | grep "/$i" | wc -l` -ge 1; then
                                        if [ ! -f $CDIR/$DSHORTPKG.xmp ]; then
                                                dget_pkg "$i" 1 "-p"
                                        fi
                                fi
				if test `cat .cache/CHECKSUMS.extra 2>/dev/null | grep "/$i" | wc -l` -ge 1; then
                                        if [ ! -f $CDIR/$DSHORTPKG.xmp ]; then
                                                dget_pkg "$i" 1 "-e"
                                        fi
                                fi
				if test `cat .cache/CHECKSUMS 2>/dev/null | grep "/$i" | wc -l` -ge 1; then
                                        if [ ! -f $CDIR/$DSHORTPKG.xmp ]; then
                                                dget_pkg "$i" 1 "-a"
                                        fi
                                fi
                               fi
			     fi
			    fi
			  done
			else
                          for i in $PACKAGES
                          do
                             DSHORTPKG=`echo $i | sed s/'.tgz'//`
                               if test `cat /etc/swaret.conf 2>/dev/null | grep -v "#" | grep "^ROOT=" | grep "file:" | wc -l` -ge 1; then
                                if test `cat .cache/CHECKSUMS.patches 2>/dev/null | grep "/$i" | wc -l` -ge 1; then
                                        if [ ! -f $CDIR/$DSHORTPKG.xmp ]; then
                                                cget_pkg "$i"
                                        fi
                                fi
                                if test `cat .cache/CHECKSUMS.extra 2>/dev/null | grep "/$i" | wc -l` -ge 1; then
                                        if [ ! -f $CDIR/$DSHORTPKG.xmp ]; then
                                                cget_pkg "$i"
                                        fi
                                fi
                                if test `cat .cache/CHECKSUMS 2>/dev/null | grep "/$i" | wc -l` -ge 1; then
                                        if [ ! -f $CDIR/$DSHORTPKG.xmp ]; then
                                                cget_pkg "$i"
                                        fi
                                fi
                               else
                                if test `cat .cache/CHECKSUMS.patches 2>/dev/null | grep "/$i" | wc -l` -ge 1; then
                                        if [ ! -f $CDIR/$DSHORTPKG.xmp ]; then
                                                dget_pkg "$i" 1 "-p"
                                        fi
                                fi
                                if test `cat .cache/CHECKSUMS.extra 2>/dev/null | grep "/$i" | wc -l` -ge 1; then
                                        if [ ! -f $CDIR/$DSHORTPKG.xmp ]; then
                                                dget_pkg "$i" 1 "-e"
                                        fi
                                fi
                                if test `cat .cache/CHECKSUMS 2>/dev/null | grep "/$i" | wc -l` -ge 1; then
                                        if [ ! -f $CDIR/$DSHORTPKG.xmp ]; then
                                                dget_pkg "$i" 1 "-a"
                                        fi
                                fi
                               fi
                          done
			fi
			if [[ "$DEP_UPGRADE" = "1" ]]; then
			  if test `cat $CDIR/MISSINGPACKAGES.tmp 2>/dev/null | grep -v "dl$" | grep -v "rob$" | grep -v "mybuild$" | wc -l` -gt 0; then
			    IPKGS=`cat $CDIR/MISSINGPACKAGES.tmp 2>/dev/null | grep -v "dl$" | grep -v "rob$" | grep -v "mybuild$"`
                          else
                            IPKGS=""
                          fi
                          for i in $IPKGS
                          do
                                ISHORTPKG=`echo $i | sed s/'.tgz'//`
                                iTMP=`echo $i | sed s/'.tgz'// | sed -e "s/.*\///g" | sed -e s/-[0-9].*//`
                                APKGS=`cat CHECKSUMS 2>/dev/null | grep "/$iTMP" | sed s/'.tgz'// | sed -e "s/.*\///g"`
                                for x in $APKGS
                                do
				  EXSW=0
				  ONSW=0
                                  DSHORTPKG=`echo $x | sed s/'.tgz'//`
                                  SHORTXPKG=`echo $x | cut -f1 -d'-'`
                                  for e in `cat $CDIR/swaret.exclude 2>/dev/null | grep -v "#"`
                                  do
                                        if test `echo $x | grep $e | wc -l` -ge 1; then
                                                EXSW=1
                                        fi
                                  done
                                  if test $EXSW -eq 0; then
					xTMP=`echo $x | sed s/'.tgz'// | sed -e "s/.*\///g" | sed -e s/-[0-9].*//`
                                        aTMP=`echo $x | sed -e s/-[0-9].*//`
                                        if [[ "$iTMP" = "$aTMP" ]]; then
                                          if test `ls -alL $PACKAGES_LOGDIR/$xTMP-* 2>/dev/null | wc -l` -eq 1; then
                                                if test `ls $REMOVED_PACKAGES_LOGDIR/$i* 2>/dev/null | wc -l` -eq 0; then
                                                        if test `ls $REMOVED_PACKAGES_LOGDIR/$x* 2>/dev/null | wc -l` -eq 0; then
                                                                if [ ! -f $PACKAGES_LOGDIR/$x ]; then
								  SHORTxTMP=`ls -a $PACKAGES_LOGDIR/$xTMP-* | sed -e "s/.*\///g" 2>/dev/null`
                                                                  echo -n "=> Upgrading $SHORTxTMP -> $DSHORTPKG... "
								  check_size_pkg $x.tgz
								  if [ ! -f $x*.corrupted ]; then
                                                                  if [[ "$DESC" = "NO" ]]; then
                                                                    upgradepkg $CDIR/$x*.tgz >/dev/null 2>&1
                                                                     
                                                                  else
                                                                    upgradepkg $CDIR/$x*.tgz
								  fi
								  touch $CDIR/$x.tgz.imp 2>/dev/null
								  fi
                                                                  if [ -f $PACKAGES_LOGDIR/$DSHORTPKG ]; then
                                                                          echo "DONE!"
                                                                          logme "dependency_check()" "=> Upgrading $SHORTxTMP -> $DSHORTPKG... DONE!"
                                                                  else
                                                                          echo "FAILED!"
                                                                          logme "dependency_check()" "=> Upgrading $SHORTxTMP -> $DSHORTPKG... FAILED!"
                                                                  fi
                                                                  if [[ "$VDEPENDENCY" = "1" ]]; then
									tar tzfv $x.tgz 2>/dev/null | grep bin/ | awk '{print$6}' | sed -e 's/.*/'$i':&/' >> $CDIR/TARFILES.tmp
                                                                  fi
                                                                fi
                                                        fi
                                                fi
					  fi
                                        fi
				  fi
                                  for e in `cat $CDIR/swaret.only 2>/dev/null | grep -v "#"`
                                  do
                                        if test `echo $x | grep $e | wc -l` -ge 1; then
                                                ONSW=1
                                        fi
                                  done
                                  if test $ONSW -eq 1; then
                                        xTMP=`echo $x | sed s/'.tgz'// | sed -e "s/.*\///g" | sed -e s/-[0-9].*//`
                                        aTMP=`echo $x | sed -e s/-[0-9].*//`
                                        if [[ "$iTMP" = "$aTMP" ]]; then
                                          if test `ls -alL $PACKAGES_LOGDIR/$xTMP-* 2>/dev/null | wc -l` -eq 1; then
                                                if test `ls $REMOVED_PACKAGES_LOGDIR/$i* 2>/dev/null | wc -l` -eq 0; then
                                                        if test `ls $REMOVED_PACKAGES_LOGDIR/$x* 2>/dev/null | wc -l` -eq 0; then
                                                                if [ ! -f $PACKAGES_LOGDIR/$x ]; then
                                                                  SHORTxTMP=`ls -a $PACKAGES_LOGDIR/$xTMP-* | sed -e "s/.*\///g" 2>/dev/null`
                                                                  echo -n "=> Upgrading $SHORTxTMP -> $DSHORTPKG... "
								  check_size_pkg $x.tgz
								  if [ ! -f $x*.corrupted ]; then
                                                                  if [[ "$DESC" = "NO" ]]; then
                                                                    upgradepkg $CDIR/$x*.tgz >/dev/null 2>&1

                                                                  else
                                                                    upgradepkg $CDIR/$x*.tgz
                                                                  fi
								  touch $CDIR/$x.tgz.imp 2>/dev/null
								  fi
                                                                  if [ -f $PACKAGES_LOGDIR/$DSHORTPKG ]; then
                                                                          echo "DONE!"
                                                                          logme "dependency_check()" "=> Upgrading $SHORTxTMP -> $DSHORTPKG... DONE!"
                                                                  else
                                                                          echo "FAILED!"
                                                                          logme "dependency_check()" "=> Upgrading $SHORTxTMP -> $DSHORTPKG... FAILED!"
                                                                  fi
                                                                  if [[ "$VDEPENDENCY" == "1" ]]; then
                                                                        tar tzfv $x.tgz 2>/dev/null | grep bin/ | awk '{print$6}' | sed -e 's/.*/'$i':&/' >> $CDIR/TARFILES.tmp
                                                                  fi
                                                                fi
                                                        fi
                                                fi
                                          fi
                                        fi
				  fi
                                done
                          done
			fi
			if [[ "$DEP_REINSTALL" == "1" ]]; then  
                         	for i in $PACKAGES
                         	do
				  if [ ! -f $CDIR/$i.imp ]; then
				    DSHORTPKG=`echo $i | sed s/'.tgz'//`
				    if [ -f $PACKAGES_LOGDIR/$DSHORTPKG ]; then
                                                  if [[ "$DESC" = "NO" ]]; then
                                                       echo -n "=> Re-Installing $DSHORTPKG... "
						       check_size_pkg $i
                                                       if [ ! -f $i*.corrupted ]; then
                                                        if [[ "$DESC" = "NO" ]]; then
                                                                installpkg $i >/dev/null 2>&1
                                                        else
                                                                installpkg $i
                                                        fi
                                                        touch $CDIR/$i.imp 2>/dev/null
                                                       fi
                                                       if [ -f $PACKAGES_LOGDIR/$DSHORTPKG ]; then
                                                               echo "DONE!"
                                                               logme "dependency_check()" "=> Re-Installing $DSHORTPKG... DONE!"
                                                       else
                                                               echo "FAILED!"
                                                               logme "dependency_check()" "=> Re-Installing $DSHORTPKG... FAILED!"
                                                       fi
                                                       if [[ "$VDEPENDENCY" == "1" ]]; then
								tar tzfv $i 2>/dev/null | grep bin/ | awk '{print$6}' | sed -e 's/.*/'$i':&/' >> $CDIR/TARFILES.tmp
                                                       fi
                                                  else
                                                       echo -n "=> Re-Installing $DSHORTPKG... "
						       check_size_pkg $i
                                                       if [ ! -f $i*.corrupted ]; then
                                                        if [[ "$DESC" = "NO" ]]; then
                                                                installpkg $i >/dev/null 2>&1
                                                        else
                                                                installpkg $i
                                                        fi
                                                        touch $CDIR/$i.imp 2>/dev/null
                                                       fi
                                                       if [ -f $PACKAGES_LOGDIR/$DSHORTPKG ]; then
                                                               echo "DONE!"
                                                               logme "dependency_check()" "=> Re-Installing $DSHORTPKG... DONE!"
                                                       else
                                                               echo "FAILED!"
                                                               logme "dependency_check()" "=> Re-Installing $DSHORTPKG... FAILED!"
                                                       fi
                                                       if [[ "$VDEPENDENCY" == "1" ]]; then
								tar tzfv $i 2>/dev/null | grep bin/ | awk '{print$6}' | sed -e 's/.*/'$i':&/' >> $CDIR/TARFILES.tmp
                                                       fi
                                                  fi
                                                  if [ -f $i ]; then
							tar tzfv $i 2>/dev/null | awk '{print$6}' | sed -e 's/.*/'$i':&/' >> $CDIR/TARFILES.tmp
                                                  fi
				    fi
				  fi
                         	done
			fi
			if [[ "$DEP_INSTALL" == "1" ]]; then
                        for i in $PACKAGES
                        do
			  if [ ! -f $CDIR/$i.imp ]; then
                            DSHORTPKG=`echo $i | sed s/'.tgz'//`
                            if [ ! -f $REMOVED_PACKAGES_LOGDIR/$DSHORTPKG ]; then
                              if [ ! -f $PACKAGES_LOGDIR/$DSHORTPKG ]; then
				XSWAP=0
				if [ -f $PACKAGES_LOGDIR/$DSHORTPKG ]; then
					XSWAP=1	
				fi
				if test $XSWAP -eq 0; then
                                         if [ ! -f $CDIR/$i.imp ]; then
                                                  if [[ "$DESC" == "NO" ]]; then
                                                       echo -n "=> Installing $DSHORTPKG... "
						       check_size_pkg $i
                                                       if [ ! -f $i*.corrupted ]; then
                                                        if [[ "$DESC" = "NO" ]]; then
                                                                installpkg $i >/dev/null 2>&1
                                                        else
                                                                installpkg $i
                                                        fi
                                                       fi
                                                       if [ -f $PACKAGES_LOGDIR/$DSHORTPKG ]; then
                                                               echo "DONE!"
                                                               logme "dependency_check()" "=> Installing $DSHORTPKG... DONE!"
                                                       else
                                                               echo "FAILED!"
                                                               logme "dependency_check()" "=> Installing $DSHORTPKG... FAILED!"
                                                       fi
                                                       if [[ "$VDEPENDENCY" == "1" ]]; then
								tar tzfv $i 2>/dev/null | grep bin/ | awk '{print$6}' | sed -e 's/.*/'$i':&/' >> $CDIR/TARFILES.tmp
                                                       fi
                                                  else
                                                       echo -n "=> Installing $DSHORTPKG... "
						       check_size_pkg $i
                                                       if [ ! -f $i*.corrupted ]; then
                                                        if [[ "$DESC" = "NO" ]]; then
                                                                installpkg $i >/dev/null 2>&1
                                                        else
                                                                installpkg $i
                                                        fi
                                                       fi
                                                       if [ -f $PACKAGES_LOGDIR/$DSHORTPKG ]; then
                                                               echo "DONE!"
                                                               logme "dependency_check()" "=> Installing $DSHORTPKG... DONE!"
                                                       else
                                                               echo "FAILED!"
                                                               logme "dependency_check()" "=> Installing $DSHORTPKG... FAILED!"
                                                       fi
                                                       if [[ "$VDEPENDENCY" == "1" ]]; then
								tar tzfv $i 2>/dev/null | grep bin/ | awk '{print$6}' | sed -e 's/.*/'$i':&/' >> $CDIR/TARFILES.tmp
                                                       fi
                                                  fi
                                                  if [ -f $i ]; then
								tar tzfv $i 2>/dev/null | grep bin/ | awk '{print$6}' | sed -e 's/.*/'$i':&/' >> $CDIR/TARFILES.tmp
                                                  fi
                                         fi
				fi
			      fi
			    fi
			  fi
                        done
			fi
			PNF=0
			for i in *.omp
			do
			  DSHORTPKG=`echo $i | sed s/'.omp'//`			
			  IPKGCHECK=`echo $DSHORTPKG | sed -e "s/.*\///g" | sed -e s/-[0-9].*//`
			  if test `ls -alL $PACKAGES_LOGDIR/$IPKGCHECK-* 2>/dev/null | wc -l` -eq 1; then
				if [[ "$DEP_REINSTALL" != "1" ]]; then
					MSG "dependency_check()" "Package $DSHORTPKG is already installed!"
				fi
			  fi
			  if test `ls -alL $PACKAGES_LOGDIR/$IPKGCHECK-* 2>/dev/null | wc -l` -eq 0; then
                          	if [ -f $DSHORTPKG.omp ]; then
					MSG "dependency_check()" "$DSHORTPKG not found in the List Files!"
					MSG "dependency_check()" "=> Installing $DSHORTPKG... FAILED!"
					MSG "dependency_check()" "Search for $DSHORTPKG!"
					PNF=1
				fi
			  else
				if test `ls -alL $PACKAGES_LOGDIR/$IPKGCHECK-* 2>/dev/null | wc -l` -eq 1; then
                                   if [ -f $DSHORTPKG.omp ]; then
				     IPKG=`ls -a $PACKAGES_LOGDIR/$IPKGCHECK-* 2>/dev/null | sed -e "s/.*\///g"`
				     if [[ "$IPKG" == "$DSHORTPKG" ]]; then
					if [[ "$DEP_REINSTALL" == "1" ]]; then
                                          MSG "dependency_check()" "$DSHORTPKG not found in the List Files!"
                                          MSG "dependency_check()" "=> Re-Installing $DSHORTPKG... FAILED!"
					  MSG "dependency_check()" "Search for $DSHORTPKG!"
					  PNF=1
					fi
				     else
					if [[ "$DEP_UPGRADE" == "1" ]]; then
                                          MSG "dependency_check()" "$DSHORTPKG not found in the List Files!"
                                          MSG "dependency_check()" "=> Upgrading $IPKG -> $DSHORTPKG... FAILED!"
					  MSG "dependency_check()" "Search for $DSHORTPKG!"
                                          PNF=1
					else
                                          MSG "dependency_check()" "$DSHORTPKG not found in the List Files!"
                                          MSG "dependency_check()" "=> Installing $DSHORTPKG... FAILED!"
					  MSG "dependency_check()" "Search for $DSHORTPKG!"
					  PNF=1
					fi
                                     fi
                                   fi
				fi
                          fi
			done
			if test $PNF -eq 1; then
				echo
				echo "Please, Consult F.A.Q.!"
			fi
                fi
                if test `cat $CDIR/MPKGS.list 2>/dev/null | wc -l` -ge 1; then
                        echo
                        echo "Making a List of missing Packages..."
                        cat $CDIR/MPKGS.list 2>/dev/null | more
                        echo
                        echo "Please, Consult F.A.Q.!"
                fi
                rm -f $CDIR/MISSINGPACKAGES.tmp
        fi
	if [ -f $CDIR/TARFILES.tmp ]; then
		echo
		echo "% Recursive Dependency Check..."
		echo
         	dependency_check
	fi
	echo
}

dependency_interactive_check()
{
		rm -f *.mmx
		rm -f *.zzx
                FPKGSW=0
                FPKGTSIZE=0
                FPKGC=0

                        for i in `cat /etc/swaret.conf 2>/dev/null | grep "^ONLY" | grep -v "#" | sed s/'"'//\g | sed s/','/' '/\g | cut -f2 -d'='`
                        do
                                for x in $i
                                do
                                        echo $x >> $CDIR/swaret.only 2>/dev/null
                                done
                        done
                        for i in `cat /etc/swaret.conf 2>/dev/null | grep "^EXCLUDE" | grep -v "#" | sed s/'"'//\g | sed s/','/' '/\g | cut -f2 -d'='`
                        do
                                for x in $i
                                do
                                        echo $x >> $CDIR/swaret.exclude 2>/dev/null
                                done
                        done

                        dget_pkg()
                        {
                        SHORTPKG=`echo $1 | sed s/'.tgz'//`
                        if [ -f $1 ]; then
                                SIZEPKGTMP=`ls -alL $1 2>/dev/null | awk '{print$5}'`
                                SIZEPKG=`echo $SIZEPKGTMP / 1024 | bc`
                                TRIGVAR=""
                                if test `cat .cache/CHECKSUMS 2>/dev/null | grep "/$1" | wc -l` -ge 1; then
                                  cp .cache/CHECKSUMS $CDIR/CHECKSUMS 2>/dev/null
                                  TRIGVAR=slackware
                                fi
                                if test `cat .cache/CHECKSUMS.patches 2>/dev/null | grep "/$1" | wc -l` -ge 1; then
                                  cp .cache/CHECKSUMS.patches $CDIR/CHECKSUMS 2>/dev/null
                                  TRIGVAR=patches
                                fi
                                if test `cat .cache/CHECKSUMS.extra 2>/dev/null | grep "/$1" | wc -l` -ge 1; then
                                  cp .cache/CHECKSUMS.extra $CDIR/CHECKSUMS 2>/dev/null
                                  TRIGVAR=extra
                                fi
                                if [[ "$TRIGVAR" == "patches" ]]; then
                                        MSG "dget_pkg()" "Patch $SHORTPKG ($SIZEPKG kB) found in $CDIR!"
                                        check_for_broken_patches $1 1
                                fi
                                if [[ "$TRIGVAR" == "extra" ]]; then
                                        MSG "dget_pkg()" "Extra Package $SHORTPKG ($SIZEPKG kB) found in $CDIR!"
                                        check_for_broken_extra $1 1
                                fi
                                if [[ "$TRIGVAR" == "slackware" ]]; then
                                        MSG "dget_pkg()" "Package $SHORTPKG ($SIZEPKG kB) found in $CDIR!"
                                        check_for_broken_packages $1 1
                                fi
                        else
                                PACKAGES_URL=`cat URL 2>/dev/null | awk '{ if(NR == '$2') print $1 }'`
                                TRIGVAR=""
                                if test `cat .cache/CHECKSUMS.patches 2>/dev/null | grep "/$1" | wc -l` -ge 1; then
                                        PACKAGE=`cat .cache/CHECKSUMS.patches 2>/dev/null | grep "/$1" | awk '{ print$3 }' | grep "/" | sed s/.//`
                                        cp CHECKSUMS.patches CHECKSUMS 2>/dev/null
                                        TRIGVAR=patches
                                fi
                                if test `cat .cache/CHECKSUMS.extra 2>/dev/null | grep "/$1" | wc -l` -ge 1; then
                                        PACKAGE=`cat .cache/CHECKSUMS.extra 2>/dev/null | grep "/$1" | awk '{ print$3 }' | grep "/" | sed s/.//`
                                        cp CHECKSUMS.extra CHECKSUMS 2>/dev/null
                                        TRIGVAR=extra
                                fi
                                if test `cat .cache/CHECKSUMS 2>/dev/null | grep "/$1" | wc -l` -ge 1; then
                                        PACKAGE=`cat .cache/CHECKSUMS 2>/dev/null | grep "/$1" | grep / | awk '{ print$3 }' | sed s/.//`
                                        cp .cache/CHECKSUMS CHECKSUMS 2>/dev/null
                                        TRIGVAR=slackware
                                fi
                                SIZEPKGTMP=`cat CHECKSUMS 2>/dev/null | grep "/$1" | awk '{print$2}'`
                                SIZEPKG=`echo $SIZEPKGTMP / 1024 | bc`
                                if [ ! -z $PACKAGES_URL ]; then
                                        MSG "dget_pkg()" "[ $PACKAGES_URL ]"
                                        echo $QS "### Fetching $SHORTPKG ($SIZEPKG kB)... "
                                        if test `echo $PACKAGES_URL | grep rsync | wc -l` -ge 1
                                        then
                                            if [ ! -z $Q ]; then
							rsync_file "$PACKAGES_URL" "$PACKAGE"
                                                    if test `cat $CDIR/.cache/CHECKSUMS 2>/dev/null | grep "/$1" | wc -l` -ge 1; then
                                                        cp $CDIR/.cache/CHECKSUMS $CDIR/CHECKSUMS 2>/dev/null
                                                    fi
                                                    if test `cat $CDIR/.cache/CHECKSUMS.extra 2>/dev/null | grep "/$1" | wc -l` -ge 1; then
                                                        cp $CDIR/.cache/CHECKSUMS.extra $CDIR/CHECKSUMS 2>/dev/null
                                                    fi
                                                    if test `cat $CDIR/.cache/CHECKSUMS.patches 2>/dev/null| grep "/$1" | wc -l` -ge 1; then
                                                        cp $CDIR/.cache/CHECKSUMS.patches $CDIR/CHECKSUMS 2>/dev/null
                                                    fi
                                                    count_size_rsync $1 $3
                                            else
							rsync_file_s "$PACKAGES_URL" "$PACKAGE"
                                                    if test `ls -alL $CDIR/$1 2>/dev/null | wc -l` -eq 1; then
                                                        if test `ls -alL $CDIR/$1 2>/dev/null | awk '{print$5}'` -eq $SIZEPKGTMP
                                                        then
                                                            touch $1.tmp 2>/dev/null
                                                        else
                                                            rm -f $1.tmp 2>/dev/null
                                                        fi
                                                    else
                                                        rm -f $1.tmp 2>/dev/null
                                                    fi
                                            fi
                                        else
                                            if [ ! -z $Q ]; then
							wget_file "$PACKAGES_URL" "$PACKAGE"
                                                    if test `cat $CDIR/.cache/CHECKSUMS 2>/dev/null | grep "/$1" | wc -l` -ge 1; then
                                                        cp $CDIR/.cache/CHECKSUMS $CDIR/CHECKSUMS 2>/dev/null
                                                    fi
                                                    if test `cat $CDIR/.cache/CHECKSUMS.extra 2>/dev/null| grep "/$1" | wc -l` -ge 1; then
                                                        cp $CDIR/.cache/CHECKSUMS.extra $CDIR/CHECKSUMS 2>/dev/null
                                                    fi
                                                    if test `cat $CDIR/.cache/CHECKSUMS.patches 2>/dev/null | grep "/$1" | wc -l` -ge 1; then
                                                        cp $CDIR/.cache/CHECKSUMS.patches $CDIR/CHECKSUMS 2>/dev/null
                                                    fi
                                                    count_size $1 $3
                                            else
							wget_file_s "$PACKAGES_URL" "$PACKAGE"
                                                    if test `ls -alL $CDIR/$1 2>/dev/null | wc -l` -eq 1; then
                                                        if test `ls -alL $CDIR/$1 2>/dev/null | awk '{print$5}'` -eq $SIZEPKGTMP
                                                        then
                                                            touch $1.tmp 2>/dev/null
                                                        else
                                                            rm -f $1.tmp 2>/dev/null
                                                        fi
                                                    else
                                                        rm -f $1.tmp 2>/dev/null
						    fi
                                            fi
                                        fi
                                        if [ -f $1.tmp ]; then
                                                FPKGSW=1
                                                FPKGTSIZE=`echo "$FPKGTSIZE + $SIZEPKG" | bc`
                                                FPKGC=`echo "$FPKGC + 1" | bc`
                                                if [ ! -z $Q ]; then
                                                        echo " DONE!"
                                                fi
                                                logme "dget_pkg()" "### Fetching $SHORTPKG ($SIZEPKG kB)... DONE!"
                                                if test `cat .cache/CHECKSUMS.patches 2>/dev/null | grep "/$1" | wc -l` -ge 1; then
                                                        checksum_patch $1
							GETPKG="$PACKAGE"
							pgp_check_remote "dependency_interactive_check()" "-p" "-ap" "$1"
                                                fi
                                                if test `cat .cache/CHECKSUMS.extra 2>/dev/null | grep "/$1" | wc -l` -ge 1; then
                                                        checksum_extra $1
							GETPKG="$PACKAGE"
							pgp_check_remote "dependency_interactive_check()" "-e" "-ae" "$1"
                                                fi
                                                if test `cat .cache/CHECKSUMS 2>/dev/null | grep "/$1" | wc -l` -ge 1; then
                                                        checksum_package $1
							GETPKG="$PACKAGE"
							pgp_check_remote "dependency_interactive_check()" "-a" "-a" "$1"
                                                fi
                                                DONE=0
                                        else
                                                if [ ! -z $Q ]; then
                                                        echo " FAILED!"
                                                fi
                                                logme "dget_pkg()" "### Fetching $SHORTPKG ($SIZEPKG kB)... FAILED!"
                                                rm -f $1.tmp 2>/dev/null
                                                RECORDS=`cat URL 2>/dev/null | wc -l`
                                                        COUNTER=`expr $COUNTER + 1`
                                                        if test $COUNTER -ne `expr $RECORDS + 1`
                                                        then
                                                                dget_pkg $1 $COUNTER $3
                                                        fi
                                        fi
                                        DONE=0
                                fi
                        fi
                        }

                        cget_pkg()
                        {
                              SHORTPKG=`echo $1 | sed s/'.tgz'//`
                              if [ ! -f $1 ]; then
				ROOTS=`cat /etc/swaret.conf | grep -v "#" | grep "^ROOT=" | grep "file:" | cut -f2 -d'=' | sed s/'file:'//`
				for RR in $ROOTS
				do
                                  TRIGVAR=""
                                  if test `cat .cache/CHECKSUMS.patches 2>/dev/null | grep "/$1" | wc -l` -ge 1; then
                                        PACKAGE=`cat .cache/CHECKSUMS.patches 2>/dev/null | grep "/$1" | awk '{print$3}' | grep "/" | sed s/.//`
                                        TRIGVAR=patches
                                  fi
                                  if test `cat .cache/CHECKSUMS.extra 2>/dev/null | grep "/$1" | wc -l` -ge 1; then
                                        PACKAGE=`cat .cache/CHECKSUMS.extra 2>/dev/null | grep "/$1" | awk '{print$3}' | grep "/" | sed s/.//`
                                        TRIGVAR=extra
                                  fi
                                  if test `cat .cache/CHECKSUMS 2>/dev/null | grep "/$1" | wc -l` -ge 1; then
                                        PACKAGE=`cat .cache/CHECKSUMS 2>/dev/null | grep "/$1" | grep / | awk '{print$3}' | sed s/.//`
                                        TRIGVAR=slackware
                                  fi
                                  if [ ! -z $RR ]; then
                                        SIZEPKGTMP=`cat CHECKSUMS 2>/dev/null | grep "/$1" | awk '{print$2}'`
                                        SIZEPKG=`echo $SIZEPKGTMP / 1024 | bc`
                                        MSG "dependency_interactive_check()" "[ file:$RR ]"
                                        echo -n "### Copying $SHORTPKG ($SIZEPKG kB)... "
                                        if test `cat .cache/CHECKSUMS.patches 2>/dev/null | grep "/$1" | wc -l` -ge 1; then
						copy_file "$RR" "$PACKAGE"
                                        fi
                                        if test `cat .cache/CHECKSUMS.extra 2>/dev/null | grep "/$1" | wc -l` -ge 1; then
						copy_file "$RR" "$PACKAGE"
                                        fi
                                        if test `cat .cache/CHECKSUMS 2>/dev/null | grep "/$1" | wc -l` -ge 1; then
						copy_file "$RR" "$PACKAGE"
                                        fi
                                        if [ -f $1 ]; then
                                                echo "DONE!"
                                                logme "dependency_interactive_check()" "### Copying $SHORTPKG ($SIZEPKG kB)... DONE!"
                                                if test `cat .cache/CHECKSUMS.patches 2>/dev/null | grep "/$1" | wc -l` -ge 1; then
                                                        checksum_patch $1
							pgp_check_local "dependency_interactive_check()" "-p" "-ap" "$1"
                                                fi
                                                if test `cat .cache/CHECKSUMS.extra 2>/dev/null | grep "/$1" | wc -l` -ge 1; then
                                                        checksum_extra $1
							pgp_check_local "dependency_interactive_check()" "-e" "-ae" "$1"
                                                fi
                                                if test `cat .cache/CHECKSUMS 2>/dev/null | grep "/$1" | wc -l` -ge 1; then
                                                        checksum_package $1
							pgp_check_local "dependency_interactive_check()" "-a" "-a" "$1"
                                                fi
                                                DONE=0
						break
                                        else
                                                echo "FAILED!"
                                                logme "dependency_interactive_check()" "### Copying $SHORTPKG ($SIZEPKG kB)... FAILED!"
                                        fi
                                  else
                                        SIZEPKGTMP=`cat CHECKSUMS 2>/dev/null | grep "/$1" | awk '{print$2}'`
                                        SIZEPKG=`echo $SIZEPKGTMP / 1024 | bc`
                                        MSG "dependency_interactive_check()" "### Copying $SHORTPKG ($SIZEPKG kB)... FAILED!"
                                  fi
				done
                              else
                                        SIZEPKGTMP=`cat CHECKSUMS 2>/dev/null | grep "/$1" | awk '{print$2}'`
                                        SIZEPKG=`echo $SIZEPKGTMP / 1024 | bc`
                                        if test `cat .cache/CHECKSUMS.patches 2>/dev/null | grep "/$1" | wc -l` -ge 1; then
                                                MSG "dependency_interactive_check()" "Patch $SHORTPKG ($SIZEPKG kB) found in $CDIR!"
                                                res_local_pat $1
                                        fi
                                        if test `cat .cache/CHECKSUMS.extra 2>/dev/null | grep "/$1" | wc -l` -ge 1; then
                                                MSG "dependency_interactive_check()" "Extra Package $SHORTPKG ($SIZEPKG kB) found in $CDIR!"
                                                res_local_ext $1
                                        fi
                                        if test `cat .cache/CHECKSUMS 2>/dev/null | grep "/$1" | wc -l` -ge 1; then
                                                MSG "dependency_interactive_check()" "Package $SHORTPKG ($SIZEPKG kB) found in $CDIR!"
                                                res_local_pac $1
                                        fi
                              fi
                          }

        CSWAP=0
        if [[ "$WARNINGS" == "1" ]]; then
                echo "WARNING: This will take some time. Be patient!"
                echo
        fi
        echo -n "%%% Verifying Dependencies... "
        TARFILES=`cat $CDIR/TARFILES.tmp 2>/dev/null`
        TARFILESN=`cat $CDIR/TARFILES.tmp 2>/dev/null | wc -l`
        echo -n "+++++++++++"
        COUNTER=0
        SWAPME=0
        COUNTME=0
        for i in 0 1 2 3 4 5 6 7 8 9
        do
                PSWAP[$i]=0
        done
        for i in $TARFILES
        do                COUNTER=`expr $COUNTER + 1`
                TCOUNTER=`expr $COUNTER \* 10 / $TARFILESN`
                if test $TCOUNTER -ge 0; then
                        if test $TCOUNTER -le 10; then
                                case $TCOUNTER in
                                        "0")
                                                if test ${PSWAP[0]} -eq 0; then
                                                        printf "\b "
                                                        PSWAP[0]=1;
                                                fi
                                                ;;
                                        "1")
                                                if test ${PSWAP[1]} -eq 0; then
                                                        printf "\b\b  "
                                                        PSWAP[1]=1;
                                                fi
                                                ;;
                                        "2")
                                                if test ${PSWAP[2]} -eq 0; then
                                                        printf "\b\b\b   "
                                                        PSWAP[2]=1;
                                                fi
                                                ;;
                                        "3")
                                                if test ${PSWAP[3]} -eq 0; then
                                                        printf "\b\b\b\b    "
                                                        PSWAP[3]=1;
                                                fi
                                                ;;
                                        "4")
                                                if test ${PSWAP[4]} -eq 0; then
                                                        printf "\b\b\b\b\b     "
                                                        PSWAP[4]=1;
                                                fi
                                                ;;
                                        "5")
                                                if test ${PSWAP[5]} -eq 0; then
                                                        printf "\b\b\b\b\b\b      "
                                                        PSWAP[5]=1;
                                                fi
                                                ;;
                                        "6")
                                                if test ${PSWAP[6]} -eq 0; then
                                                        printf "\b\b\b\b\b\b\b       "
                                                        PSWAP[6]=1;
                                                fi
                                                ;;
                                        "7")
                                                if test ${PSWAP[7]} -eq 0; then
                                                        printf "\b\b\b\b\b\b\b\b        "
                                                        PSWAP[7]=1;
                                                fi
                                                ;;
                                        "8")
                                                if test ${PSWAP[8]} -eq 0; then
                                                        printf "\b\b\b\b\b\b\b\b\b         "
                                                        PSWAP[8]=1;
                                                fi
                                                ;;
                                        "9")
                                                if test ${PSWAP[9]} -eq 0; then
                                                        printf "\b\b\b\b\b\b\b\b\b\b          "
                                                        PSWAP[9]=1;
                                                fi
                                                ;;
                                esac
                        fi
                fi
                if test $COUNTME -eq 0; then
                        printf "\b\\"
                fi
                if test $COUNTME -eq 1; then
                        printf "\b|"
                fi
                if test $COUNTME -eq 2; then
                        printf "\b/"
                fi
                if test $COUNTME -eq 3; then
                        printf "\b-"
                fi
                PKG=`echo $i | awk -F : '{print $1}' | sed s/'.tgz'//`
                FILEP=`echo $i | awk -F : '{print$2}'`
                if [ `ldd /$FILEP 2> /dev/null | grep "not found" -c` -gt 0 ]; then
                        SWAPME=1
                        ldd /$FILEP | grep "not found" | awk '{print$1}' | sort -u | sed -e 's/.*/'$PKG':&/' >> $CDIR/MISSINGDEPS.tmp 2>/dev/null
                fi
                if test $COUNTME -eq 4; then
                        COUNTME=0
                else
                        COUNTME=`expr $COUNTME + 1`
                fi
        done
        rm -f $CDIR/TARFILES.tmp 2>/dev/null
        if [ "$SWAPME" = "0" ]; then
                printf "\b\b\b\b\b\b\b\b\b\b\b"
                echo "Libraries resolved successfully!"
                logme "dependency_interactive_check()" "=> Verifying Dependencies... Libraries resolved sucessfully!"
                echo
                exit
        else
                CSWAP=0
                printf "\b\b\b\b\b\b\b\b\b\b\b"
                echo "Missing Libraries!"
                logme "dependency_interactive_check()" "=> Verifying Dependencies... Missing Libraries!"
                echo
                if [ ! -f $CDIR/libraries-$VERSION.tmp ]; then
                        DROOTS=`cat /etc/swaret.conf 2>/dev/null | grep "^DEP_ROOT=" | sed s/'"'//\g | grep -v "#" | cut -f2 -d'='
`
                        for i in $DROOTS
                        do
                          if test `echo $i | grep file: | wc -l` -ge 1; then
                                MSG "dependency_interactive_check()" "[ $i ]"
                                echo -n "### Copying Slackware Linux ($VERSION) libraries-$VERSION List File... "
                                DEP_URL=`echo $i | sed s/'file:'//`
                                cp $DEP_URL/libraries-$VERSION $CDIR/libraries-$VERSION.tmp 2>/dev/null
                                if [ -f $CDIR/libraries-$VERSION.tmp ]; then
                                        echo "DONE!"
                                        logme "dependency_check()" "### Copying Slackware Linux ($VERSION) libraries-$VERSION List File... DONE!"
					break
                                else
                                        echo "FAILED!"
                                        logme "dependency_check()" "### Copying Slackware Linux ($VERSION) libraries-$VERSION List File... FAILED!"
                                fi
				CSWAP=1
                          else
                                CSWAP=1
                                MSG "dependency_interactive_check()" "[ $i ]"
                                echo -n "### Fetching Slackware Linux ($VERSION) libraries-$VERSION List File... "
                                DEP_URL=`echo $i | sed s/'file:'//`
                                if test `echo $DEP_URL | grep rsync: | wc -l` -ge 1
                                then
                                        rsync --timeout=$TIMEOUT -q $DEP_URL/libraries-$VERSION $CDIR/libraries-$VERSION 2>/dev/null
                                else
                                        wget $PF -t $RETRIES -T $TIMEOUT -q --directory-prefix=$CDIR $DEP_URL\libraries-$VERSION 2>/dev/null 
                                fi
                                if [ -f $CDIR/libraries-$VERSION ]; then
                                        mv $CDIR/libraries-$VERSION $CDIR/libraries-$VERSION.tmp 2>/dev/null
                                        if [ ! -z $Q ]; then
                                                echo "DONE!"
                                        fi
                                        logme "dependency_interactive_check()" "### Fetching Slackware Linux ($VERSION) libraries-$VERSION List File... DONE"
                                        break
                                else
                                        if [ ! -z $Q ]; then
                                                echo "FAILED!"
                                        fi
                                        logme "dependency_interactive_check()" "### Fetching Slackware Linux ($VERSION) libraries-$VERSION List File... FAILED!"
                                fi
			  fi
                        done
                fi
                if test $CSWAP -eq 1; then
                        echo
                fi
                MISSINGDEPENDENCIES=`cat $CDIR/MISSINGDEPS.tmp 2>/dev/null | sort -u`
                CSWAP=0
                SWAP=0
                for i in $MISSINGDEPENDENCIES
                do
                        PKG=`echo $i | awk -F : '{print$1}'`
                        LIB=`echo $i | awk -F : '{print$2}'`
                        PACKAGE=`grep $LIB $CDIR/libraries-$VERSION.tmp 2>/dev/null | cut -f1 -d':' | sed s/'.tgz'/''/''`
                        if [ "$PACKAGE" = "" ]; then
                                MSG "dependency_interactive_check()" "% $LIB from $PKG not found!"
                                logme "dependency_interactive_check()" "Search for $LIB, needed by $PKG"
                                echo "Search for $LIB, needed by $PKG" >> $CDIR/MPKGS.list 2>/dev/null
                                CSWAP=1
                        else
                                SWAP=1
                                CSWAP=1
                                RSWAP=0
                                for x in $i
                                do
                                        for z in $PACKAGE
                                        do
                                                SHORTME=`echo $z | sed -e s/-[0-9].*//`
                                                MSG "dependency_interactive_check()" "% $PKG ($LIB) requires at least $z!"
                                                if test `grep "$SHORTME-" $CDIR/.cache/CHECKSUMS 2>/dev/null | wc -l` -ge 1; then

                                                        for M in `grep "$SHORTME-" $CDIR/.cache/CHECKSUMS 2>/dev/null | awk '{print$3}'`
                                                        do
                                                                basename $M >> $CDIR/MISSINGPACKAGES.tmp 2>/dev/null
                                                        done
                                                        RSWAP=1
                                                fi
                                                if test `grep "$SHORTME-" $CDIR/CHECKSUMS.patches 2>/dev/null | wc -l` -ge 1; then
                                                        for M in `grep "$SHORTME-" $CDIR/.cache/CHECKSUMS.patches 2>/dev/null | awk '{print$3}'`
                                                        do
                                                                basename $M >> $CDIR/MISSINGPACKAGES.tmp 2>/dev/null
                                                        done
                                                        RSWAP=1
                                                  fi
                                                if test `grep "$SHORTME-" $CDIR/CHECKSUMS.extra 2>/dev/null | wc -l` -ge 1; then
                                                        for M in `grep "$SHORTME-" $CDIR/.cache/CHECKSUMS.extra 2>/dev/null | awk '{print$3}'`
                                                        do
                                                                basename $M >> $CDIR/MISSINGPACKAGES.tmp 2>/dev/null
                                                        done
                                                        RSWAP=1
                                                fi
                                                if test $RSWAP -eq 0; then
                                                        touch $CDIR/$z.omp 2>/dev/null
                                                fi
                                                RSWAP=0
                                        done
                                done
                        fi
                done
                if test $CSWAP -eq 1; then
                        if test $SWAP -eq 1; then
                                echo
                        fi
                fi
                rm -f $CDIR/MISSINGDEPS.tmp 2>/dev/null
                PACKAGES=`sort -u $CDIR/MISSINGPACKAGES.tmp 2>/dev/null`
                if [[ $SWAP = 1 ]]; then
                        XDL=0
                        SWAP=0
                        for i in $PACKAGES
                        do
                                iSHORT=`echo $i | sed s/'.tgz'//`
                                if [ ! -f $PACKAGES_LOGDIR/$iSHORT ]; then
                                  if [[ "$DEP_REINSTALL" != "1" ]]; then
                                        XDL=1
                                  fi
                                fi
                                if [[ "$DEP_REINSTALL" == "1" ]]; then
                                        XDL=1
                                fi
                        done
                        if test $XDL -eq 1; then
                                if test `cat /etc/swaret.conf | grep -v "#" | grep "^ROOT=" | grep "file:" | wc -l` -ge 1; then
                                        echo "Making a List of available Packages to Copy..."
                                else
                                        echo "Making a List of available Packages to Download..."
                                fi
                                z=0
                                xCOUNTER=0
                                zCOUNTER=0
                                for i in $PACKAGES
                                do
                                        xCOUNTER=`expr $xCOUNTER + 1`
                                done
                                for i in $PACKAGES
                                do
                                        iSHORT=`echo $i | sed s/'.tgz'//`
                                        if [ ! -f $PACKAGES_LOGDIR/$iSHORT ]; then
                                          if [[ "$DEP_REINSTALL" != "1" ]]; then
                                            SIZEPKGTMP=`cat .cache/CHECKSUMS* 2>/dev/null | grep "x " | grep -v source | grep "/$i" | awk '{print$2}'`
                                            SIZEPKG=`echo $SIZEPKGTMP / 1024 | bc`
                                                echo "$iSHORT ($SIZEPKG kB)  "
                                                zCOUNTER=`expr $zCOUNTER + 1`
						if [[ "$zCOUNTER" != "$xCOUNTER" ]]; then
                                                        ls_break "Packages"
                                                fi
                                          fi
                                        fi
                                        if [[ "$DEP_REINSTALL" == "1" ]]; then
                                            SIZEPKGTMP=`cat .cache/CHECKSUMS* 2>/dev/null | grep "x " | grep -v source | grep "/$i" | awk '{print$2}'`
                                            SIZEPKG=`echo $SIZEPKGTMP / 1024 | bc`
                                                echo "$iSHORT ($SIZEPKG kB)  "
                                                zCOUNTER=`expr $zCOUNTER + 1`
						if [[ "$zCOUNTER" != "$xCOUNTER" ]]; then
                                                        ls_break "Packages"
                                                fi
                                        fi
                                done
                        fi
			echo 
                        if [[ "$DEP_REINSTALL" != "1" ]]; then
                          for i in $PACKAGES
                          do
                             if test `cat /etc/swaret.conf 2>/dev/null | grep -v "#" | grep "^ROOT=" | grep "file:" | wc -l` -eq 1; then
                                DSHORTPKG=`echo $i | sed s/'.tgz'//`
                                if test `cat .cache/CHECKSUMS.patches 2>/dev/null | grep "/$i" | wc -l` -ge 1; then
                                        if [ -f $PACKAGES_LOGDIR/$DSHORTPKG ]; then
                                           if [ ! -f $CDIR/$DSHORTPKG.zmp ]; then
                                                MSG "dependency_interactive_check()" "Patch $DSHORTPKG is already installed!"
                                                touch $CDIR/$DSHORTPKG.xmp 2>/dev/null
                                                SWAP=1
                                                CSWAP=1
                                           fi
                                        fi
                                fi
                                if test `cat .cache/CHECKSUMS.extra 2>/dev/null | grep "/$i" | wc -l` -ge 1; then
                                        if [ -f $PACKAGES_LOGDIR/$DSHORTPKG ]; then
                                           if [ ! -f $CDIR/$DSHORTPKG.zmp ]; then
                                                MSG "dependency_interactive_check()" "Extra Package $DSHORTPKG is already installed!"
                                                touch $CDIR/$DSHORTPKG.xmp 2>/dev/null
                                                SWAP=1
                                                CSWAP=1
                                           fi
                                        fi
                                fi
                                if test `cat .cache/CHECKSUMS 2>/dev/null | grep "/$i" | wc -l` -ge 1; then
                                        if [ -f $PACKAGES_LOGDIR/$DSHORTPKG ]; then
						if [ ! -f $CDIR/$DSHORTPKG.zmp ]; then
                                                MSG "dependency_interactive_check()" "Package $DSHORTPKG is already installed!"
                                                touch $CDIR/$DSHORTPKG.xmp 2>/dev/null
                                                CSWAP=1
                                           fi
                                        fi
                                fi
                             else
                                DSHORTPKG=`echo $i | sed s/'.tgz'//`
                                if test `cat .cache/CHECKSUMS.patches 2>/dev/null | grep "/$i" | wc -l` -ge 1; then
                                        if [ -f $PACKAGES_LOGDIR/$DSHORTPKG ]; then
                                           if [ ! -f $CDIR/$DSHORTPKG.zmp ]; then
                                                MSG "dependency_interactive_check()" "Patch $DSHORTPKG is already installed!"
                                                touch $CDIR/$DSHORTPKG.xmp 2>/dev/null
                                                SWAP=1
                                           fi
                                        fi
                                fi
                                if test `cat .cache/CHECKSUMS.extra 2>/dev/null | grep "/$i" | wc -l` -ge 1; then
                                        if [ -f $PACKAGES_LOGDIR/$DSHORTPKG ]; then
                                           if [ ! -f $CDIR/$DSHORTPKG.zmp ]; then
                                                MSG "dependency_interactive_check()" "Extra Package $DSHORTPKG is already installed!"
                                                touch $CDIR/$DSHORTPKG.xmp 2>/dev/null
                                                SWAP=1
                                           fi
                                        fi
                                fi
                                if test `cat .cache/CHECKSUMS 2>/dev/null | grep "/$i" | wc -l` -ge 1; then
                                        if [ -f $PACKAGES_LOGDIR/$DSHORTPKG ]; then
                                           if [ ! -f $CDIR/$DSHORTPKG.zmp ]; then
                                                MSG "dependency_interactive_check()" "Package $DSHORTPKG is already installed!"
                                                touch $CDIR/$DSHORTPKG.xmp 2>/dev/null
                                           fi
                                        fi
                                fi
                             fi
                          done
                        fi
			rm -f $CDIR/DPKGLIST.list 2>/dev/null
                        if [[ "$DEP_UPGRADE" == "1" ]]; then
                          if test `cat $CDIR/MISSINGPACKAGES.tmp 2>/dev/null | grep -v "dl$" | grep -v "rob$" | grep -v "mybuild$" | wc -l` -gt 0; then
                            IPKGS=`cat $CDIR/MISSINGPACKAGES.tmp 2>/dev/null | grep -v "dl$" | grep -v "rob$" | grep -v "mybuild$"`
                          else
                            IPKGS=""
                          fi
                          for i in $IPKGS
                          do
                                ISHORTPKG=`echo $i | sed s/'.tgz'//`
                                iTMP=`echo $i | sed s/'.tgz'// | sed -e "s/.*\///g" | sed -e s/-[0-9].*//`
                                APKGS=`cat CHECKSUMS 2>/dev/null | grep "/$iTMP" | sed s/'.tgz'// | sed -e "s/.*\///g"`
                                for x in $APKGS
                                do
				  EXSW=0
				  ONSW=0
				  DSHORTPKG=`echo $x | sed s/'.tgz'//`
				  SHORTXPKG=`echo $x | cut -f1 -d'-'`
				  for e in `cat $CDIR/swaret.exclude 2>/dev/null | grep -v "#"`
				  do
					if test `echo $x | grep $e | wc -l` -ge 1; then
						EXSW=1
					fi
				  done
				  if test $EXSW -eq 0; then
 				    if [ ! -f $DSHORTPKG.mmx ]; then
                                        xTMP=`echo $x | sed s/'.tgz'// | sed -e "s/.*\///g" | sed -e s/-[0-9].*//`
                                        aTMP=`echo $x | sed -e s/-[0-9].*//`
                                        if [[ "$iTMP" == "$aTMP" ]]; then
                                          if test `ls -alL $PACKAGES_LOGDIR/$xTMP-* 2>/dev/null | wc -l` -eq 1; then
                                                if test `ls $REMOVED_PACKAGES_LOGDIR/$i* 2>/dev/null | wc -l` -eq 0; then
                                                        if test `ls $REMOVED_PACKAGES_LOGDIR/$x* 2>/dev/null | wc -l` -eq 0; then
                                                                if [ ! -f $PACKAGES_LOGDIR/$x ]; then
                                                                  SHORTxTMP=`ls -a $PACKAGES_LOGDIR/$xTMP-* | sed -e "s/.*\///g" 2>/dev/null`
								  echo -n "Upgrade $SHORTxTMP to $DSHORTPKG? (y/n): [y]"
								  read answer
 								  if [ -z "$answer" ]; then
									answer="y"
									touch $DSHORTPKG.zzx 2>/dev/null
								  else
									if [[ "$answer" != "y" ]]; then
										answer="n"
									else
										touch $DSHORTPKG.zzx 2>/dev/null
									fi
								  fi
								  touch $DSHORTPKG.mmx 2>/dev/null
								  case $answer in
									"y")
										echo "$DSHORTPKG.tgz" >> DPKGSLIST.list 2>/dev/null
										;;
									"n")
										;;
                                                        		*)
										invalid_charz
                                                                		;;	
								  esac
                                                                  touch $CDIR/$x.tgz.imp 2>/dev/null
                                                                fi
                                                        fi
                                                fi
                                          fi
                                        fi
				    fi
				  fi
                                  for e in `cat $CDIR/swaret.only 2>/dev/null | grep -v "#"`
                                  do
                                        if test `echo $x | grep $e | wc -l` -ge 1; then
                                                ONSW=1
                                        fi
                                  done
				  if test $ONSW -eq 1; then
                                    if [ ! -f $DSHORTPKG.mmx ]; then
                                        xTMP=`echo $x | sed s/'.tgz'// | sed -e "s/.*\///g" | sed -e s/-[0-9].*//`
                                        aTMP=`echo $x | sed -e s/-[0-9].*//`
                                        if [[ "$iTMP" == "$aTMP" ]]; then
                                          if test `ls -alL $PACKAGES_LOGDIR/$xTMP-* 2>/dev/null | wc -l` -eq 1; then
                                                if test `ls $REMOVED_PACKAGES_LOGDIR/$i* 2>/dev/null | wc -l` -eq 0; then
                                                        if test `ls $REMOVED_PACKAGES_LOGDIR/$x* 2>/dev/null | wc -l` -eq 0; then
                                                                if [ ! -f $PACKAGES_LOGDIR/$x ]; then
                                                                  SHORTxTMP=`ls -a $PACKAGES_LOGDIR/$xTMP-* | sed -e "s/.*\///g" 2>/dev/null`
								  echo -n "Upgrade $SHORTxTMP to $DSHORTPKG? (y/n): [y]"
                                                                  read answer
                                                                  if [ -z "$answer" ]; then
                                                                        answer="y"
                                                                        touch $DSHORTPKG.zzx 2>/dev/null
                                                                  else
                                                                        if [[ "$answer" != "y" ]]; then
                                                                                answer="n"
                                                                        else
                                                                                touch $DSHORTPKG.zzx 2>/dev/null
                                                                        fi
                                                                  fi
                                                                  touch $DSHORTPKG.mmx 2>/dev/null
                                                                  case $answer in
                                                                        "y")
                                                                                echo "$DSHORTPKG.tgz" >> DPKGSLIST.list 2>/dev/null
                                                                                ;;
                                                                        "n")
                                                                                ;;
                                                                        *)
										invalid_charz
                                                                                ;;
                                                                  esac
                                                                  touch $CDIR/$x.tgz.imp 2>/dev/null
                                                                fi
                                                        fi
                                                fi
                                          fi
                                        fi
                                    fi
                                  fi
                                done
                          done
                        fi
                        if [[ "$DEP_REINSTALL" == "1" ]]; then
                                for i in $PACKAGES
                                do
                                  DSHORTPKG=`echo $i | sed s/'.tgz'//`
				  if [ ! -f $DSHORTPKG.mmx ]; then
                                    if [ -f $PACKAGES_LOGDIR/$DSHORTPKG ]; then
                                                                  echo -n "Re-Install $DSHORTPKG? (y/n): [y]"
                                                                  read answer
                                                                  if [ -z "$answer" ]; then
                                                                        answer="y"
									touch $DSHORTPKG.zzx 2>/dev/null
                                                                  else
                                                                        if [[ "$answer" != "y" ]]; then
                                                                                answer="n"
									else
										touch $DSHORTPKG.zzx 2>/dev/null
                                                                        fi
                                                                  fi
								  touch $DSHORTPKG.mmx 2>/dev/null
                                                                  case $answer in
                                                                        "y")
                                                                                echo "$DSHORTPKG.tgz" >> DPKGSLIST.list 2>/dev/null
                                                                                ;;
                                                                        "n")
                                                                                ;;
                                                                        *)
										invalid_charz
                                                                                ;;      
                                                                  esac
				    fi
                                  fi
                                done
                        fi
			if [[ "$DEP_INSTALL" == "1" ]]; then
                        for i in $PACKAGES
                        do
                          DSHORTPKG=`echo $i | sed s/'.tgz'//`
                          if [ ! -f $DSHORTPKG.mmx ]; then
                            if [ ! -f $REMOVED_PACKAGES_LOGDIR/$DSHORTPKG ]; then
                              if [ ! -f $PACKAGES_LOGDIR/$DSHORTPKG ]; then
                                XSWAP=0
                                if [ -f $PACKAGES_LOGDIR/$DSHORTPKG ]; then
                                        XSWAP=1
                                fi
                                if test $XSWAP -eq 0; then
                                         if [ ! -f $CDIR/$i.imp ]; then 
                                           if [ ! -f $PACKAGES_LOGDIR/$DSHORTPKG ]; then
                                                                  echo -n "Install $DSHORTPKG? (y/n): [y]"
                                                                  read answer
                                                                  if [ -z "$answer" ]; then
                                                                        answer="y"
									touch $DSHORTPKG.zzx 2>/dev/null
                                                                  else
                                                                        if [[ "$answer" != "y" ]]; then
                                                                                answer="n"
									else
										touch $DSHORTPKG.zzx 2>/dev/null
                                                                        fi
                                                                  fi
								  touch $DSHORTPKG.mmx 2>/dev/null
                                                                  case $answer in
                                                                        "y")
                                                                                echo "$DSHORTPKG.tgz" >> DPKGSLIST.list 2>/dev/null
                                                                                ;;
                                                                        "n")
                                                                                ;;
                                                                        *)
										invalid_charz
                                                                                ;;      
                                                                  esac
                                           fi
                                         fi
                               fi
                             fi
                           fi
                          fi
                        done
			fi
			PACKAGES=`cat $CDIR/DPKGSLIST.list 2>/dev/null | uniq | sort 2>/dev/null`
                        if [[ "$DEP_REINSTALL" != "1" ]]; then
                          for i in $PACKAGES
                          do
                            DSHORTPKG=`echo $i | sed s/'.tgz'//`
                            if [ ! -f $REMOVED_PACKAGES_LOGDIR/$DSHORTPKG ]; then
                             if [ ! -f $PACKAGES_LOGDIR/$DSHORTPKG ]; then
                               if test `cat /etc/swaret.conf 2>/dev/null | grep -v "#" | grep "^ROOT=" | grep "file:" | wc -l` -ge 1; then
                                if test `cat .cache/CHECKSUMS.patches 2>/dev/null | grep "/$i" | wc -l` -ge 1; then
                                        if [ ! -f $CDIR/$DSHORTPKG.xmp ]; then
                                                cget_pkg "$i"
                                        fi
                                fi
                                if test `cat .cache/CHECKSUMS.extra 2>/dev/null | grep "/$i" | wc -l` -ge 1; then
                                        if [ ! -f $CDIR/$DSHORTPKG.xmp ]; then
                                                cget_pkg "$i" 
                                        fi
                                fi
                                if test `cat .cache/CHECKSUMS 2>/dev/null | grep "/$i" | wc -l` -ge 1; then
                                        if [ ! -f $CDIR/$DSHORTPKG.xmp ]; then
                                                cget_pkg "$i"
                                        fi
                                fi
                               else
                                if test `cat .cache/CHECKSUMS.patches 2>/dev/null | grep "/$i" | wc -l` -ge 1; then
                                        if [ ! -f $CDIR/$DSHORTPKG.xmp ]; then
                                                dget_pkg "$i" 1 "-p"
                                        fi
                                fi
                                if test `cat .cache/CHECKSUMS.extra 2>/dev/null | grep "/$i" | wc -l` -ge 1; then
                                        if [ ! -f $CDIR/$DSHORTPKG.xmp ]; then
                                                dget_pkg "$i" 1 "-e"
                                        fi
                                fi
                                if test `cat .cache/CHECKSUMS 2>/dev/null | grep "/$i" | wc -l` -ge 1; then
                                        if [ ! -f $CDIR/$DSHORTPKG.xmp ]; then
                                                dget_pkg "$i" 1 "-a"
                                        fi
                                fi
                               fi
                             fi
                            fi
                          done
                        else
                          for i in $PACKAGES
                          do
                             DSHORTPKG=`echo $i | sed s/'.tgz'//`
                               if test `cat /etc/swaret.conf 2>/dev/null | grep -v "#" | grep "^ROOT=" | grep "file:" | wc -l` -ge 1; then
                                if test `cat .cache/CHECKSUMS.patches 2>/dev/null | grep "/$i" | wc -l` -ge 1; then
                                        if [ ! -f $CDIR/$DSHORTPKG.xmp ]; then
                                                cget_pkg "$i"
                                        fi
                                fi
                                if test `cat .cache/CHECKSUMS.extra 2>/dev/null | grep "/$i" | wc -l` -ge 1; then
                                        if [ ! -f $CDIR/$DSHORTPKG.xmp ]; then
                                                cget_pkg "$i"
                                        fi
                                fi
                                if test `cat .cache/CHECKSUMS 2>/dev/null | grep "/$i" | wc -l` -ge 1; then
                                        if [ ! -f $CDIR/$DSHORTPKG.xmp ]; then
                                                cget_pkg "$i"
                                        fi
                                fi
                               else
                                if test `cat .cache/CHECKSUMS.patches 2>/dev/null | grep "/$i" | wc -l` -ge 1; then
                                        if [ ! -f $CDIR/$DSHORTPKG.xmp ]; then
                                                dget_pkg "$i" 1 "-p"
                                        fi
                                fi
                                if test `cat .cache/CHECKSUMS.extra 2>/dev/null | grep "/$i" | wc -l` -ge 1; then
                                        if [ ! -f $CDIR/$DSHORTPKG.xmp ]; then
                                                dget_pkg "$i" 1 "-e"
                                        fi
                                fi
                                if test `cat .cache/CHECKSUMS 2>/dev/null | grep "/$i" | wc -l` -ge 1; then
                                        if [ ! -f $CDIR/$DSHORTPKG.xmp ]; then
                                                dget_pkg "$i" 1 "-a"
                                        fi
                                fi
                               fi
                          done
                        fi
                        if [[ "$DEP_UPGRADE" == "1" ]]; then
                          if test `cat $CDIR/MISSINGPACKAGES.tmp 2>/dev/null | grep -v "dl$" | grep -v "rob$" | grep -v "mybuild$" | wc -l` -gt 0; then
                            IPKGS=`cat $CDIR/MISSINGPACKAGES.tmp 2>/dev/null | grep -v "dl$" | grep -v "rob$" | grep -v "mybuild$"`
                          else
                            IPKGS=""
                          fi
                          for i in $IPKGS
                          do
                                ISHORTPKG=`echo $i | sed s/'.tgz'//`
                                iTMP=`echo $i | sed s/'.tgz'// | sed -e "s/.*\///g" | sed -e s/-[0-9].*//`
                                APKGS=`cat CHECKSUMS 2>/dev/null | grep "/$iTMP" | sed s/'.tgz'// | sed -e "s/.*\///g"`
                                for x in $APKGS
                                do
				   DSHORTPKG=`echo $x | sed s/'.tgz'//`
                                   if [ -f $DSHORTPKG.zzx ]; then
                                        xTMP=`echo $x | sed s/'.tgz'// | sed -e "s/.*\///g" | sed -e s/-[0-9].*//`
                                        aTMP=`echo $x | sed -e s/-[0-9].*//`
                                        if [[ "$iTMP" == "$aTMP" ]]; then
                                          if test `ls -alL $PACKAGES_LOGDIR/$xTMP-* 2>/dev/null | wc -l` -eq 1; then
                                                if test `ls $REMOVED_PACKAGES_LOGDIR/$i* 2>/dev/null | wc -l` -eq 0; then
                                                        if test `ls $REMOVED_PACKAGES_LOGDIR/$x* 2>/dev/null | wc -l` -eq 0; then
                                                                if [ ! -f $PACKAGES_LOGDIR/$x ]; then
                                                                  SHORTxTMP=`ls -a $PACKAGES_LOGDIR/$xTMP-* | sed -e "s/.*\///g" 2>/dev/null`
                                                                  echo -n "=> Upgrading $SHORTxTMP -> $DSHORTPKG... "
								  check_size_pkg $x.tgz
								  if [ ! -f $x*.corrupted ]; then
                                                                  if [[ "$DESC" = "NO" ]]; then
                                                                    upgradepkg $CDIR/$x*.tgz >/dev/null 2>&1

                                                                  else
                                                                    upgradepkg $CDIR/$x*.tgz
                                                                  fi
								  touch $CDIR/$x.tgz.imp 2>/dev/null 
								  fi
                                                                  if [ -f $PACKAGES_LOGDIR/$DSHORTPKG ]; then
                                                                          echo "DONE!"
                                                                          logme "dependency_interactive_check()" "=> Upgrading $SHORTxTMP -> $DSHORTPKG... DONE!"
                                                                  else
                                                                          echo "FAILED!"
                                                                          logme "dependency_interactive_check()" "=> Upgrading $SHORTxTMP -> $DSHORTPKG... FAILED!"
                                                                  fi
                                                                  if [[ "$VDEPENDENCY" == "1" ]]; then
                                                                        tar tzfv $x.tgz 2>/dev/null | grep bin/ | awk '{print$6}' | sed -e 's/.*/'$i':&/' >> $CDIR/TARFILES.tmp
                                                                  fi
                                                                fi
                                                        fi
                                                fi
                                          fi
                                        fi
				   fi
                                done
                          done
                        fi
                        if [[ "$DEP_REINSTALL" == "1" ]]; then  
                                for i in $PACKAGES
                                do
                                   DSHORTPKG=`echo $i | sed s/'.tgz'//`
                                   if [ -f $DSHORTPKG.zzx ]; then
                                     if [ -f $PACKAGES_LOGDIR/$DSHORTPKG ]; then
                                       if [ ! -f $CDIR/$i.imp ]; then
                                                  if [[ "$DESC" = "NO" ]]; then
                                                       echo -n "=> Re-Installing $DSHORTPKG... "
						       check_size_pkg $i
                                                       if [ ! -f $i*.corrupted ]; then
                                                        if [[ "$DESC" = "NO" ]]; then
                                                                installpkg $i >/dev/null 2>&1
                                                        else
                                                                installpkg $i
                                                        fi
							touch $CDIR/$i.imp 2>/dev/null
                                                       fi
                                                       if [ -f $PACKAGES_LOGDIR/$DSHORTPKG ]; then
                                                               echo "DONE!"
                                                               logme "dependency_interactive_check()" "=> Re-Installing $DSHORTPKG... DONE!"
                                                       else
                                                               echo "FAILED!"
                                                               logme "dependency_interactive_check()" "=> Re-Installing $DSHORTPKG... FAILED!"
                                                       fi
                                                       if [[ "$VDEPENDENCY" == "1" ]]; then
                                                                tar tzfv $i 2>/dev/null | grep bin/ | awk '{print$6}' | sed -e 's/.*/'$i':&/' >> $CDIR/TARFILES.tmp
                                                       fi
                                                  else
                                                       echo -n "=> Re-Installing $DSHORTPKG... "
						       check_size_pkg $i
                                                       if [ ! -f $i*.corrupted ]; then
                                                        if [[ "$DESC" = "NO" ]]; then
                                                                installpkg $i >/dev/null 2>&1
                                                        else
                                                                installpkg $i
                                                        fi
                                                        touch $CDIR/$i.imp 2>/dev/null
                                                       fi
                                                       if [ -f $PACKAGES_LOGDIR/$DSHORTPKG ]; then
                                                               echo "DONE!"
                                                               logme "dependency_interactive_check()" "=> Re-Installing $DSHORTPKG... DONE!"
                                                       else
                                                               echo "FAILED!"
                                                               logme "dependency_interactive_check()" "=> Re-Installing $DSHORTPKG... FAILED!"
                                                       fi
                                                       if [[ "$VDEPENDENCY" == "1" ]]; then
                                                                tar tzfv $i 2>/dev/null | grep bin/ | awk '{print$6}' | sed -e 's/.*/'$i':&/' >> $CDIR/TARFILES.tmp
                                                       fi
                                                  fi
                                                  if [ -f $i ]; then
                                                        tar tzfv $i 2>/dev/null | awk '{print$6}' | sed -e 's/.*/'$i':&/' >> $CDIR/TARFILES.tmp
                                                  fi
				      fi
                                    fi
				  fi
                                done
                        fi
			if [[ "$DEP_INSTALL" = "1" ]]; then
                        for i in $PACKAGES
                        do
                          DSHORTPKG=`echo $i | sed s/'.tgz'//`
                          if [ -f $DSHORTPKG.zzx ]; then
                            if [ ! -f $REMOVED_PACKAGES_LOGDIR/$DSHORTPKG ]; then
                              if [ ! -f $PACKAGES_LOGDIR/$DSHORTPKG ]; then
				if [ ! -f $CDIR/$i.imp ]; then
                                  XSWAP=0
                                  if [ -f $PACKAGES_LOGDIR/$DSHORTPKG ]; then
                                        XSWAP=1 
                                  fi
                                  if test $XSWAP -eq 0; then
                                         if [ ! -f $CDIR/$i.imp ]; then
                                                  if [[ "$DESC" = "NO" ]]; then
                                                       echo -n "=> Installing $DSHORTPKG... "
						       check_size_pkg $i
                                                       if [ ! -f $i*.corrupted ]; then
                                                        if [[ "$DESC" = "NO" ]]; then
                                                                installpkg $i >/dev/null 2>&1
                                                        else
                                                                installpkg $i
                                                        fi
                                                       fi
                                                       if [ -f $PACKAGES_LOGDIR/$DSHORTPKG ]; then
                                                               echo "DONE!"
                                                               logme "dependency_interactive_check()" "=> Installing $DSHORTPKG... DONE!"
                                                       else
                                                               echo "FAILED!"
                                                               logme "dependency_interactive_check()" "=> Installing $DSHORTPKG... FAILED!"
                                                       fi
                                                       if [[ "$VDEPENDENCY" == "1" ]]; then
                                                                tar tzfv $i 2>/dev/null | grep bin/ | awk '{print$6}' | sed -e 's/.*/'$i':&/' >> $CDIR/TARFILES.tmp
                                                       fi
                                                  else
                                                       echo -n "=> Installing $DSHORTPKG... "
						       check_size_pkg $i
                                                       if [ ! -f $i*.corrupted ]; then
                                                        if [[ "$DESC" = "NO" ]]; then
                                                                installpkg $i >/dev/null 2>&1
                                                        else
                                                                installpkg $i
                                                        fi
                                                       fi
                                                       if [ -f $PACKAGES_LOGDIR/$DSHORTPKG ]; then
                                                               echo "DONE!"
                                                               logme "dependency_interactive_check()" "=> Installing $DSHORTPKG... DONE!"
                                                       else
                                                               echo "FAILED!"
                                                               logme "dependency_interactive_check()" "=> Installing $DSHORTPKG... FAILED!"
                                                       fi
                                                       if [[ "$VDEPENDENCY" == "1" ]]; then
                                                                tar tzfv $i 2>/dev/null | grep bin/ | awk '{print$6}' | sed -e 's/.*/'$i':&/' >> $CDIR/TARFILES.tmp
                                                       fi
                                                  fi
                                                  if [ -f $i ]; then
                                                                tar tzfv $i 2>/dev/null | grep bin/ | awk '{print$6}' | sed -e 's/.*/'$i':&/' >> $CDIR/TARFILES.tmp
                                                  fi
                                         fi
				 fi
                               fi
			     fi
                           fi
                          fi
                        done
			fi
                        PNF=0
                        for i in *.omp
                        do
                          DSHORTPKG=`echo $i | sed s/'.omp'//`                        
                          IPKGCHECK=`echo $DSHORTPKG | sed -e "s/.*\///g" | sed -e s/-[0-9].*//`
                          if test `ls -alL $PACKAGES_LOGDIR/$IPKGCHECK-* 2>/dev/null | wc -l` -eq 1; then
                                if [[ "$DEP_REINSTALL" != "1" ]]; then
                                        MSG "dependency_interactive_check()" "Package $DSHORTPKG is already installed!"
                                fi
                          fi
                          if test `ls -alL $PACKAGES_LOGDIR/$IPKGCHECK-* 2>/dev/null | wc -l` -eq 0; then
                                if [ -f $DSHORTPKG.omp ]; then
                                        MSG "dependency_interactive_check()" "$DSHORTPKG not found in the List Files!"
                                        MSG "dependency_interactive_check()" "=> Installing $DSHORTPKG... FAILED!"
                                        MSG "dependency_interactive_check()" "Search for $DSHORTPKG!"
                                        PNF=1
                                fi
                          else
                                if test `ls -alL $PACKAGES_LOGDIR/$IPKGCHECK-* 2>/dev/null | wc -l` -eq 1; then
                                   if [ -f $DSHORTPKG.omp ]; then
                                     IPKG=`ls -a $PACKAGES_LOGDIR/$IPKGCHECK-* 2>/dev/null | sed -e "s/.*\///g"`
                                     if [[ "$IPKG" == "$DSHORTPKG" ]]; then
                                        if [[ "$DEP_REINSTALL" == "1" ]]; then
                                          MSG "dependency_interactive_check()" "$DSHORTPKG not found in the List Files!"
                                          MSG "dependency_interactive_check()" "=> Re-Installing $DSHORTPKG... FAILED!"
                                          MSG "dependency_interactive_check()" "Search for $DSHORTPKG!"
                                          PNF=1
                                        fi
                                     else
                                        if [[ "$DEP_UPGRADE" == "1" ]]; then
                                          MSG "dependency_interactive_check()" "$DSHORTPKG not found in the List Files!"
                                          MSG "dependency_interactive_check()" "=> Upgrading $IPKG -> $DSHORTPKG... FAILED!"
                                          MSG "dependency_interactive_check()" "Search for $DSHORTPKG!"
                                          PNF=1
                                        else
                                          MSG "dependency_interactive_check()" "$DSHORTPKG not found in the List Files!"
                                          MSG "dependency_interactive_check()" "=> Installing $DSHORTPKG... FAILED!"
                                          MSG "dependency_interactive_check()" "Search for $DSHORTPKG!"
                                          PNF=1
                                        fi
                                     fi
                                   fi
                                fi
                          fi
                        done
                        if test $PNF -eq 1; then
                                echo
                                echo "Please, Consult F.A.Q.!"
                        fi
                fi
                if test `cat $CDIR/MPKGS.list 2>/dev/null | wc -l` -ge 1; then
                        echo
                        echo "Making a List of missing Packages..."
                        cat $CDIR/MPKGS.list 2>/dev/null | more
                        echo
                        echo "Please, Consult F.A.Q.!"
                fi
                rm -f $CDIR/MISSINGPACKAGES.tmp
        fi
        if [ -f $CDIR/TARFILES.tmp ]; then
                echo
                echo "% Recursive Dependency Check..."
                echo
                dependency_interactive_check
        fi
        echo
}

pgp_check_remote()
{
                        if [[ "$PGPCHECK" = "1" ]]; then                               
			  if [ ! -f $CDIR/$SHORTPKG.pgp.lock ]; then
                                ACTION="$1"
                                SARG2="$2"
                                SARG3="$3"
				PGPROOTS=`cat /etc/swaret.conf 2>/dev/null | grep "^ROOT=" | sed s/'"'//\g | grep -v "#" | cut -f2 -d'='`
				for PGPR in $PGPROOTS
				do
				  MSG "pgp_check_remote()" "[ $PGPR ]"
				  echo -n "### Fetching $SHORTPKG PGP Signature... "
                                  if test `echo $PGPR | grep rsync | wc -l` -ge 1
                                  then
                                        rsync --timeout=$TIMEOUT $Q $PGPR/$GETPKG.asc . 2>/dev/null
                                  else
                                        wget $PF -t $RETRIES -T $TIMEOUT $Q $PGPR/$GETPKG.asc 2>/dev/null
                                  fi
				  if [ -f $SHORTPKG.tgz.asc ]; then
					echo "DONE!"
					break
				  else
					echo "FAILED!"
				  fi
				done
                                if [ -f $SHORTPKG.tgz.asc ]; then
                                        logme "$ACTION" "### Fetching $SHORTPKG PGP Signature... DONE!"
                                        echo -n "=> Verifying $SHORTPKG PGP Signature... "
                                        if test `gpg --verify $SHORTPKG.tgz.asc $SHORTPKG.tgz 2>&1 | grep CRC | wc -l` -eq 1; then
                                                echo "DONE!"
                                                logme "$ACTION" "=> Verifying $SHORTPKG PGP Signature... DONE!"
                                                PGPSWAP=0
                                                if [[ "$SARG2" = "-p" || "$SARG2" = "-ap" || "$SARG3" = "-p" || "$SARG3" = "-ap" ]]; then
                                                  MSG "$ACTION" "=> <PGPCHECK> Patch $SHORTPKG is CORRUPTED!"
						  touch $CDIR/$4.corrupted 2>/dev/null
                                                  PGPSWAP=1
                                                fi
                                                if [[ "$SARG2" = "-e" || "$SARG2" = "-ae" || "$SARG3" = "-e" || "$SARG3" = "-ae" ]]; then
						  MSG "$ACTION" "=> <PGPCHECK> Extra Package $SHORTPKG is CORRUPTED!"
						  touch $CDIR/$4.corrupted 2>/dev/null
                                                  PGPSWAP=1
                                                fi
                                                if test $PGPSWAP -eq 0; then
						  MSG "$ACTION" "=> <PGPCHECK> Package $SHORTPKG is CORRUPTED!"
						  touch $CDIR/$4.corrupted 2>/dev/null
                                                fi
                                        else
						echo "DONE!"
                                                logme "$ACTION" "=> Verifying $SHORTPKG PGP Signature... DONE!"
                                                PGPSWAP=0
                                                if [[ "$SARG2" = "-p" || "$SARG2" = "-ap" || "$SARG3" = "-p" || "$SARG3" = "-ap" ]]; then
                                                  MSG "$ACTION" "=> <PGPCHECK> Patch $SHORTPKG is OK!"
						  touch $CDIR/$SHORTPKG.pgp.lock 2>/dev/null
                                                  PGPSWAP=1
                                                fi
                                                if [[ "$SARG2" = "-e" || "$SARG2" = "-ae" || "$SARG3" = "-e" || "$SARG3" = "-ae" ]]; then
                                                  MSG "$ACTION" "=> <PGPCHECK> Extra Package $SHORTPKG is OK!"
						  touch $CDIR/$SHORTPKG.pgp.lock 2>/dev/null
                                                  PGPSWAP=1
                                                fi
                                                if test $PGPSWAP -eq 0; then
                                                  MSG "$ACTION" "=> <PGPCHECK> Package $SHORTPKG is OK!"
						  touch $CDIR/$SHORTPKG.pgp.lock 2>/dev/null
                                                fi
                                        fi
                                else
                                        logme "$ACTION" "### Fetching $SHORTPKG PGP Signature... FAILED!"
                                        logme "$ACTION" "=> Verifying $SHORTPKG PGP Signature... FAILED!"
                                        PGPSWAP=0
                                        if [[ "$SARG2" = "-p" || "$SARG2" = "-ap" || "$SARG3" = "-p" || "$SARG3" = "-ap" ]]; then
                                          MSG "$ACTION" "=> PGP Signature Check for Patch $SHORTPKG... SKIPPED!"
					  touch $CDIR/$SHORTPKG.pgp.lock 2>/dev/null
                                          PGPSWAP=1
                                        fi
                                        if [[ "$SARG2" = "-e" || "$SARG2" = "-ae" || "$SARG3" = "-e" || "$SARG3" = "-ae" ]]; then
                                          MSG "$ACTION" "=> PGP Signature Check for Extra Package $SHORTPKG... SKIPPED!"
					  touch $CDIR/$SHORTPKG.pgp.lock 2>/dev/null
                                          PGPSWAP=1
                                        fi
                                        if test $PGPSWAP -eq 0; then
                                          MSG "$ACTION" "=> PGP Signature Check for Package $SHORTPKG... SKIPPED!"
					  touch $CDIR/$SHORTPKG.pgp.lock 2>/dev/null
                                        fi
                                fi
			  fi
                        fi
}

pgp_check_local()
{
                        if [[ "$PGPCHECK" = "1" ]]; then   
			  if [ ! -f $CDIR/$SHORTPKG.pgp.lock ]; then
                                ACTION="$1"
                                SARG2="$2"
                                SARG3="$3"          
                                PGPROOTS=`cat /etc/swaret.conf | grep -v "#" | grep "^ROOT=" | grep "file:" | cut -f2 -d'=' | sed s/'file:'//`
                                for PGPR in $PGPROOTS
                                do                
                                  MSG "pgp_check_remote()" "[ file:$PGPR ]"
                                  echo -n "### Copying $SHORTPKG PGP Signature... "
                                  cp $PGPR/$PACKAGE.asc . 2>/dev/null
				  if [ -f $SHORTPKG.tgz.asc ]; then
					echo "DONE!"
					break
				  else
					echo "FAILED!"
				  fi
                                done            
                                if [ -f $SHORTPKG.tgz.asc ]; then
                                        logme "$ACTION" "### Copying $SHORTPKG PGP Signature... DONE!"
                                        echo -n "=> Verifying $SHORTPKG PGP Signature... "
                                        if test `gpg --verify $SHORTPKG.tgz.asc $SHORTPKG.tgz 2>&1 | grep CRC | wc -l` -eq 1; then
                                                echo "DONE!"
                                                logme "$ACTION" "=> Verifying $SHORTPKG PGP Signature... DONE!"
                                                PGPSWAP=0
                                                if [[ "$2" = "-p" || "$2" = "-ap" || "$3" = "-p" || "$3" = "-ap" ]]; then
						  MSG "$ACTION" "=> <PGPCHECK> Patch $SHORTPKG is CORRUPTED!"
						  touch $CDIR/$4.corrupted 2>/dev/null
                                                  PGPSWAP=1
                                                fi
                                                if [[ "$2" = "-e" || "$2" = "-ae" || "$3" = "-e" || "$3" = "-ae" ]]; then
						  MSG "$ACTION" "=> <PGPCHECK> Extra Package $SHORTPKG is CORRUPTED!"
						  touch $CDIR/$4.corrupted 2>/dev/null
                                                  PGPSWAP=1
                                                fi
                                                if test $PGPSWAP -eq 0; then
						  MSG "$ACTION" "=> <PGPCHECK> Package $SHORTPKG is CORRUPTED!"
						  touch $CDIR/$4.corrupted 2>/dev/null
                                                fi
                                        else
						echo "DONE!"
                                                logme "$ACTION" "=> Verifying $SHORTPKG PGP Signature... DONE!"
                                                PGPSWAP=0
                                                if [[ "$2" = "-p" || "$2" = "-ap" || "$3" = "-p" || "$3" = "-ap" ]]; then
                                                  MSG "$ACTION" "=> <PGPCHECK> Patch $SHORTPKG is OK!"
						  touch $CDIR/$SHORTPKG.pgp.lock 2>/dev/null
                                                  PGPSWAP=1
                                                fi
                                                if [[ "$2" = "-e" || "$2" = "-ae" || "$3" = "-e" || "$3" = "-ae" ]]; then
                                                  MSG "$ACTION" "=> <PGPCHECK> Extra Package $SHORTPKG is OK!"
						  touch $CDIR/$SHORTPKG.pgp.lock 2>/dev/null
                                                  PGPSWAP=1
                                                fi
                                                if test $PGPSWAP -eq 0; then
                                                  MSG "$ACTION" "=> <PGPCHECK> Package $SHORTPKG is OK!"
						  touch $CDIR/$SHORTPKG.pgp.lock 2>/dev/null
                                                fi
                                        fi
                                else
                                        logme "$ACTION" "### Copying $SHORTPKG PGP Signature... FAILED!"
                                        logme "$ACTION" "=> Verifying $SHORTPKG PGP Signature... FAILED!"
                                        PGPSWAP=0
                                        if [[ "$2" = "-p" || "$2" = "-ap" || "$3" = "-p" || "$3" = "-ap" ]]; then
                                          MSG "$ACTION" "=> PGP Signature Check for Patch $SHORTPKG... SKIPPED!"
					  touch $CDIR/$SHORTPKG.pgp.lock 2>/dev/null
                                          PGPSWAP=1
                                        fi
                                        if [[ "$2" = "-e" || "$2" = "-ae" || "$3" = "-e" || "$3" = "-ae" ]]; then
                                          MSG "$ACTION" "=> PGP Signature Check for Extra Package $SHORTPKG... SKIPPED!"
					  touch $CDIR/$SHORTPKG.pgp.lock 2>/dev/null
                                          PGPSWAP=1
                                        fi
                                        if test $PGPSWAP -eq 0; then
                                          MSG "$ACTION" "=> PGP Signature Check for Package $SHORTPKG... SKIPPED!"
					  touch $CDIR/$SHORTPKG.pgp.lock 2>/dev/null
                                        fi
                                fi
			  fi
                        fi
}

upgradefromoldtonewi()
{
  TMPxSizeTMP=`cat $CDIR/CHECKSUMS 2>/dev/null | grep "/$x.tgz" | awk '{ print$2 }'`
  TMPxSize=`echo "$TMPxSizeTMP / 1024" | bc`
  echo "! New: $x ($TMPxSize kB) - Installed: $i"
  echo "$x.tgz" >> NEWPKGS.list 2>/dev/null
  echo "$i" >> INSTALLEDPKGS.list 2>/dev/null
  touch $x.tmp
}

upgradefromoldtonew()
{
  TMPxSizeTMP=`cat $CDIR/CHECKSUMS 2>/dev/null | grep "/$x.tgz" | awk '{ print$2 }'`
  TMPxSize=`echo "$TMPxSizeTMP / 1024" | bc`
  echo "New: $x ($TMPxSize kB) - Installed: $i"
  echo "$x.tgz" >> NEWPKGS.list 2>/dev/null
  echo "$i" >> INSTALLEDPKGS.list 2>/dev/null
  touch $x.tmp
}

ls_break()
{
                                        z=`expr $z + 1`
                                        if [ ! $OFFSET = 0 ]; then
                                        CHECKz=`expr $z % $OFFSET`
                                        else
                                        CHECKz=1
                                        fi
                                        if test $CHECKz -eq 0
                                        then
                                                if test $OFFSET -ne 0
                                                then
                                                        echo
                                                        echo -n "Press ENTER Key to view the next $OFFSET $1..."
                                                        read
                                                        echo
                                                fi
                                        fi
}

function_upgrade()
{
			if [ -z $5 ]; then
				echo
			fi
			cleanup_quick
			URL

			copy_from_cache

			TRIGVAR=slackware 
                        SWAPME=0 
                        if [[ "$2" = "-p" || "$2" = "-ap" || "$3" = "-p" || "$3" = "-ap" ]]; then
                          check_patch_files
                          TRIGVAR=patches 
                          SWAPME=1
                        fi 
                        if [[ "$2" = "-e" || "$2" = "-ae" || "$3" = "-e" || "$3" = "-ae" ]]; then
                          check_extra_files 
                          TRIGVAR=extra 
                          SWAPME=1
			fi 
                        if test $SWAPME -eq 0 
			then
			  check_package_files
                          TRIGVAR=slackware
			fi

                        rm -f $CDIR/swaret.important
                        rm -f $CDIR/swaret.only
                        rm -f $CDIR/swaret.exclude
                        for i in `cat /etc/swaret.conf 2>/dev/null | grep "^IMPORTANT" | grep -v "#" | sed s/'"'//\g | sed s/','/' '/\g | cut -f2 -d'='`
                        do
                                for x in $i
                                do
                                        echo $x >> $CDIR/swaret.important 2>/dev/null
                                done
                        done
                        for i in `cat /etc/swaret.conf 2>/dev/null | grep "^ONLY" | grep -v "#" | sed s/'"'//\g | sed s/','/' '/\g | cut -f2 -d'='`
                        do
                                for x in $i
                                do
                                        echo $x >> $CDIR/swaret.only 2>/dev/null
                                done
                        done
                        for i in `cat /etc/swaret.conf 2>/dev/null | grep "^EXCLUDE" | grep -v "#" | sed s/'"'//\g | sed s/','/' '/\g | cut -f2 -d'='`
                        do
                                for x in $i
                                do
                                        echo $x >> $CDIR/swaret.exclude 2>/dev/null
                                done
                        done
                        SWAPEX=0
                        SWAPON=0
                        for e in `cat $CDIR/swaret.exclude 2>/dev/null | grep -v "#"`
                        do
                                for X in `cat CHECKSUMS 2>/dev/null | grep "/$e" | sed -e "s/.*\///g"`
                                do
                                        touch $CDIR/$X.exclude
                                done
                        done
                        if test $SWAPEX -eq 1; then
                                echo
                        fi
                        for e in `cat $CDIR/swaret.only 2>/dev/null | grep -v "#"`
                        do
                                for X in `cat CHECKSUMS 2>/dev/null | grep "/$e" | sed -e "s/.*\///g"`
                                do
                                        touch $CDIR/$X.only
                                done
                        done
                        if test $SWAPON -eq 1; then
                                echo
                        fi

			SWAP=0
			if [[ "$2" = "-a" || "$2" = "-ap" || "$2" = "-ae" ]]; then
				SWAP=1
			fi 
		 	if [ -z "$2" ]; then
				SWAP=1
		    	fi
			if [[ "$2" = "-p" || "$2" = "-e" ]]; then
				SWAP=1
			fi
                        if test $SWAP -eq 1
		 	then
				  SWAPME=0 
                                  if [[ "$2" = "-p" || "$2" = "-ap" || "$3" = "-p" || "$3" = "-ap" ]]; then
					check_patch_files
					PKGS=`ls $PACKAGES_LOGDIR/ 2>/dev/null`
					NPKGS=`ls $PACKAGES_LOGDIR/ 2>/dev/null | wc -l`
					if [[ "$WARNINGS" == "1" ]]; then
						echo "WARNING: This will take some time. Be patient!"
						if [[ "$INFORMATION" != "1" ]]; then
							echo
						fi
					fi
					if [[ "$INFORMATION" == "1" ]]; then
						printf "INFORMATION: When you see different versions of a Patch,\n"
						printf "             you will need to remove all versions of that Patch,\n"
                                                printf "             but not the most recent one!\n"
                                                printf "             Hit 'CTRL + C' and use 'swaret --remove PATCH-VERSION'\n"
                                                printf "             to solve this problem and restart!\n\n"
					fi
					echo "Making a List of installed Patches to Upgrade..."
                                        SWAPME=1
				  fi 
                                  if [[ "$2" = "-e" || "$2" = "-ae" || "$3" = "-e" || "$3" = "-ae" ]]; then
					check_extra_files
                                        PKGS=`ls $PACKAGES_LOGDIR/ 2>/dev/null`
                                        NPKGS=`ls $PACKAGES_LOGDIR/ 2>/dev/null | wc -l`
                                        if [[ "$WARNINGS" == "1" ]]; then
                                                echo "WARNING: This will take some time. Be patient!"
                                                if [[ "$INFORMATION" != "1" ]]; then
                                                        echo
                                                fi
                                        fi
                                        if [[ "$INFORMATION" == "1" ]]; then
                                                printf "INFORMATION: When you see different versions of a Extra Package,\n"
                                                printf "             you will need to remove all versions of that Extra Package,\n"
                                                printf "             but not the most recent one!\n"
                                                printf "             Hit 'CTRL + C' and use 'swaret --remove EXTRA-PACKAGE-VERSION'\n"
                                                printf "             to solve this problem and restart!\n\n"
                                        fi
                                        echo "Making a List of installed Extra Packages to Upgrade..."	
                                        SWAPME=1
				  fi 
                                  if test $SWAPME -eq 0 
				  then
					check_package_files
                                        PKGS=`ls $PACKAGES_LOGDIR/ 2>/dev/null`
                                        NPKGS=`ls $PACKAGES_LOGDIR/ 2>/dev/null | wc -l`
                                        if [[ "$WARNINGS" == "1" ]]; then
                                                echo "WARNING: This will take some time. Be patient!"
						if [[ "$INFORMATION" != "1" ]]; then
							echo
						fi
                                        fi
                                        if [[ "$INFORMATION" == "1" ]]; then
                                                printf "INFORMATION: When you see different versions of a Package,\n"
                                                printf "             you will need to remove all versions of that Package,\n"
                                                printf "             but not the most recent one!\n"
                                                printf "             Hit 'CTRL + C' and use 'swaret --remove PACKAGE-VERSION'\n"
                                                printf "             to solve this problem and restart!\n\n"
                                        fi
					echo "Making a List of installed Packages to Upgrade..."
				  fi 
                                  if test $NPKGS -eq 0; then
                                    NPKGS=`ls $PACKAGES_LOGDIR/* 2>/dev/null | wc -l`
                                    NPKGS=`echo $NPKGS | awk '{print$1}'`
                                    if test $NPKGS -eq 0; then
				      echo
                                      if [[ "$3" = "-p" || "$3" = "-ap" ]]; then
                                        MSGERR "--upgrade [-p|-ap]" "No installed Patches found!"
                                        SWAPUS=1
                                      fi
                                      if [[ "$3" = "-e" || "$3" = "-ae" ]]; then
                                        MSGERR "--upgrade [-e|-ae]" "No installed Extra Packages found!"
                                        SWAPUS=1
                                      fi
                                      if test $SWAPUS -eq 0; then
                                        MSGERR "--upgrade" "No installed Packages found!"
                                      fi
				    fi
				  fi
		        else
				  SWAPME=0 
                                  if [[ "$3" = "-p" || "$3" = "-ap" || "$2" = "-p" || "$2" = "-ap" ]]; then
					check_patch_files
                                        PKGS=`ls $PACKAGES_LOGDIR/$2* 2>/dev/null`
                                        NPKGS=`ls $PACKAGES_LOGDIR/$2* 2>/dev/null | wc -l`
                                        if [[ "$WARNINGS" == "1" ]]; then
                                                echo "WARNING: This will take some time. Be patient!"
                                                if [[ "$INFORMATION" != "1" ]]; then
                                                        echo
                                                fi
                                        fi
                                        if [[ "$INFORMATION" == "1" ]]; then
                                                printf "INFORMATION: When you see different versions of a Patch,\n"
                                                printf "             you will need to remove all versions of that Patch,\n"
                                                printf "             but not the most recent one!\n"
                                                printf "             Hit 'CTRL + C' and use 'swaret --remove PATCH-VERSION'\n"
                                                printf "             to solve this problem and restart!\n\n"
                                        fi
					echo "Making a List of installed Patches to Upgrade matching Keyword: $2..."  
                                        SWAPME=1
				  fi 
                                  if [[ "$3" = "-e" || "$3" = "-ae" || "$2" = "-e" || "$2" = "-ae" ]]; then
					check_extra_files
                                        PKGS=`ls $PACKAGES_LOGDIR/$2* 2>/dev/null`
                                        NPKGS=`ls $PACKAGES_LOGDIR/$2* 2>/dev/null | wc -l`
                                        if [[ "$WARNINGS" == "1" ]]; then
                                                echo "WARNING: This will take some time. Be patient!"
                                                if [[ "$INFORMATION" != "1" ]]; then
                                                        echo
                                                fi
                                        fi
                                        if [[ "$INFORMATION" == "1" ]]; then
                                                printf "INFORMATION: When you see different versions of a Extra Package,\n"
                                                printf "             you will need to remove all versions of that Extra Package,\n"
                                                printf "             but not the most recent one!\n"
                                                printf "             Hit 'CTRL + C' and use 'swaret --remove EXTRA-PACKAGE-VERSION'\n"
                                                printf "             to solve this problem and restart!\n\n"
                                        fi
					echo "Making a List of installed Extra Packages to Upgrade matching Keyword: $2..."  
                                        SWAPME=1
				  fi 
                                  if test $SWAPME -eq 0 	
				  then
					check_package_files
                                        PKGS=`ls $PACKAGES_LOGDIR/$2* 2>/dev/null`
                                        NPKGS=`ls $PACKAGES_LOGDIR/$2* 2>/dev/null | wc -l`
                                        if [[ "$WARNINGS" == "1" ]]; then
                                                echo "WARNING: This will take some time. Be patient!"
                                                if [[ "$INFORMATION" != "1" ]]; then
                                                        echo
                                                fi
                                        fi
                                        if [[ "$INFORMATION" == "1" ]]; then
                                                printf "INFORMATION: When you see different versions of a Package,\n"
                                                printf "             you will need to remove all versions of that Package,\n"
                                                printf "             but not the most recent one!\n"
                                                printf "             Hit 'CTRL + C' and use 'swaret --remove PACKAGE-VERSION'\n"
                                                printf "             to solve this problem and restart!\n\n"
                                        fi
					echo "Making a List of installed Packages to Upgrade matching Keyword: $2..."
				  fi 
				  SWAPUS=0
				  if test $NPKGS -eq 0; then
				    NPKGS=`ls $PACKAGES_LOGDIR/$2* 2>/dev/null | wc -l`
				    NPKGS=`echo $NPKGS | awk '{print$1}'`
				    if test $NPKGS -eq 0; then
				      echo
				      if [[ "$3" = "-p" || "$3" = "-ap" || "$2" = "-p" || "$2" = "-ap" ]]; then
					MSGERR "--upgrade [-p|-ap]" "No installed Patches found matching Keyword: $2!"
					SWAPUS=1
				      fi
                                      if [[ "$3" = "-e" || "$3" = "-ae" || "$2" = "-e" || "$2" = "-ae" ]]; then
					MSGERR "--upgrade [-e|-ae]" "No installed Extra Packages found matching Keyword: $2!"	
					SWAPUS=1
                                      fi
				      if test $SWAPUS -eq 0; then
					MSGERR "--upgrade" "No installed Packages found matching Keyword: $2!"
                                      fi
                                    else
                                      echo
                                      if [[ "$3" = "-p" || "$3" = "-ap" || "$2" = "-p" || "$2" = "-ap" ]]; then
					if test $NPKGS -eq 1; then
				          MSGERR "--upgrade [-p|-ap]" "$NPKGS installed Patch matching Keyword '$2' is up to date!"
					else
					  MSGERR "--upgrade [-p|-ap]" "$NPKGS installed Patches matching Keyword '$2' are up to date!"
					fi
                                        SWAPUS=1
                                      fi
                                      if [[ "$3" = "-e" || "$3" = "-ae" || "$2" = "-e" || "$2" = "-ae" ]]; then
                                        if test $NPKGS -eq 1; then
                                          MSGERR "--upgrade [-e|-ae]" "$NPKGS installed Extra Package matching Keyword '$2' is up to date!"
                                        else
                                          MSGERR "--upgrade [-e|-ae]" "$NPKGS installed Extra Packages matching Keyword '$2' are up to date!"
                                        fi
                                        SWAPUS=1
                                      fi
                                      if test $SWAPUS -eq 0; then
                                        if test $NPKGS -eq 1; then
                                          MSGERR "--upgrade" "$NPKGS installed Package matching Keyword '$2' is up to date!"
                                        else
                                          MSGERR "--upgrade" "$NPKGS installed Packages matching Keyword '$2' are up to date!"
                                        fi
                                      fi
				    fi
 				  fi
			fi
			NPKGS=`echo $NPKGS | awk '{print$1}'`
                        SWAPME=0
                        if [[ "$2" = "-p" || "$2" = "-ap" || "$3" = "-p" || "$3" = "-ap" ]]; then
			  swap_to_patches
			  make_patches_list
                          SWAPME=1
                        fi
                        if [[ "$2" = "-e" || "$2" = "-ae" || "$3" = "-e" || "$3" = "-ae" ]]; then
			  swap_to_extra
			  make_extra_list
                          SWAPME=1
                        fi
                        if test $SWAPME -eq 0
                        then
			  cat CHECKSUMS.md5 2>/dev/null | sed -e "s/.*\///g" > CHECKSUMS.md5.upgrade
			fi
                        if [ ! -z $2 ]; then
                                if [[ "$2" != "-p" ]] && [[ "$2" != "-e" ]] && [[ "$2" != "-a" ]] && [[ "$2" != "-ap" ]] && [[ "$2" != "-ae" ]]; then
                                        IPKGS=`ls -a $PACKAGES_LOGDIR/$2* 2>/dev/null | grep -v "dl$" | grep -v "rob$" | grep -v "mybuild$" | sed -e "s/.*\///g" | grep "-"`
                                else
                                        IPKGS=`ls -a $PACKAGES_LOGDIR/ 2>/dev/null | grep -v "dl$" | grep -v "rob$" | grep -v "mybuild$" | sed -e "s/.*\///g" | grep "-"`
                                fi
                        else
                                IPKGS=`ls -a $PACKAGES_LOGDIR/ 2>/dev/null | grep -v "dl$" | grep -v "rob$" | grep -v "mybuild$" | sed -e "s/.*\///g" | grep "-"`
                        fi
			ALPHA=0
			SWAPMORE=0
			METHOD=0
			if test `cat $CDIR/swaret.only 2>/dev/null | grep -v "#" | wc -l` -gt 0; then
                          if test `cat $CDIR/swaret.exclude 2>/dev/null | grep -v "#" | wc -l` -gt 0; then
			    cat $CDIR/swaret.only 2>/dev/null | grep -v "#" | grep -q '^[[:alpha:]]\+' && OALPHA=1 || OALPHA=0
			    cat $CDIR/swaret.exclude 2>/dev/null | grep -v "#" | grep -q '^[[:alpha:]]\+' && EALPHA=1 || EALPHA=0
                            if test $OALPHA -eq 1; then
			      if test $EALPHA -eq 1; then
                                if [[ "$WARNINGS" == "1" ]]; then
                                        echo
                                        echo "WARNING: Using 'Only - Exclude' method."
                                        echo "         If you don 't want swaret to use this method,"
                                        echo "         clear the ONLY and EXCLUDE Variables"
					echo "         in /etc/swaret.conf Please!"
					echo "         You may also comment(#) the Keywords!"
                                        echo
					METHOD=1
                                fi
                                SWAPMORE=1
			      fi
			    fi
 			  fi
			fi
                        if test `cat $CDIR/swaret.only 2>/dev/null | grep -v "#" | wc -l` -gt 0; then
                          if test $SWAPMORE -eq 0; then
                            cat $CDIR/swaret.only 2>/dev/null | grep -v "#" | grep -q '^[[:alpha:]]\+' && ALPHA=1 || ALPHA=0
                            if test $ALPHA -eq 1; then
                                if [[ "$WARNINGS" == "1" ]]; then
                                        echo
                                        echo "WARNING: Using Only method."
                                        echo "         If you don 't want swaret to use this method,"
                                        echo "         clear the ONLY Variable in /etc/swaret.conf Please!"
					echo "         You may also comment(#) the Keywords!"
                                        echo
                                        METHOD=2
                                fi
                            fi
                          fi
                        fi
			if test `cat $CDIR/swaret.exclude 2>/dev/null | grep -v "#" | wc -l` -gt 0; then
			  if test $SWAPMORE -eq 0; then
			    cat $CDIR/swaret.exclude 2>/dev/null | grep -v "#" | grep -q '^[[:alpha:]]\+' && ALPHA=1 || ALPHA=0
                            if test $ALPHA -eq 1; then
				if [[ "$WARNINGS" == "1" ]]; then
					echo
					echo "WARNING: Using Exclude method."
                                        echo "         If you don 't want swaret to use this method,"
                                        echo "         clear the EXCLUDE Variable in /etc/swaret.conf Please!"
					echo "         You may also comment(#) the Keywords!"
					echo
					METHOD=3
				fi
				SWAPMORE=1
			    fi
			  fi
			fi
			SWAPMORE=0
			PIPKGS=`cat $CDIR/swaret.important 2>/dev/null | grep -v "#"`
			for z in $PIPKGS 
			do
			  for i in `ls -a $PACKAGES_LOGDIR/$z* 2>/dev/null | sed -e "s/.*\///g"` 
			  do
                            iTMP=`echo $i | sed s/'.tgz'// | sed -e "s/.*\///g" | sed -e s/-[0-9].*//`
                            iTMP2=`echo $i | sed -e 's/-[0-9\.]*\(_[^-]*\).*/-\1/' | sed -e s/-[0-9].*//`
                            APKGS=`cat CHECKSUMS 2>/dev/null | grep "/$iTMP" | sed s/'.tgz'// | sed -e "s/.*\///g"`
                            for x in $APKGS
                            do
                                        aTMP=`echo $x | sed -e s/-[0-9].*//`
                                        aTMP2=`echo $x | sed -e 's/-[0-9\.]*\(_[^-]*\).*/-\1/' | sed -e s/-[0-9].*//`
                                        if [[ "$iTMP" == "$aTMP" ]]; then
                                          if [[ "$iTMP2" == "$aTMP2" ]]; then
                                                if test `ls $REMOVED_PACKAGES_LOGDIR/$i* 2>/dev/null | wc -l` -eq 0; then
                                                        if test `ls $REMOVED_PACKAGES_LOGDIR/$x* 2>/dev/null | wc -l` -eq 0; then
                                                                if [ ! -f $PACKAGES_LOGDIR/$x ]; then
									upgradefromoldtonewi
                                                                fi
                                                        fi
                                                fi
                                          fi
                                        fi
			    done
                          done
			done
			for i in `cat $CDIR/swaret.only 2>/dev/null | grep -v "#"`
			do
				if test `cat $CDIR/swaret.exclude 2>/dev/null | grep -v "#" | grep "$i$" | wc -l` -eq 1; then
					touch $i.xmp
				fi
			done
			SWAPONS=0
                        for i in $IPKGS
                        do
                           iTMP=`echo $i | sed s/'.tgz'// | sed -e "s/.*\///g" | sed -e s/-[0-9].*//`
                           iTMP2=`echo $i | sed -e 's/-[0-9\.]*\(_[^-]*\).*/-\1/' | sed -e s/-[0-9].*//`
			   SHORTPKG=`echo $i | sed -e s/-[0-9].*//`
			   if [ ! -f $SHORTPKG*.xmp ]; then
                             case $METHOD in
                              "0")
                                 APKGS=`cat CHECKSUMS 2>/dev/null | grep "/$iTMP" | sed s/'.tgz'// | sed -e "s/.*\///g"`
                                 for x in $APKGS
                                 do
                                               aTMP=`echo $x | sed -e s/-[0-9].*//`
                                               aTMP2=`echo $x | sed -e 's/-[0-9\.]*\(_[^-]*\).*/-\1/' | sed -e s/-[0-9].*//`
                                               if [[ "$iTMP" == "$aTMP" ]]; then
                                                 if [[ "$iTMP2" == "$aTMP2" ]]; then
                                                       if test `ls $REMOVED_PACKAGES_LOGDIR/$i* 2>/dev/null | wc -l` -eq 0; then
                                                                      if test `ls $REMOVED_PACKAGES_LOGDIR/$x* 2>/dev/null | wc -l` -eq 0; then
                                                                              if [ ! -f $PACKAGES_LOGDIR/$x ]; then
                                                                                 if test `cat NEWPKGS.list 2>/dev/null | grep "$x.tgz" | wc -l` -eq 0; then
											upgradefromoldtonew
                                                                                 fi
                                                                              fi
                                                                      fi
                                                       fi
                                                 fi
                                               fi
                                 done
                                 ;;
                              "1")
				   if test `cat $CDIR/swaret.only 2>/dev/null | grep -v "#" | wc -l` -ge 1; then
                                     SHORTPKG=`echo "$iTMP" | sed -e s/-[0-9].*//`
                                     SWAPMEX=0
                                     if test `grep "$iTMP" $CDIR/swaret.only 2>/dev/null | grep -v "#" | wc -l` -eq 1; then
				      if test `grep "$iTMP" $CDIR/swaret.exclude 2>/dev/null | grep -v "#" | wc -l` -eq 0; then
                                       SWAPMEX=1
                                       APKGS=`cat CHECKSUMS 2>/dev/null | grep "/$iTMP" | sed s/'.tgz'// | sed -e "s/.*\///g"`
                                       for x in $APKGS
                                       do
                                               aTMP=`echo $x | sed -e s/-[0-9].*//`
                                               aTMP2=`echo $x | sed -e 's/-[0-9\.]*\(_[^-]*\).*/-\1/' | sed -e s/-[0-9].*//`
                                               if [[ "$iTMP" == "$aTMP" ]]; then
                                                 if [[ "$iTMP2" == "$aTMP2" ]]; then
                                                       if test `ls $REMOVED_PACKAGES_LOGDIR/$i* 2>/dev/null | wc -l` -eq 0; then
                                                                      if test `ls $REMOVED_PACKAGES_LOGDIR/$x* 2>/dev/null | wc -l` -eq 0; then
                                                                              if [ ! -f $PACKAGES_LOGDIR/$x ]; then
                                                                                 if test `cat NEWPKGS.list 2>/dev/null | grep "$x.tgz" | wc -l` -eq 0; then
											upgradefromoldtonew
										      SWAPMEX=1
                                                                                 fi
                                                                              fi
                                                                      fi
                                                       fi
                                                 fi
                                               fi
                                       done
				      fi
                                     fi
                                     if test `grep "$SHORTPKG$" $CDIR/swaret.only 2>/dev/null | grep -v "#" | wc -l` -eq 1; then
				      if test `grep "$iTMP" $CDIR/swaret.exclude 2>/dev/null | grep -v "#" | wc -l` -eq 0; then
                                       if test $SWAPMEX -eq 0; then
                                        APKGS=`cat CHECKSUMS 2>/dev/null | grep "/$iTMP" | sed s/'.tgz'// | sed -e "s/.*\///g"`
                                        for x in $APKGS
                                        do
                                               aTMP=`echo $x | sed -e s/-[0-9].*//`
                                               aTMP2=`echo $x | sed -e 's/-[0-9\.]*\(_[^-]*\).*/-\1/' | sed -e s/-[0-9].*//`
                                               if [[ "$iTMP" == "$aTMP" ]]; then
                                                 if [[ "$iTMP2" == "$aTMP2" ]]; then
                                                       if test `ls $REMOVED_PACKAGES_LOGDIR/$i* 2>/dev/null | wc -l` -eq 0; then
                                                                      if test `ls $REMOVED_PACKAGES_LOGDIR/$x* 2>/dev/null | wc -l` -eq 0; then
                                                                              if [ ! -f $PACKAGES_LOGDIR/$x ]; then
                                                                                 if test `cat NEWPKGS.list 2>/dev/null | grep "$x.tgz" | wc -l` -eq 0; then
											upgradefromoldtonew
										      SWAPMEX=1
                                                                                 fi
                                                                              fi
                                                                      fi
                                                       fi
                                                 fi
                                               fi
                                        done
				       fi
                                      fi
                                     fi
				     SWAPONS=1
                                     SHORTPKG=`echo $iTMP | cut -f1 -d'-'`
                                     if test `grep "$SHORTPKG$" $CDIR/swaret.only 2>/dev/null | grep -v "#" | wc -l` -eq 1; then
                                        if test `grep "$SHORTPKG$" $CDIR/swaret.exclude 2>/dev/null | grep -v "#" | wc -l` -eq 1; then
                                                SWAPMEX=1
                                        fi
                                     fi
                                     if test `grep "$SHORTPKG$" $CDIR/swaret.only 2>/dev/null | grep -v "#" | wc -l` -eq 1; then
                                      if test `grep "$iTMP$" $CDIR/swaret.exclude 2>/dev/null | grep -v "#" | wc -l` -eq 0; then
                                       if test $SWAPMEX -eq 0; then
                                        APKGS=`cat CHECKSUMS 2>/dev/null | grep "/$iTMP" | sed s/'.tgz'// | sed -e "s/.*\///g"`
                                        for x in $APKGS
                                        do
                                               aTMP=`echo $x | sed -e s/-[0-9].*//`
                                               aTMP2=`echo $x | sed -e 's/-[0-9\.]*\(_[^-]*\).*/-\1/' | sed -e s/-[0-9].*//`
                                               if [[ "$iTMP" == "$aTMP" ]]; then
                                                 if [[ "$iTMP2" == "$aTMP2" ]]; then
                                                       if test `ls $REMOVED_PACKAGES_LOGDIR/$i* 2>/dev/null | wc -l` -eq 0; then
                                                                      if test `ls $REMOVED_PACKAGES_LOGDIR/$x* 2>/dev/null | wc -l` -eq 0; then
                                                                              if [ ! -f $PACKAGES_LOGDIR/$x ]; then
                                                                                 if test `cat NEWPKGS.list 2>/dev/null | grep "$x.tgz" | wc -l` -eq 0; then
                                                                                        upgradefromoldtonew
                                                                                      SWAPMEX=1
                                                                                 fi
                                                                              fi
                                                                      fi
                                                       fi
                                                 fi
                                               fi
                                        done
                                       fi
                                      fi
                                     fi
                                   fi
                                   ;;
                              "2")
                                   if test `cat $CDIR/swaret.only 2>/dev/null | grep -v "#" | wc -l` -ge 1; then
                                     SHORTPKG=`echo "$iTMP" | sed -e s/-[0-9].*//`
                                     SWAPMEX=0
                                     if test `grep "$iTMP" $CDIR/swaret.only 2>/dev/null | grep -v "#" | wc -l` -eq 1; then
                                       SWAPMEX=1
                                       APKGS=`cat CHECKSUMS 2>/dev/null | grep "/$iTMP" | sed s/'.tgz'// | sed -e "s/.*\///g"`
                                       for x in $APKGS
                                       do
                                               aTMP=`echo $x | sed -e s/-[0-9].*//`
                                               aTMP2=`echo $x | sed -e 's/-[0-9\.]*\(_[^-]*\).*/-\1/' | sed -e s/-[0-9].*//`
                                               if [[ "$iTMP" == "$aTMP" ]]; then
                                                 if [[ "$iTMP2" == "$aTMP2" ]]; then
                                                       if test `ls $REMOVED_PACKAGES_LOGDIR/$i* 2>/dev/null | wc -l` -eq 0; then
                                                                      if test `ls $REMOVED_PACKAGES_LOGDIR/$x* 2>/dev/null | wc -l` -eq 0; then
                                                                              if [ ! -f $PACKAGES_LOGDIR/$x ]; then
                                                                                 if test `cat NEWPKGS.list 2>/dev/null | grep "$x.tgz" | wc -l` -eq 0; then
											upgradefromoldtonew
                                                                                 fi
                                                                              fi
                                                                      fi
                                                       fi
                                                 fi
                                               fi
                                       done
                                     fi
                                     if test `grep "$SHORTPKG$" $CDIR/swaret.only 2>/dev/null | grep -v "#" | wc -l` -eq 1; then
                                      if test $SWAPMEX -eq 0; then
                                       APKGS=`cat CHECKSUMS 2>/dev/null | grep "/$iTMP" | sed s/'.tgz'// | sed -e "s/.*\///g"`
                                       for x in $APKGS
                                       do
                                               aTMP=`echo $x | sed -e s/-[0-9].*//`
                                               aTMP2=`echo $x | sed -e 's/-[0-9\.]*\(_[^-]*\).*/-\1/' | sed -e s/-[0-9].*//`
                                               if [[ "$iTMP" == "$aTMP" ]]; then
                                                 if [[ "$iTMP2" == "$aTMP2" ]]; then
                                                       if test `ls $REMOVED_PACKAGES_LOGDIR/$i* 2>/dev/null | wc -l` -eq 0; then
                                                                      if test `ls $REMOVED_PACKAGES_LOGDIR/$x* 2>/dev/null | wc -l` -eq 0; then
                                                                              if [ ! -f $PACKAGES_LOGDIR/$x ]; then
                                                                                 if test `cat NEWPKGS.list 2>/dev/null | grep "$x.tgz" | wc -l` -eq 0; then
											upgradefromoldtonew
                                                                                 fi
                                                                              fi
                                                                      fi
                                                       fi
                                                 fi
                                               fi
                                       done
                                      fi
                                     fi
                                   fi
                                   if test $SWAPMEX -eq 0; then
                                       APKGS=`cat CHECKSUMS 2>/dev/null | grep "/$e" | sed s/'.tgz'// | sed -e "s/.*\///g"`
                                       for x in $APKGS
                                       do
					 if [ -f $CDIR/$x.tgz.only ]; then
                                               aTMP=`echo $x | sed -e s/-[0-9].*//`
                                               aTMP2=`echo $x | sed -e 's/-[0-9\.]*\(_[^-]*\).*/-\1/' | sed -e s/-[0-9].*//`
                                               if [[ "$iTMP" == "$aTMP" ]]; then
                                                 if [[ "$iTMP2" == "$aTMP2" ]]; then
                                                       if test `ls $REMOVED_PACKAGES_LOGDIR/$i* 2>/dev/null | wc -l` -eq 0; then
                                                                      if test `ls $REMOVED_PACKAGES_LOGDIR/$x* 2>/dev/null | wc -l` -eq 0; then
                                                                              if [ ! -f $PACKAGES_LOGDIR/$x ]; then
                                                                                 if test `cat NEWPKGS.list 2>/dev/null | grep "$x.tgz" | wc -l` -eq 0; then
											upgradefromoldtonew
                                                                                 fi
                                                                              fi
                                                                      fi
                                                       fi
                                                 fi
                                               fi
					 fi
                                       done
                                   fi
                                 ;;
                              "3")
                                 if test `cat $CDIR/swaret.exclude 2>/dev/null | grep -v "#" | wc -l` -ge 1; then
                                   if test `grep "$iTMP" $CDIR/swaret.exclude 2>/dev/null | grep -v "#" | wc -l` -eq 0; then
				     SHORTPKG=`echo "$iTMP" | sed -e s/-[0-9].*//`
				     if test `grep "$SHORTPKG$" $CDIR/swaret.exclude 2>/dev/null | grep -v "#" | wc -l` -eq 0; then 
                                       APKGS=`cat CHECKSUMS 2>/dev/null | grep "/$iTMP" | sed s/'.tgz'// | sed -e "s/.*\///g"`
                                       for x in $APKGS
                                       do
					 if [ ! -f $CDIR/$x.tgz.exclude ]; then
                                              if [ ! -f $x.tmp ]; then
                                               aTMP=`echo $x | sed -e s/-[0-9].*//`
                                               aTMP2=`echo $x | sed -e 's/-[0-9\.]*\(_[^-]*\).*/-\1/' | sed -e s/-[0-9].*//`
                                               if [[ "$iTMP" == "$aTMP" ]]; then
                                                 if [[ "$iTMP2" == "$aTMP2" ]]; then
                                                       if test `ls $REMOVED_PACKAGES_LOGDIR/$x* 2>/dev/null | wc -l` -eq 0; then
                                                                      if test `ls $REMOVED_PACKAGES_LOGDIR/$x* 2>/dev/null | wc -l` -eq 0; then
                                                                              if [ ! -f $PACKAGES_LOGDIR/$x ]; then
                                                                                 if test `cat NEWPKGS.list 2>/dev/null | grep "$x.tgz" | wc -l` -eq 0; then
											upgradefromoldtonew
                                                                                 fi
                                                                              fi
                                                                      fi
                                                       fi
                                                 fi
                                               fi
					      fi
					 fi
                                       done
				     fi
                                   fi
                                 fi
                                 ;;
                             esac
			   fi
                        done
                        if test $SWAPONS -eq 1; then
                         if [[ "$2" != "-a" ]] && [ ! -z "$2" ]; then
                          for e in `cat $CDIR/swaret.only 2>/dev/null | grep -v "#"`
                          do
                            APKGS=`cat CHECKSUMS 2>/dev/null | grep "/$e" | sed s/'.tgz'// | sed -e "s/.*\///g"`
                            for x in $APKGS
                            do
                              iSHORTPKG="$2"
                              if test `ls -alL $PACKAGES_LOGDIR/$iSHORTPKG* 2>/dev/null | wc -l` -eq 1; then
                                iPKG=`ls -a $PACKAGES_LOGDIR/$iSHORTPKG* 2>/dev/null | grep -v "dl$" | grep -v "rob$" | grep -v "mybuild$" | sed -e "s/.*\///g" | grep "-"`
                                iTMP=`echo $iPKG | sed s/'.tgz'// | sed -e "s/.*\///g" | sed -e s/-[0-9].*//`
                                iTMP2=`echo $iPKG | sed -e 's/-[0-9\.]*\(_[^-]*\).*/-\1/' | sed -e s/-[0-9].*//`

                                          SHORTXPKG=`echo $x | sed -e s/-[0-9].*//`

                                          if test `cat $CDIR/swaret.exclude | grep "$SHORTXPKG" | wc -l` -eq 0; then
                                               aTMP=`echo $x | sed -e s/-[0-9].*//`
                                               aTMP2=`echo $x | sed -e 's/-[0-9\.]*\(_[^-]*\).*/-\1/' | sed -e s/-[0-9].*//`
                                               if [[ "$iTMP" == "$aTMP" ]]; then
                                                 if [[ "$iTMP2" == "$aTMP2" ]]; then
                                                       if test `ls $REMOVED_PACKAGES_LOGDIR/$i* 2>/dev/null | wc -l` -eq 0; then
                                                                      if test `ls $REMOVED_PACKAGES_LOGDIR/$x* 2>/dev/null | wc -l` -eq 0; then
                                                                              if [ ! -f $PACKAGES_LOGDIR/$x ]; then
                                                                                 if test `cat NEWPKGS.list 2>/dev/null | grep "$x.tgz" | wc -l` -eq 0; then
											upgradefromoldtonew
                                                                                 fi
                                                                              fi
                                                                      fi
                                                       fi
                                                 fi
                                               fi
                                          fi
                              fi
                            done
                          done
                         else
                          for e in `cat $CDIR/swaret.only 2>/dev/null | grep -v "#"`
                          do
                            APKGS=`cat CHECKSUMS 2>/dev/null | grep "/$e" | sed s/'.tgz'// | sed -e "s/.*\///g"`
                            for x in $APKGS
                            do
                              iSHORTPKG=`echo $x | sed -e s/-[0-9].*//`
                              if test `ls -alL $PACKAGES_LOGDIR/$iSHORTPKG* 2>/dev/null | wc -l` -eq 1; then
                                iPKG=`ls -a $PACKAGES_LOGDIR/$iSHORTPKG* 2>/dev/null | grep -v "dl$" | grep -v "rob$" | grep -v "mybuild$" | sed -e "s/.*\///g" | grep "-"`
                                iTMP=`echo $iPKG | sed s/'.tgz'// | sed -e "s/.*\///g" | sed -e s/-[0-9].*//`
                                iTMP2=`echo $iPKG | sed -e 's/-[0-9\.]*\(_[^-]*\).*/-\1/' | sed -e s/-[0-9].*//`

                                          SHORTXPKG=`echo $x | sed -e s/-[0-9].*//`

                                          if test `cat $CDIR/swaret.exclude | grep "$SHORTXPKG" | wc -l` -eq 0; then
                                               aTMP=`echo $x | sed -e s/-[0-9].*//`
                                               aTMP2=`echo $x | sed -e 's/-[0-9\.]*\(_[^-]*\).*/-\1/' | sed -e s/-[0-9].*//`
                                               if [[ "$iTMP" == "$aTMP" ]]; then
                                                 if [[ "$iTMP2" == "$aTMP2" ]]; then
                                                       if test `ls $REMOVED_PACKAGES_LOGDIR/$i* 2>/dev/null | wc -l` -eq 0; then
                                                                      if test `ls $REMOVED_PACKAGES_LOGDIR/$x* 2>/dev/null | wc -l` -eq 0; then
                                                                              if [ ! -f $PACKAGES_LOGDIR/$x ]; then
                                                                                 if test `cat NEWPKGS.list 2>/dev/null | grep "$x.tgz" | wc -l` -eq 0; then
											upgradefromoldtonew
                                                                                 fi
                                                                              fi
                                                                      fi
                                                       fi
                                                 fi
                                               fi
                                          fi
                              fi
                            done
                          done
                         fi
                        fi

			CHECK=`cat NEWPKGS.list 2>/dev/null | wc -l`
			if test $CHECK -eq 0
			then
				echo
				if test $SWAP -eq 1
				then
				   SWAPME=0
                                   if [[ "$2" = "-p" || "$2" = "-ap" || "$3" = "-p" || "$3" = "-ap" ]]; then
					MSGERR "--upgrade [-ap]" "Installed Patches are up to date!"
                                        SWAPME=1
                                   fi
				   if [[ "$2" = "-e" || "$2" = "-ae" || "$3" = "-e" || "$3" = "-ae" ]]; then
	                                MSGERR "--upgrade [-ae]" "Installed Extra Packages are up to date!"
					SWAPME=1
                                   fi
                                   if test $SWAPME -eq 0
                                   then
	                                MSGERR "--upgrade" "Installed Packages are up to date!"
                                   fi
				else
				   SWAPME=0
				   if [[ "$2" = "-p" || "$2" = "-ap" || "$3" = "-p" || "$3" = "-ap" ]]; then
                                        if test $NPKGS -eq 1
                                        then
                                                MSGERR "--upgrade" "$NPKGS installed Patch matching Keyword '$2' is up to date!"
                                        else
                                                MSGERR "--upgrade" "$NPKGS installed Patches matching Keyword '$2' are up to date!"
                                        fi
					SWAPME=1
				   fi
				   if [[ "$2" = "-e" || "$2" = "-ae" || "$3" = "-e" || "$3" = "-ae" ]]; then
                                        if test $NPKGS -eq 1
                                        then
                                                MSGERR "--upgrade" "$NPKGS installed Extra Package matching Keyword '$2' is up to date!"
                                        else
                                                MSGERR "--upgrade" "$NPKGS installed Extra Packages matching Keyword '$2' are up to date!"
                                        fi
					SWAPME=1
				   fi
				   if test $SWAPME -eq 0
				   then
					if test $NPKGS -eq 1 
					then
						MSGERR "--upgrade" "$NPKGS installed Package matching Keyword '$2' is up to date!"
					else
						MSGERR "--upgrade" "$NPKGS installed Packages matching Keyword '$2' are up to date!"
					fi
				   fi
				fi
				exit
			fi
			if test $SWAP -eq 1 
			then
				if [[ "$2" = "-a" || "$2" = "-ap" || "$2" = "-ae" ]]; then			
					rm -f *.tmp
					answer1="y"
				else
					rm -f *.tmp
					answer1="n"
				fi
			else
                                if [[ "$3" = "-a" || "$3" = "-ap" || "$3" = "-ae" ]]; then
                                        rm -f *.tmp
                                        answer1="y"
                                else
                                        rm -f *.tmp
                                        answer1="n"
                                fi
			fi
			FPKGSW=0
			FPKGTSIZE=0
			FPKGC=0
			echo
			case $answer1 in 
				"y")
					NEWPKGSLIST_FILE=`cat NEWPKGS.list 2>/dev/null`
					INSTALLEDPKGSLIST_FILE=`cat INSTALLEDPKGS.list 2>/dev/null`
					DONE=1
					COUNTER=1
					for i in $NEWPKGSLIST_FILE
					do
						get_pkg()
						{
							SHORTPKG=`echo $1 | sed s/'.tgz'//`
							PACKAGES_URL=`cat URL 2>/dev/null | awk '{ if(NR == '$2') print $1 }'`
							PACKAGE=`cat CHECKSUMS 2>/dev/null | grep "/$1" | grep / | awk '{print$3}' | sed s/.//`
							if [ ! -z $PACKAGES_URL ]; then
							   if [ -f $1 ]; then
                                                        	SIZEPKGTMP=`ls -alL $1 2>/dev/null | awk '{print$5}'`
                                                        	SIZEPKG=`echo $SIZEPKGTMP / 1024 | bc`
								SWAPME=0
								if [[ "$3" = "-p" || "$3" = "-ap" ]]; then
                                                                        MSG "--upgrade [-p|-ap]" "Patch $SHORTPKG ($SIZEPKG kB) found in $CDIR!"
                                                                        check_for_broken_patches $1 1
                                                                        SWAPME=1
                                                                fi
                                                                if [[ "$3" = "-e" || "$3" = "-ae" ]]; then
                                                                        MSG "--upgrade [-e|-ae]" "Extra Package $SHORTPKG ($SIZEPKG kB) found in $CDIR!"
                                                                        check_for_broken_extra $1 1
                                                                        SWAPME=1
                                                                fi
                                                                if test $SWAPME -eq 0
                                                                then
                                                                        MSG "--upgrade" "Package $SHORTPKG ($SIZEPKG kB) found in $CDIR!"
                                                                        check_for_broken_packages $1 1
                                                                        SWAPME=1
                                                                fi
							   else
        							SIZEPKGTMP=`cat CHECKSUMS 2>/dev/null | grep "/$1" | awk '{print$2}'`
								SIZEPKG=`echo $SIZEPKGTMP / 1024 | bc`
								GETPKG="$PACKAGE"
								MSG "--upgrade" "[ $PACKAGES_URL ]"
								echo $QS "### Fetching $SHORTPKG ($SIZEPKG kB)... "
								if test `echo $PACKAGES_URL | grep rsync | wc -l` -ge 1
								then
                                                                    if [ ! -z $Q ]; then
									    rsync_file "$PACKAGES_URL" "$PACKAGE"
                                                                            count_size_rsync $1 $3
                                                                    else
								  	    rsync_file_s "$PACKAGES_URL" "$PACKAGE"
									    touch_it "$1"
                                                                    fi
                                                                else
                                                                    if [ ! -z $Q ]; then
									    wget_file "$PACKAGES_URL" "$PACKAGE"
                                                                            count_size $1 $3
                                                                    else
									    wget_file_s "$PACKAGES_URL" "$PACKAGE"
									    touch_it "$1"
                                                                    fi
								fi
								if [ -f $1.tmp ]; then
									FPKGSW=1
									FPKGTSIZE=`echo "$FPKGTSIZE + $SIZEPKG" | bc`
									FPKGC=`echo "$FPKGC + 1" | bc`
									if [ ! -z $Q ]; then
										echo " DONE!"
									fi
									logme "--upgrade" "### Fetching $SHORTPKG ($SIZEPKG kB)... DONE!"
                                                                        SWAPME=0
                                                                        if [[ "$2" = "-p" || "$2" = "-ap" || "$3" = "-p" || "$3" = "-ap" ]]; then
                                                                                checksum_patch $1
                                                                                SWAPME=1
                                                                        fi
                                                                        if [[ "$2" = "-e" || "$2" = "-ae" || "$3" = "-e" || "$3" = "-ae" ]]; then
                                                                                checksum_extra $1
                                                                                SWAPME=1
                                                                        fi
                                                                        if test $SWAPME -eq 0
                                                                        then
                                                                                checksum_package $1
                                                                        fi
									DONE=0
									pgp_check_remote "--upgrade" "$2" "$3" "$1"
								else
									if [ ! -z $Q ]; then
										echo " FAILED!"
									fi
									logme "--upgrade" "### Fetching $SHORTPKG ($SIZEPKG kB)... FAILED!"
									rm -f $1.tmp
									RECORDS=`cat URL 2>/dev/null | wc -l`
									COUNTER=`expr $COUNTER + 1`
									if test $COUNTER -ne `expr $RECORDS + 1`
									then
									    	get_pkg $1 $COUNTER $3
									fi
									DONE=0
								fi
							   fi
							fi
						}
                                                get_local_pkg()
                                                {
                                                          SHORTPKG=`echo $1 | sed s/'.tgz'//`
                                                          if [ -f $1 ]; then
                                                        	SIZEPKGTMP=`ls -alL $1 2>/dev/null | awk '{print$5}'`
                                                        	SIZEPKG=`echo $SIZEPKGTMP / 1024 | bc`
                                                                SWAPME=0
                                                                if [[ "$3" = "-p" || "$3" = "-ap" ]]; then
                                                                        MSG "--upgrade [-p|-ap]" "Patch $SHORTPKG ($SIZEPKG kB) found in $CDIR!"
									res_local_pat $1
                                                                        SWAPME=1
                                                                fi
                                                                if [[ "$3" = "-e" || "$3" = "-ae" ]]; then
                                                                        MSG "--upgrade [-p|-ap]" "Extra Package $SHORTPKG ($SIZEPKG kB) found in $CDIR!"
									res_local_ext $1
                                                                        SWAPME=1
                                                                fi
                                                                if test $SWAPME -eq 0
                                                                then
                                                                        MSG "--upgrade" "Package $SHORTPKG ($SIZEPKG kB) found in $CDIR!"
									res_local_pac $1
                                                                fi
							  else
							    ROOTS=`cat /etc/swaret.conf | grep -v "#" | grep "^ROOT=" | grep "file:" | cut -f2 -d'=' | sed s/'file:'//`
							    for RR in $ROOTS
							    do
							        PACKAGE=`cat CHECKSUMS 2>/dev/null | grep "/$1" | grep / | awk '{print$3}' | sed s/.//`
								TMPTRIGVAR=slackware
								SIZEPKGTMP=`cat CHECKSUMS 2>/dev/null | grep "/$1" | awk '{print$2}'`
								SIZEPKG=`echo $SIZEPKGTMP / 1024 | bc`
                                                                MSG "--upgrade" "[ file:$RR ]"
								echo -n "### Copying $SHORTPKG ($SIZEPKG kB)... "
								SWAPME=0
                                                                if [[ "$3" = "-p" || "$3" = "-ap" ]]; then
									copy_file "$RR" "$PACKAGE"
									TMPTRIGVAR=patches
                                                                        SWAPME=1
                                                                fi
                                                                if [[ "$3" = "-e" || "$3" = "-ae" ]]; then
									copy_file "$RR" "$PACKAGE"
									TMPTRIGVAR=extra
                                                                        SWAPME=1
                                                                fi
                                                                if test $SWAPME -eq 0
                                                                then
									copy_file "$RR" "$PACKAGE"
									TMPTRIGVAR=slackware
                                                                fi
                                                                if [ -f $1 ]; then
                                                			FPKGSW=1
                                                			FPKGTSIZE=`echo "$FPKGTSIZE + $SIZEPKG" | bc` 
                                                			FPKGC=`echo "$FPKGC + 1" | bc`
                                                                        echo " DONE!"
									logme "--upgrade" "### Copying $SHORTPKG ($SIZEPKG kB)... DONE!"
                                                                        SWAPME=0
                                                                        if [[ "$2" = "-p" || "$2" = "-ap" || "$3" = "-p" || "$3" = "-ap" ]]; then
                                                                                checksum_patch $1
                                                                                SWAPME=1
                                                                        fi
                                                                        if [[ "$2" = "-e" || "$2" = "-ae" || "$3" = "-e" || "$3" = "-ae" ]]; then
                                                                                checksum_extra $1
                                                                                SWAPME=1
                                                                        fi
                                                                        if test $SWAPME -eq 0
                                                                        then
                                                                                checksum_package $1
                                                                        fi
                                                                        DONE=0
									pgp_check_local "--upgrade" "$2" "$3" "$1"
									break
                                                                else
                                                                        echo " FAILED!"
									logme "--upgrade" "### Copying $SHORTPKG ($SIZEPKG kB)... FAILED!"
                                                                fi
							    done
							  fi
                                                }
						if test $DONE -eq 1
						then
                                                    if test `cat /etc/swaret.conf | grep -v "#" | grep "^ROOT=" | grep "file:" | wc -l` -ge 1
						    then
                                                        SWAPME=0
                                                        if [[ "$2" = "-p" || "$2" = "-ap" || "$2" = "-e" || "$2" = "-ae" ]]; then
                                                                get_local_pkg "$i" 1 $2
                                                                SWAPME=1
                                                        fi
                                                        if [[ "$3" = "-p" || "$3" = "-ap" || "$3" = "-e" || "$3" = "-ae" ]]; then
                                                                get_local_pkg "$i" 1 $3
                                                                SWAPME=1
                                                        fi
                                                        if test $SWAPME -eq 0
                                                        then
                                                                get_local_pkg "$i" 1 "-a"
                                                        fi
						    else
                                                        SWAPME=0
                                                        if [[ "$2" = "-p" || "$2" = "-ap" || "$2" = "-e" || "$2" = "-ae" ]]; then
                                                                get_pkg "$i" 1 $2
                                                                SWAPME=1
                                                        fi
                                                        if [[ "$3" = "-p" || "$3" = "-ap" || "$3" = "-e" || "$3" = "-ae" ]]; then
                                                                get_pkg "$i" 1 $3
                                                                SWAPME=1
                                                        fi
                                                        if test $SWAPME -eq 0
                                                        then
                                                                get_pkg "$i" 1 "-a"
                                                        fi
						    fi
						fi
						COUNTER=1
						DONE=1
					done
					z=1
					a=1
					b=1
                        		if test $FPKGSW -eq 1
                        		then
                                	 if test $FPKGC -ge 1
                                	 then
					  if test `cat /etc/swaret.conf | grep -v "#" | grep "^ROOT=" | grep "file:" | wc -l` -ge 1; then
                                            if test $FPKGC -eq 1
                                            then
                                          	MSG "--upgrade" "Copied $FPKGC File with a Size of $FPKGTSIZE kB!"
                                            else
                                               	MSG "--upgrade" "Copied $FPKGC Files with a Total Size of $FPKGTSIZE kB!"
                                            fi
					  else
                                            if test $FPKGC -eq 1
                                            then
                                                MSG "--upgrade" "Downloaded $FPKGC File with a Size of $FPKGTSIZE kB!"
                                            else
                                                MSG "--upgrade" "Downloaded $FPKGC Files with a Total Size of $FPKGTSIZE kB!"
                                            fi  
					  fi
                                	 fi
                        		fi
                                        for i in $NEWPKGSLIST_FILE
	                                do
						for a in $INSTALLEDPKGSLIST_FILE
						do
							if test $b -eq $z
							then
								INSTALLED_PACKAGE=$a
							fi
							b=`expr $b + 1`
						done

						SHORTPKG=`echo $i | sed s/'.tgz'//`
						if [ -f $i.tmp ] || [ -f $i ]; then
                                                       	echo -n "=> Upgrading $INSTALLED_PACKAGE -> $SHORTPKG... "
							check_size_pkg $i
							if [ ! -f $i*.corrupted ]; then
							if [[ "$DESC" = "NO" ]]; then
								upgradepkg $i >/dev/null 2>&1
							else
								upgradepkg $i
							fi
							fi
							FIX=`echo $i | sed s/'.tgz'/' '/`
							if [ -f $PACKAGES_LOGDIR/$FIX ]; then
								echo "DONE!"	
								logme "--upgrade" "=> Upgrading $INSTALLED_PACKAGE -> $SHORTPKG... DONE!"
								SHORTTMPLILOCHK=`echo $i | cut -f1 -d'-'`
								if [[ "$SHORTTMPLILOCHK" = "lilo" ]]; then
									lilo -v >/dev/null
								fi
                                                                if [[ "$SHORTTMPLILOCHK" = "kernel" ]]; then
                                                                        lilo -v >/dev/null
                                                                fi
							else
								echo "FAILED!"
								logme "--upgrade" "=> Upgrading $INSTALLED_PACKAGE -> $SHORTPKG... FAILED!"
								rm -f $i.tmp
							fi
                                                        if [[ "$VDEPENDENCY" == "1" ]]; then
								tar tzfv $i 2>/dev/null | grep bin/ | awk '{print$6}' | sed -e 's/.*/'$i':&/' >> $CDIR/TARFILES.tmp
                                                        fi
						else
							echo "=> Upgrading $INSTALLED_PACKAGE -> $SHORTPKG... FAILED!"
							logme "--upgrade" "=> Upgrading $INSTALLED_PACKAGE -> $SHORTPKG... FAILED!"
							rm -f $i.tmp
                                                fi
                                                z=`expr $z + 1`
						b=1
                                        done
					;;
				"n")
					NEWPKGSLIST_FILE=`cat NEWPKGS.list 2>/dev/null`
                                 	INSTALLEDPKGSLIST_FILE=`cat INSTALLEDPKGS.list 2>/dev/null`
					z=1
					a=1
					b=1
					COUNTER=1
					QSWAP=0
					for i in $NEWPKGSLIST_FILE
                                       	do
						for a in $INSTALLEDPKGSLIST_FILE
						do
							if test $b -eq $z 
							then
								INSTALLED_PACKAGE=$a
							fi
							b=`expr $b + 1`
						done 	
						SHORTPKG=`echo $i | sed s/'.tgz'//`
						echo -n "Upgrade $INSTALLED_PACKAGE to $SHORTPKG? (y/n): [y]"
						read answer2
						if [ -z "$answer2" ]; then
							answer2="y"
						else
							if [[ $answer2 != "y" ]]; then
								answer2="n"
							fi
						fi
						QSWAP=1
						case $answer2 in	
							"y")
								echo $INSTALLED_PACKAGE >> INSTALLPKGSLISTOLD.list 2>/dev/null
								echo $i >> INSTALLPKGSLISTNEW.list 2>/dev/null
								;;
							"n")
								;;
							*)	
								invalid_charz
								;;
						esac	
						z=`expr $z + 1`
						b=1
					done
                                        if test $QSWAP -eq 1; then
                                                echo
                                        fi
					CHECK=`cat INSTALLPKGSLISTOLD.list 2>/dev/null | wc -l`
					if test $CHECK -gt 0
					then
						z=1
						a=1
						b=1
						OLDPKGSLIST=`cat INSTALLPKGSLISTOLD.list 2>/dev/null`
						NEWPKGSLIST=`cat INSTALLPKGSLISTNEW.list 2>/dev/null`
						DONE=1
						for i in $NEWPKGSLIST
						do
						   get_pkg()
						   {
							SHORTPKGTMP=`echo $1 | sed s/'.tgz'//`
							PACKAGES_URL=`cat URL 2>/dev/null | awk '{ if(NR == '$2') print $1 }'`
							PACKAGE=`cat CHECKSUMS 2>/dev/null | grep "/$1" | grep / | awk '{print$3}' | sed s/.//`
							if [ ! -z $PACKAGES_URL ]; then
                          	                	  for a in $OLDPKGSLIST
                                	                  do
                                        	                if test $b -eq $z
                                                        	then
                                                                	INSTALLED_PACKAGE=$a
                                                        	fi
                                                        	b=`expr $b + 1`
                                                	  done

							  SHORTPKG=`echo $1 | sed s/'.tgz'//`
							  if [ -f $1 ]; then
                                                        	SIZEPKGTMP=`ls -alL $1 2>/dev/null | awk '{print$5}'`
                                                        	SIZEPKG=`echo $SIZEPKGTMP / 1024 | bc`
                                                                SWAPME=0
                                                                if [[ "$3" = "-p" || "$3" = "-ap" ]]; then
                                                                        MSG "--upgrade [-p|-ap]" "Patch $SHORTPKG ($SIZEPKG kB) found in $CDIR!"
                                                                        check_for_broken_patches $1 1
                                                                        SWAPME=1
                                                                fi
                                                                if [[ "$3" = "-e" || "$3" = "-ae" ]]; then
                                                                        MSG "--upgrade [-e|-ae]" "Extra Package $SHORTPKG ($SIZEPKG kB) found in $CDIR!"
                                                                        check_for_broken_extra $1 1
                                                                        SWAPME=1
                                                                fi
                                                                if test $SWAPME -eq 0
                                                                then
                                                                        MSG "--upgrade" "Package $SHORTPKG ($SIZEPKG kB) found in $CDIR!"
                                                                        check_for_broken_packages $1 1
                                                                        SWAPME=1
                                                                fi
							  else
								SIZEPKGTMP=`cat CHECKSUMS 2>/dev/null | grep "/$1" | awk '{print$2}'`
								SIZEPKG=`echo $SIZEPKGTMP / 1024 | bc`
								GETPKG="$PACKAGE"
								MSG "--upgrade" "[ $PACKAGES_URL ]"
								echo $QS "### Fetching $SHORTPKG ($SIZEPKG kB)... "
								if test `echo $PACKAGES_URL | grep rsync | wc -l` -ge 1
								then
                                                                    if [ ! -z $Q ]; then
									    rsync_file "$PACKAGES_URL" "$PACKAGE"
                                                                            count_size_rsync $1 $3
                                                                    else
									    rsync_file_s "$PACKAGES_URL" "$PACKAGE"
									    touch_it "$1"
                                                                    fi
                                                                else
                                                                    if [ ! -z $Q ]; then
									    wget_file "$PACKAGES_URL" "$PACKAGE"
                                                                            count_size $1 $3
                                                                    else
									    wget_file_s "$PACKAGES_URL" "$PACKAGE"
									    touch_it "$1"
                                                                    fi
								fi
                                               			if [ -f $1.tmp ]; then
									FPKGSW=1
									FPKGTSIZE=`echo "$FPKGTSIZE + $SIZEPKG" | bc`
									FPKGC=`echo "$FPKGC + 1" | bc`
									if [ ! -z $Q ]; then
          		                                          		echo " DONE!"
									fi
									logme "--upgrade" "### Fetching $SHORTPKG ($SIZEPKG kB)... DONE!"
                                                                        SWAPME=0
                                                                        if [[ "$2" = "-p" || "$2" = "-ap" || "$3" = "-p" || "$3" = "-ap" ]]; then
                                                                                checksum_patch $1
                                                                                SWAPME=1
                                                                        fi
                                                                        if [[ "$2" = "-e" || "$2" = "-ae" || "$3" = "-e" || "$3" = "-ae" ]]; then
                                                                                checksum_extra $1
                                                                                SWAPME=1
                                                                        fi
                                                                        if test $SWAPME -eq 0
                                                                        then
                                                                                checksum_package $1
                                                                        fi
									DONE=0
									pgp_check_remote "--upgrade" "$2" "$3" "$1"
								else 
									if [ ! -z $Q ]; then
										echo " FAILED!"
									fi
									logme "--upgrade" "### Fetching $SHORTPKG ($SIZEPKG kB)... FAILED!"
									rm -f $1.tmp
									RECORDS=`cat URL 2>/dev/null | wc -l`
									COUNTER=`expr $COUNTER + 1`
									if test $COUNTER -ne `expr $RECORDS + 1`
									then
									    get_pkg $1 $COUNTER $3
									fi
									DONE=0
								fi
							  fi
							  z=`expr $z + 1`
							  b=1
							fi
						    }
                                                    get_local_pkg()
                                                    {
                                                          SHORTPKG=`echo $1 | sed s/'.tgz'//`
                                                          if [ -f $1 ]; then
                                                        	SIZEPKGTMP=`ls -alL $1 2>/dev/null | awk '{print$5}'`
                                                        	SIZEPKG=`echo $SIZEPKGTMP / 1024 | bc`
                                                                SWAPME=0
                                                                if [[ "$3" = "-p" || "$3" = "-ap" ]]; then
                                                                        MSG "--upgrade [-p|-ap]" "Patch $SHORTPKG ($SIZEPKG kB) found in $CDIR!"
									res_local_pat $1
                                                                        SWAPME=1
                                                                fi
                                                                if [[ "$3" = "-e" || "$3" = "-ae" ]]; then
                                                                        MSG "--upgrade [-e|-ae]" "Extra Package $SHORTPKG ($SIZEPKG kB) found in $CDIR!"
									res_local_ext $1
                                                                        SWAPME=1
                                                                fi
                                                                if test $SWAPME -eq 0
                                                                then
                                                                        MSG "--upgrade" "Package $SHORTPKG ($SIZEPKG kB) found in $CDIR!"
									res_local_pac $1
                                                                fi
                                                          else
							      ROOTS=`cat /etc/swaret.conf | grep -v "#" | grep "^ROOT=" | grep "file:" | cut -f2 -d'=' | sed s/'file:'//`
							      for RR in $ROOTS
							      do
								PACKAGE=`cat CHECKSUMS 2>/dev/null | grep "/$1" | grep / | awk '{print$3}' | sed s/.//`
								SIZEPKGTMP=`cat CHECKSUMS 2>/dev/null | grep "/$1" | awk '{print$2}'`
								SIZEPKG=`echo $SIZEPKGTMP / 1024 | bc`
                                                                MSG "--upgrade" "[ file:$RR ]"
								echo -n "### Copying $SHORTPKG ($SIZEPKG kB)... "
                                                                SWAPME=0
                                                                if [[ "$3" = "-p" || "$3" = "-ap" ]]; then
									copy_file "$RR" "$PACKAGE"
                                                                        SWAPME=1
                                                                fi
                                                                if [[ "$3" = "-e" || "$3" = "-ae" ]]; then
									copy_file "$RR" "$PACKAGE"
                                                                        SWAPME=1
                                                                fi
                                                                if test $SWAPME -eq 0
                                                                then
									copy_file "$RR" "$PACKAGE"
                                                                fi
                                                                if [ -f $1 ]; then
                                                			FPKGSW=1
                                                			FPKGTSIZE=`echo "$FPKGTSIZE + $SIZEPKG" | bc` 
                                                			FPKGC=`echo "$FPKGC + 1" | bc`
                                                                        echo " DONE!"
									logme "--upgrade" "### Copying $SHORTPKG ($SIZEPKG kB)... DONE!"
                                                                        SWAPME=0
                                                                        if [[ "$2" = "-p" || "$2" = "-ap" || "$3" = "-p" || "$3" = "-ap" ]]; then
                                                                                checksum_patch $1
                                                                                SWAPME=1
                                                                        fi
                                                                        if [[ "$2" = "-e" || "$2" = "-ae" || "$3" = "-e" || "$3" = "-ae" ]]; then
                                                                                checksum_extra $1
                                                                                SWAPME=1
                                                                        fi
                                                                        if test $SWAPME -eq 0
                                                                        then
                                                                                checksum_package $1
                                                                        fi
                                                                        DONE=0
									pgp_check_local "--upgrade" "$2" "$3" "$1"
									break
                                                                else
                                                                        echo " FAILED!"
									logme "--upgrade" "### Copying $SHORTPKG ($SIZEPKG kB)... FAILED!"
                                                                fi
							    done
							  fi
                                                    }
						    if test $DONE -eq 1
						    then
                                                      if test `cat /etc/swaret.conf | grep -v "#" | grep "^ROOT=" | grep "file:" | wc -l` -ge 1
                                                      then
                                                        SWAPME=0
                                                        if [[ "$2" = "-p" || "$2" = "-ap" || "$2" = "-e" || "$2" = "-ae" ]]; then
                                                                get_local_pkg "$i" 1 $2
                                                                SWAPME=1
                                                        fi
                                                        if [[ "$3" = "-p" || "$3" = "-ap" || "$3" = "-e" || "$3" = "-ae" ]]; then
                                                                get_local_pkg "$i" 1 $3
                                                                SWAPME=1
                                                        fi
                                                        if test $SWAPME -eq 0
                                                        then
                                                                get_local_pkg "$i" 1 "-a"
                                                        fi
                                                      else
                                                        SWAPME=0
                                                        if [[ "$2" = "-p" || "$2" = "-ap" || "$2" = "-e" || "$2" = "-ae" ]]; then
                                                                get_pkg "$i" 1 $2
                                                                SWAPME=1
                                                        fi
                                                        if [[ "$3" = "-p" || "$3" = "-ap" || "$3" = "-e" || "$3" = "-ae" ]]; then
                                                                get_pkg "$i" 1 $3
                                                                SWAPME=1
                                                        fi
                                                        if test $SWAPME -eq 0
                                                        then
                                                                get_pkg "$i" 1 "-a"
                                                        fi
                                                      fi
					  	    fi
						    DONE=1
						    COUNTER=1
						done
                                                z=1
                                                a=1
                                                b=1
                                                OLDPKGSLIST=`cat INSTALLPKGSLISTOLD.list 2>/dev/null`
                                                NEWPKGSLIST=`cat INSTALLPKGSLISTNEW.list 2>/dev/null`
                                        if test $FPKGSW -eq 1
                                        then
                                         if test $FPKGC -ge 1
                                         then
                                          if test `cat /etc/swaret.conf | grep -v "#" | grep "^ROOT=" | grep "file:" | wc -l` -ge 1; then
                                            if test $FPKGC -eq 1
                                            then
                                                MSG "--upgrade" "Copied $FPKGC File with a Size of $FPKGTSIZE kB!"
                                            else
                                                MSG "--upgrade" "Copied $FPKGC Files with a Total Size of $FPKGTSIZE kB!"
                                            fi  
                                          else
                                            if test $FPKGC -eq 1
                                            then
                                                MSG "--upgrade" "Downloaded $FPKGC File with a Size of $FPKGTSIZE kB!"
                                            else
                                                MSG "--upgrade" "Downloaded $FPKGC Files with a Total Size of $FPKGTSIZE kB!"
                                            fi  
                                          fi
                                         fi
                                        fi
                                                for i in $NEWPKGSLIST
                                                do
                                                        for a in $OLDPKGSLIST
                                                        do
                                                                if test $b -eq $z
                                                                then
                                                                        INSTALLED_PACKAGE=$a
                                                                fi
                                                                b=`expr $b + 1`
                                                        done
							SHORTPKG=`echo $i | sed s/'.tgz'//`
							if [ -f $i.tmp ] || [ -f $i ]; then
								echo -n "=> Upgrading $INSTALLED_PACKAGE -> $SHORTPKG... "
								if [ ! -f $PACKAGES_LOGDIR/$INSTALLED_PACKAGE ]; then
									touch $PACKAGES_LOGDIR/$INSTALLED_PACKAGE 
								fi
								if [ -f $PACKAGES_LOGDIR/$SHORTPKG ]; then
									rm -f $PACKAGES_LOGDIR/$SHORTPKG 
								fi
								check_size_pkg $i
								if [ ! -f $i*.corrupted ]; then
								if [[ "$DESC" = "NO" ]]; then
									upgradepkg $i >/dev/null 2>&1
								else
									upgradepkg $i
								fi
								fi
                                                                FIX=`echo $i | sed s/'.tgz'/' '/`
                                                                if [ -f $PACKAGES_LOGDIR/$FIX ]; then
                                                                       	echo "DONE!"
									logme "--upgrade" "=> Upgrading $INSTALLED_PACKAGE -> $SHORTPKG... DONE!"
									SHORTTMPLILOCHK=`echo $i | cut -f1 -d'-'`
                                                                	if [[ "$SHORTTMPLILOCHK" = "lilo" ]]; then
                                                                        	lilo >/dev/null 
                                                                	fi
                                                                	if [[ "$SHORTTMPLILOCHK" = "kernel" ]]; then
                                                                        	lilo -v >/dev/null
                                                                	fi
                                                                else 
                                                                      	echo "FAILED!"
									logme "--upgrade" "=> Upgrading $INSTALLED_PACKAGE -> $SHORTPKG... FAILED!"
                                                                       	rm -f $i.tmp
								fi
                                                        	if [[ "$VDEPENDENCY" == "1" ]]; then
									tar tzfv $i 2>/dev/null | grep bin/ | awk '{print$6}' | sed -e 's/.*/'$i':&/' >> $CDIR/TARFILES.tmp
                                                        	fi
                                                        else 
								echo "=> Upgrading $INSTALLED_PACKAGE -> $SHORTPKG... FAILED!"
								logme "--upgrade" "=> Upgrading $INSTALLED_PACKAGE -> $SHORTPKG... FAILED!"
                                                                rm -f $i.tmp
                                                        fi
                                                        z=`expr $z + 1`
                                                        b=1
						done
					fi
					;;
				*)
					invalid_charz
					;;
			esac
			if [ -z $5 ]; then
				echo
			fi
                        if [[ $VDEPENDENCY = 1 ]]; then
                                if test `cat $CDIR/TARFILES.tmp 2>/dev/null | wc -l` -gt 0; then
					echo
					if [[ "$DINTERACTIVE" = "1" ]]; then
						dependency_interactive_check
					else
                                        	dependency_check
					fi
                                fi
                        fi
}

function_install()
{
			if [ -z $5 ]; then
				echo
			fi
			cleanup_quick
			URL

			copy_from_cache

			SWAPME=0
                        if [[ "$3" = "-p" || "$3" = "-ap" ]]; then
                                check_patch_files
				TRIGVAR=patches
				SWAPME=1				
                        fi
                        if [[ "$3" = "-e" || "$3" = "-ae" ]]; then
                                check_extra_files
				TRIGVAR=extra
				SWAPME=1
                        fi
			if test $SWAPME -eq 0
			then
                                check_package_files
				TRIGVAR=slackware
                        fi

                        if [ -z "$2" ]; then
                                MSGERR "--install" "Please, provide a Keyword to Install!"
                        fi
                        export GO=0
                        echo "$2" | grep -q '^[[:alpha:]]\+' && export GO=1
                        if test $GO -eq 0
                        then
				invalid_charz
                        fi

			check_ipkg()
			{
				SHORT=`echo $1 | sed s/'.tgz'//`
                                if [ -f $PACKAGES_LOGDIR/$SHORT ]; then
					NEWSWAP=0
					NSWAP=1
					if [[ "$2" == "-p" || "$2" == "-ap" ]]; then
						touch $SHORT.zmp
                                        	MSG "--install" "Patch $SHORT is already installed!"
						NEWSWAP=1
					fi
                                        if [[ "$2" == "-e" || "$2" == "-ae" ]]; then
						touch $SHORT.zmp
                                                MSG "--install" "Extra Package $SHORT is already installed!"
						NEWSWAP=1
                                        fi
					if test $NEWSWAP -eq 0
					then
						touch $SHORT.zmp
                                                MSG "--install" "Package $SHORT is already installed!"
                                        fi
					touch $1.pmt
                                fi
			}

			install_pkg()
			{	
				   xSWAP=0
                                   if [ -f $1.tgz ]; then
					xSWAP=1
				   fi
				   if [ -f $1.tgz.tmp ]; then
					xSWAP=1
				   fi
				   if test $xSWAP -eq 1
				   then
                                        echo -n "=> Installing $1... " 
					check_size_pkg $1.tgz
					if [ ! -f $1*.corrupted ]; then
					if [[ "$DESC" = "NO" ]]; then
						installpkg $1.tgz >/dev/null 2>&1
					else
						installpkg $1.tgz
					fi
					fi
                                        if [ -f $PACKAGES_LOGDIR/$1 ]; then
                                                echo "DONE!"
						logme "--install" "=> Installing $1... DONE!"
                                        else
                                                echo "FAILED!"
						logme "--install" "=> Installing $1... FAILED!"
                                                rm -f $1.tgz.tmp
                                        fi
                                        if [[ "$VDEPENDENCY" == "1" ]]; then
						tar tzfv $1.tgz 2>/dev/null | grep bin/ | awk '{print$6}' | sed -e 's/.*/'$i':&/' >> $CDIR/TARFILES.tmp
                                        fi
                                   else
					if [ ! -z $Q ]; then
                                        	MSG "--install" "=> Installing $1... FAILED!"
					else
						MSG "--install" "=> Installing $1... "
					fi
                                        rm -f $1.tgz.tmp
				   fi
			}

                        download_pkg()
                        {
			   DONE=1
			   COUNTER=1
			   get_pkg()
			   {
			      SHORTPKG=`echo $1 | sed s/'.tgz'//`
			      if [ -f $1 ]; then
                                        SIZEPKGTMP=`ls -alL $1 2>/dev/null | awk '{print$5}'`
                                        SIZEPKG=`echo $SIZEPKGTMP / 1024 | bc`
					SWAPME=0
					if [[ "$3" = "-p" || "$3" = "-ap" ]]; then
						MSG "--install" "Patch $SHORTPKG ($SIZEPKG kB) found in $CDIR!"
                                        	check_for_broken_patches $1 1
                                        	SWAPME=1
					fi
                                        if [[ "$3" = "-e" || "$3" = "-ae" ]]; then
						MSG "--install" "Extra Package $SHORTPKG ($SIZEPKG kB) found in $CDIR!"
                                                check_for_broken_extra $1 1
                                                SWAPME=1
                                        fi
					if test $SWAPME -eq 0
					then
						MSG "--install" "Package $SHORTPKG ($SIZEPKG kB) found in $CDIR!"
                                                check_for_broken_packages $1 1
                                        fi
                              else
				  PACKAGES_URL=`cat URL 2>/dev/null | awk '{ if(NR == '$2') print $1 }'`
				  SWAPME=0
				  if [[ "$3" = "-p" || "$3" = "-ap" ]]; then
			                PACKAGE=`cat CHECKSUMS.patches 2>/dev/null | grep "/$1" | awk '{print$3}' | grep "/" | sed s/.//`
				        SWAPME=1
				  fi
				  if [[ "$3" = "-e" || "$3" = "-ae" ]]; then
				        PACKAGE=`cat CHECKSUMS.extra 2>/dev/null | grep "/$1" | awk '{print$3}' | grep "/" | sed s/.//`
				        SWAPME=1
				  fi
				  if test $SWAPME -eq 0
				  then
                                        PACKAGE=`cat CHECKSUMS 2>/dev/null | grep "/$1" | grep / | awk '{print$3}' | sed s/.//`
				  fi
                                  SIZEPKGTMP=`cat CHECKSUMS 2>/dev/null | grep "/$1" | awk '{print$2}'`
				  SIZEPKG=`echo $SIZEPKGTMP / 1024 | bc`
				  GETPKG="$PACKAGE"
				  if [ ! -z $PACKAGES_URL ]; then
                                        MSG "--install" "[ $PACKAGES_URL ]"
					echo $QS "### Fetching $SHORTPKG ($SIZEPKG kB)... "
					if test `echo $PACKAGES_URL | grep rsync | wc -l` -ge 1
					then
						if [ ! -z $Q ]; then
							rsync_file "$PACKAGES_URL" "$PACKAGE"
							count_size_rsync $1 $3
						else
							rsync_file_s "$PACKAGES_URL" "$PACKAGE"
							touch_it "$1"
						fi
					else
						if [ ! -z $Q ]; then
							wget_file "$PACKAGES_URL" "$PACKAGE"
                                        		count_size $1 $3
						else
							wget_file_s "$PACKAGES_URL" "$PACKAGE"
							touch_it "$1"
						fi
					fi
                                        if [ -f $1.tmp ]; then
						FPKGSW=1
						FPKGTSIZE=`echo "$FPKGTSIZE + $SIZEPKG" | bc`
						FPKGC=`echo "$FPKGC + 1" | bc`
						if [ ! -z $Q ]; then
                                                	echo " DONE!"
						fi
						logme "--install" "### Fetching $SHORTPKG ($SIZEPKG kB)... DONE!"
						SWAPME=0
						if [[ "$3" = "-p" || "$3" = "-ap" ]]; then
							checksum_patch $1
							SWAPME=1
						fi
						if [[ "$3" = "-e" || "$3" = "-ae" ]]; then
							checksum_extra $1
							SWAPME=1
						fi
						if test $SWAPME -eq 0
						then
							checksum_package $1
						fi
						DONE=0
						pgp_check_remote "--install" "$3" "$3" "$1"
                                        else
						if [ ! -z $Q ]; then
                                                	echo " FAILED!"
						fi
						logme "--install" "### Fetching $SHORTPKG ($SIZEPKG kB)... FAILED!"
                                                rm -f $1.tmp
						RECORDS=`cat URL 2>/dev/null | wc -l`
						COUNTER=`expr $COUNTER + 1`
						if test $COUNTER -ne `expr $RECORDS + 1`
						then
							get_pkg $1 $COUNTER $3
						fi
						DONE=0
						
                                        fi
				  fi
                              fi
			   }
			   if test $DONE -eq 1
			   then
				   if [ -z "$2" ]; then
				   	get_pkg "$1.tgz" 1 "-a"
				   else
					get_pkg "$1.tgz" 1 $2
				   fi
			   fi
			   COUNTER=1
			   DONE=1
				   
                        }

                        copy_pkg()
                        {
                           DONE=1
                           COUNTER=1
                           get_pkg()
                           {
                              SHORTPKG=`echo $1 | sed s/'.tgz'//`
                              if [ ! -f $1 ]; then
				ROOTS=`cat /etc/swaret.conf | grep -v "#" | grep "^ROOT=" | grep "file:" | cut -f2 -d'=' | sed s/'file:'//`
				for RR in $ROOTS
				do
                                  SWAPME=0
                                  if [[ "$3" = "-p" || "$3" = "-ap" ]]; then
                                        PACKAGE=`cat CHECKSUMS.patches 2>/dev/null | grep "/$1" | awk '{print$3}' | grep "/" | sed s/.//`
                                        SWAPME=1
                                  fi
                                  if [[ "$3" = "-e" || "$3" = "-ae" ]]; then
                                        PACKAGE=`cat CHECKSUMS.extra 2>/dev/null | grep "/$1" | awk '{print$3}' | grep "/" | sed s/.//`
                                        SWAPME=1
                                  fi
                                  if test $SWAPME -eq 0
                                  then
                                        PACKAGE=`cat CHECKSUMS 2>/dev/null | grep "/$1" | grep / | awk '{print$3}' | sed s/.//`
                                  fi
                                  if [ ! -z $RR ]; then
					TMPTRIGVAR=slackware
					SIZEPKGTMP=`cat CHECKSUMS 2>/dev/null | grep "/$1" | awk '{print$2}'`
					SIZEPKG=`echo $SIZEPKGTMP / 1024 | bc`
                                        MSG "--install" "[ file:$RR ]"
                                        echo -n "### Copying $SHORTPKG ($SIZEPKG kB)... "
                                        SWAPME=0
                                        if [[ "$3" = "-p" || "$3" = "-ap" ]]; then
						copy_file "$RR" "$PACKAGE"
					  TMPTRIGVAR=patches
                                          SWAPME=1
                                        fi 
                                        if [[ "$3" = "-e" || "$3" = "-ae" ]]; then
						copy_file "$RR" "$PACKAGE"
					  TMPTRIGVAR=extra
                                          SWAPME=1
                                        fi 
                                        if test $SWAPME -eq 0
                                        then
						copy_file "$RR" "$PACKAGE"
					  TMPTRIGVAR=slackware
					fi
                                        if [ -f $1 ]; then
                                                FPKGSW=1
                                                FPKGTSIZE=`echo "$FPKGTSIZE + $SIZEPKG" | bc` 
                                                FPKGC=`echo "$FPKGC + 1" | bc`
                                                echo "DONE!"
						logme "--install" "### Copying $SHORTPKG ($SIZEPKG kB)... DONE!"
                                                SWAPME=0
                                                if [[ "$3" = "-p" || "$3" = "-ap" ]]; then
                                                        checksum_patch $1
                                                        SWAPME=1
                                                fi
                                                if [[ "$3" = "-e" || "$3" = "-ae" ]]; then
                                                        checksum_extra $1
                                                        SWAPME=1
                                                fi
                                                if test $SWAPME -eq 0
                                                then
                                                        checksum_package $1
                                                fi
                                                DONE=0
						pgp_check_local "--install" "$3" "$3" "$1"
						break
                                        else
                                                echo "FAILED!"
						logme "--install" "### Copying $SHORTPKG ($SIZEPKG kB)... FAILED!"
                                        fi
                                  else
					SIZEPKGTMP=`cat CHECKSUMS 2>/dev/null | grep "/$1" | awk '{print$2}'`
					SIZEPKG=`echo $SIZEPKGTMP / 1024 | bc`
                                        MSG "--install" "### Copying $SHORTPKG ($SIZEPKG kB)... FAILED!"
                                  fi
				done
			      else
                                        SWAPME=0
                			SIZEPKGTMP=`cat CHECKSUMS 2>/dev/null | grep "/$1" | awk '{print$2}'`
                			SIZEPKG=`echo $SIZEPKGTMP / 1024 | bc`
                                        if [[ "$3" = "-p" || "$3" = "-ap" ]]; then
                                                MSG "--install" "Patch $SHORTPKG ($SIZEPKG kB) found in $CDIR!"
						res_local_pat $1
                                                SWAPME=1
                                        fi
                                        if [[ "$3" = "-e" || "$3" = "-ae" ]]; then
                                                MSG "--install" "Extra Package $SHORTPKG ($SIZEPKG kB) found in $CDIR!"
						res_local_ext $1
                                                SWAPME=1
                                        fi
                                        if test $SWAPME -eq 0
                                        then
                                                MSG "--install" "Package $SHORTPKG ($SIZEPKG kB) found in $CDIR!"
						res_local_pac $1
                                        fi
                              fi
                           }
                           if test $DONE -eq 1
                           then
                                   if [ -z "$2" ]; then
                                        get_pkg "$1.tgz" 1 "-a"
                                   else
                                        get_pkg "$1.tgz" 1 $2
                                   fi
                           fi
                           COUNTER=1
                           DONE=1
                        }

			SWAPME=0
			SHORTPKGTMP=`echo $2 | sed s/'.tgz'//`
			FPKGSW=0
			FPKGTSIZE=0
			FPKGC=0
                        if [[ "$3" = "-p" || "$3" = "-ap" ]]; then
			  swap_to_patches
			  make_patches_list
                          CHECKPKG=`cat CHECKSUMS.md5.patches.tmp 2>/dev/null | grep "$2" | sort`
                          CHECK=`cat CHECKSUMS.md5.patches.tmp 2>/dev/null | grep "$2" | wc -l`
                          SWAPME=1
                        fi
                        if [[ "$3" = "-e" || "$3" = "-ae" ]]; then
			  swap_to_extra
			  make_extra_list
                          CHECKPKG=`cat CHECKSUMS.md5.extra.tmp 2>/dev/null | grep "$2" | sort`
                          CHECK=`cat CHECKSUMS.md5.extra.tmp 2>/dev/null | grep "$2" | wc -l`
			  SWAPME=1
			fi
			if test $SWAPME -eq 0
			then
                          CHECKPKG=`cat CHECKSUMS.md5 2>/dev/null | grep "$2" | sed -e "s/.*\///g" | sort`
                          CHECK=`cat CHECKSUMS.md5 2>/dev/null | grep "$2" | wc -l`
			fi
			if test $CHECK -eq 0
                        then
			 	SWAPME=0
			 	if [[ "$3" = "-p" || "$3" = "-ap" ]]; then
					MSGERR "--install [-p|-ap]" "No available Patches found matching Keyword: $2!"
					SWAPME=1
			 	fi
			 	if [[ "$3" = "-e" || "$3" = "-ae" ]]; then
					MSGERR "--install [-e|-ae]" "No available Extra Packages found matching Keyword: $2!"
					SWAPME=1
			  	fi
				if test $SWAPME -eq 0
				then	
					MSGERR "--install" "No available Packages found matching Keyword: $2!"
				fi
                        fi
                        if test $CHECK -gt 0
			then
				SWAPME=0
				TRIGVAR=""
				if [[ "$3" = "-p" || "$3" = "-ap" ]]; then
					echo "Making a List of available Patches matching Keyword: $2..."	
					SWAPME=1
					TRIGVAR="Patches"
				fi
				if [[ "$3" = "-e" || "$3" = "-ae" ]]; then
					echo "Making a List of available Extra Packages matching Keyword: $2..."
					SWAPME=1
					TRIGVAR="Extra Packages"
				fi
				if test $SWAPME -eq 0
				then
					echo "Making a List of available Packages matching Keyword: $2..."
					TRIGVAR="Packages"
				fi
				SWITCH=0
				if [[ "$3" = "-a" || "$3" = "-ap" || "$3" = "-ae" ]]; then
                                        z=0
                                        xCOUNTER=0
                                        zCOUNTER=0
                                        for i in $CHECKPKG
                                        do
                                                xCOUNTER=`expr $xCOUNTER + 1`
                                        done
					for i in $CHECKPKG
					do
                                                FIX=`echo $i | sed s/'.tgz'//`
                                        	SIZEPKGTMP=`cat $CDIR/CHECKSUMS 2>/dev/null | grep "/$i" | awk '{print$2}'`
                                        	SIZEPKG=`echo "$SIZEPKGTMP / 1024" | bc`
                                        	echo "$FIX ($SIZEPKG kB)"
                                                zCOUNTER=`expr $zCOUNTER + 1`
						if [[ "$zCOUNTER" != "$xCOUNTER" ]]; then
                                                	ls_break "Packages"
						fi
					done
					echo
                                	for i in $CHECKPKG
                                	do
						FIX=`echo $i | sed s/'.tgz'//`
						check_ipkg $FIX $3 
					done
					for i in $CHECKPKG
					do
						FIX=`echo $i | sed s/'.tgz'//`
						if [ ! -f $FIX.pmt ]; then
							if test `cat /etc/swaret.conf | grep -v "#" | grep "^ROOT=" | grep "file:" | wc -l` -ge 1
							then
								copy_pkg $FIX $3 $3
							else
								download_pkg $FIX $3
							fi
						fi
                                	done
                                        if [ ! -f $FIX.pmt ]; then
                                        if test $FPKGSW -eq 1
                                        then
                                         if test $FPKGC -ge 1
                                         then
                                          if test `cat /etc/swaret.conf | grep -v "#" | grep "^ROOT=" | grep "file:" | wc -l` -ge 1; then
                                            if test $FPKGC -eq 1
                                            then
                                                MSG "--install" "Copied $FPKGC File with a Size of $FPKGTSIZE kB!"
                                            else
                                                MSG "--install" "Copied $FPKGC Files with a Total Size of $FPKGTSIZE kB!"
                                            fi  
                                          else
                                            if test $FPKGC -eq 1
                                            then
                                                MSG "--install" "Downloaded $FPKGC File with a Size of $FPKGTSIZE kB!"
                                            else
                                                MSG "--install" "Downloaded $FPKGC Files with a Total Size of $FPKGTSIZE kB!"
                                            fi  
                                          fi
                                         fi
                                        fi
                                        fi
					for i in $CHECKPKG
					do
						FIX=`echo $i | sed s/'.tgz'//`
						if [ ! -f $FIX.pmt ]; then
							install_pkg $FIX $3
						fi
					done
					for i in $CHECKPKG
					do
						FIX=`echo $i | sed s/'.tgz'//`
						rm -f $FIX.pmt
					done
					SWITCH=1
				fi
				if test $SWITCH -eq 0
				then
					z=0
					xCOUNTER=0
					zCOUNTER=0
					for i in $CHECKPKG
					do
						xCOUNTER=`expr $xCOUNTER + 1`
					done
					for i in $CHECKPKG
					do
						FIX=`echo $i | sed s/'.tgz'//`
                                                SIZEPKGTMP=`cat $CDIR/CHECKSUMS 2>/dev/null | grep "/$i" | awk '{print$2}'`
                                                SIZEPKG=`echo "$SIZEPKGTMP / 1024" | bc`
                                                echo "$FIX ($SIZEPKG kB)"
                                                zCOUNTER=`expr $zCOUNTER + 1`
						if [[ "$zCOUNTER" != "$xCOUNTER" ]]; then
                                                	ls_break "Packages"
						fi
					done
					echo
					QSWAP=0
					for i in $CHECKPKG
					do
					    SHORTPKG=`echo $i | sed s/'.tgz'//`
					    check_ipkg $SHORTPKG $3
				   	    if [ ! -f $SHORTPKG.pmt ]; then
						echo -n "Install $SHORTPKG? (y/n): [y]"
						read answer
						if [ -z "$answer" ]; then
							answer="y"
						else
							if [[ $answer != "y" ]]; then
								answer="n"
							fi
						fi
						logme "--install" "Install $SHORTPKG? (y/n): [$answer]"
						case $answer in 
							"y")
								QSWAP=1
								echo $SHORTPKG >> PKGTOINSTALLLIST.list
								;;
							"n")
								;;
							*)
								invalid_charz
								;;
						esac
					    fi
					done
                                        if test $QSWAP -eq 1; then
                                                echo
                                        fi
					if [ -f PKGTOINSTALLLIST.list ]; then
						PKGTOINSTALLLIST=`cat PKGTOINSTALLLIST.list 2>/dev/null`
						for i in $PKGTOINSTALLLIST
						do
							FIX=`echo $i | sed s/'.tgz'//`
							if [ ! -f $FIX.pmt ]; then
                                                        	if test `cat /etc/swaret.conf | grep -v "#" | grep "^ROOT=" | grep "file:" | wc -l` -ge 1
                                                        	then
                                                                	copy_pkg $FIX $3 $3
                                                        	else
                                                                	download_pkg $FIX $3
                                                        	fi
							fi
						done
                                        if test $FPKGSW -eq 1
                                        then
                                         if test $FPKGC -ge 1
                                         then
                                          if test `cat /etc/swaret.conf | grep -v "#" | grep "^ROOT=" | grep "file:" | wc -l` -ge 1; then
                                            if test $FPKGC -eq 1
                                            then
                                                MSG "--install" "Copied $FPKGC File with a Size of $FPKGTSIZE kB!"
                                            else
                                                MSG "--install" "Copied $FPKGC Files with a Total Size of $FPKGTSIZE kB!"
                                            fi  
                                          else
                                            if test $FPKGC -eq 1
                                            then
                                                MSG "--install" "Downloaded $FPKGC File with a Size of $FPKGTSIZE kB!"
                                            else
                                                MSG "--install" "Downloaded $FPKGC Files with a Total Size of $FPKGTSIZE kB!"
                                            fi  
                                          fi
                                         fi
                                        fi
                                                for i in $PKGTOINSTALLLIST
                                                do
							FIX=`echo $i | sed s/'.tgz'//`
							if [ ! -f $FIX.pmt ]; then
                                                        	install_pkg $FIX $3
							fi
                                                done
						for i in $PKGTOINSTALLLIST
						do	
							FIX=`echo $i | sed s/'.tgz'//`
							if [ -f $FIX.pmt ]; then
								rm -f $FIX.pmt
							fi
						done
					fi
				fi
			fi
			if [ -z $5 ]; then
				echo
			fi
                        if [[ $VDEPENDENCY = 1 ]]; then
				if test `cat $CDIR/TARFILES.tmp 2>/dev/null | wc -l` -gt 0; then
					echo
                                        if [[ "$DINTERACTIVE" = "1" ]]; then
                                                dependency_interactive_check
                                        else
                                                dependency_check
                                        fi
				fi
                        fi
}

function_reinstall()
{
                        if [ -z $5 ]; then
                                echo
                        fi
                        cleanup_quick
                        URL

                        copy_from_cache

                        SWAPME=0
                        if [[ "$3" = "-p" || "$3" = "-ap" ]]; then
                                check_patch_files
                                TRIGVAR=patches
                                SWAPME=1
                                logme "--reinstall" "Re-installing Patches matching Keyword: $2..."
                        fi
                        if [[ "$3" = "-e" || "$3" = "-ae" ]]; then
                                check_extra_files
                                TRIGVAR=extra
                                SWAPME=1
                                logme "--reinstall" "Re-installing Extra Packages matching Keyword: $2..."
                        fi
                        if test $SWAPME -eq 0
                        then
                                check_package_files
                                TRIGVAR=slackware
                                logme "--reinstall" "Re-installing Packages matching Keyword: $2..."
                        fi

                        if [ -z "$2" ]; then
                                MSGERR "--reinstall" "Please, provide a Keyword to Install!"
                        fi
                        export GO=0
                        echo "$2" | grep -q '^[[:alpha:]]\+' && export GO=1
                        if test $GO -eq 0
                        then
				invalid_charz
                        fi

                        reinstall_pkg()
                        {
                                   xSWAP=0
                                   if [ -f $1.tgz ]; then
                                        xSWAP=1
                                   fi
                                   if [ -f $1.tgz.tmp ]; then
                                        xSWAP=1
                                   fi
                                   if test $xSWAP -eq 1
                                   then
                                        echo -n "=> Re-Installing $1... "
					check_size_pkg $1.tgz
					if [ ! -f $1*.corrupted ]; then
                                        if [[ "$DESC" = "NO" ]]; then
                                                installpkg $1.tgz >/dev/null 2>&1
                                        else
                                                installpkg $1.tgz
                                        fi
					fi
                                        if [ -f $PACKAGES_LOGDIR/$1 ]; then
                                                echo "DONE!"
                                                logme "--reinstall" "=> Re-Installing $1... DONE!"
                                        else
                                                echo "FAILED!"
                                                logme "--reinstall" "=> Re-Installing $1... FAILED!"
                                                rm -f $1.tgz.tmp
                                        fi
                                        if [[ "$VDEPENDENCY" == "1" ]]; then
						tar tzfv $1.tgz 2>/dev/null | grep bin/ | awk '{print$6}' | sed -e 's/.*/'$i':&/' >> $CDIR/TARFILES.tmp
                                        fi
                                   else
                                        if [ ! -z $Q ]; then
                                                MSG "--reinstall" "=> Re-Installing $1... FAILED!"
                                        else
                                                MSG "--reinstall" "=> Re-Installing $1... "
                                        fi
                                        rm -f $1.tgz.tmp
                                   fi
                        }

                        download_pkg()
                        {
                           DONE=1
                           COUNTER=1
                           get_pkg()
                           {
                              SHORTPKG=`echo $1 | sed s/'.tgz'//`
                              if [ -f $1 ]; then
                                        SIZEPKGTMP=`ls -alL $1 2>/dev/null | awk '{print$5}'`
                                        SIZEPKG=`echo $SIZEPKGTMP / 1024 | bc`
                                        SWAPME=0
                                        if [[ "$3" = "-p" || "$3" = "-ap" ]]; then
                                                MSG "--reinstall" "Patch $SHORTPKG ($SIZEPKG kB) found in $CDIR!"
                                                check_for_broken_patches $1 1
                                                SWAPME=1
                                        fi
                                        if [[ "$3" = "-e" || "$3" = "-ae" ]]; then
                                                MSG "--reinstall" "Extra Package $SHORTPKG ($SIZEPKG kB) found in $CDIR!"
                                                check_for_broken_extra $1 1
                                                SWAPME=1
                                        fi
                                        if test $SWAPME -eq 0
                                        then
                                                MSG "--reinstall" "Package $SHORTPKG ($SIZEPKG kB) found in $CDIR!"
                                                check_for_broken_packages $1 1
                                        fi
                              else
                                  PACKAGES_URL=`cat URL 2>/dev/null | awk '{ if(NR == '$2') print $1 }'`
                                  SWAPME=0
                                  if [[ "$3" = "-p" || "$3" = "-ap" ]]; then
                                        PACKAGE=`cat CHECKSUMS.patches 2>/dev/null | grep "/$1" | awk '{print$3}' | grep "/" | sed s/.//`
                                        SWAPME=1
                                  fi
                                  if [[ "$3" = "-e" || "$3" = "-ae" ]]; then
                                        PACKAGE=`cat CHECKSUMS.extra 2>/dev/null | grep "/$1" | awk '{print$3}' | grep "/" | sed s/.//`
                                        SWAPME=1
                                  fi
                                  if test $SWAPME -eq 0
                                  then
                                        PACKAGE=`cat CHECKSUMS 2>/dev/null | grep "/$1" | grep / | awk '{print$3}' | sed s/.//`
                                  fi
                                  SIZEPKGTMP=`cat CHECKSUMS 2>/dev/null | grep "/$1" | awk '{print$2}'`
                                  SIZEPKG=`echo $SIZEPKGTMP / 1024 | bc`
				  GETPKG="$PACKAGE"
                                  if [ ! -z $PACKAGES_URL ]; then
                                        MSG "--reinstall" "[ $PACKAGES_URL ]"
                                        echo $QS "### Fetching $SHORTPKG ($SIZEPKG kB)... "
                                        if test `echo $PACKAGES_URL | grep rsync | wc -l` -ge 1
                                        then
                                                if [ ! -z $Q ]; then
							rsync_file "$PACKAGES_URL" "$PACKAGE"
                                                        count_size_rsync $1 $3
                                                else
							rsync_file_s "$PACKAGES_URL" "$PACKAGE"
							touch_it "$1"
                                                fi
                                        else
                                                if [ ! -z $Q ]; then
							wget_file "$PACKAGES_URL" "$PACKAGE"
                                                        count_size $1 $3
                                                else
							wget_file_s "$PACKAGES_URL" "$PACKAGE"
							touch_it "$1"
                                                fi
                                        fi
                                        if [ -f $1.tmp ]; then
                                                FPKGSW=1
                                                FPKGTSIZE=`echo "$FPKGTSIZE + $SIZEPKG" | bc`
                                                FPKGC=`echo "$FPKGC + 1" | bc`
                                                if [ ! -z $Q ]; then
                                                        echo " DONE!"
                                                fi
                                                logme "--reinstall" "### Fetching $SHORTPKG ($SIZEPKG kB)... DONE!"
                                                SWAPME=0
                                                if [[ "$3" = "-p" || "$3" = "-ap" ]]; then
                                                        checksum_patch $1
                                                        SWAPME=1
                                                fi
                                                if [[ "$3" = "-e" || "$3" = "-ae" ]]; then
                                                        checksum_extra $1
                                                        SWAPME=1
                                                fi
                                                if test $SWAPME -eq 0
                                                then
                                                        checksum_package $1
                                                fi
                                                DONE=0
						pgp_check_remote "--reinstall" "$3" "$3" "$1"
                                        else
                                                if [ ! -z $Q ]; then
                                                        echo " FAILED!"
                                                fi
                                                logme "--reinstall" "### Fetching $SHORTPKG ($SIZEPKG kB)... FAILED!"
                                                rm -f $1.tmp
                                                RECORDS=`cat URL 2>/dev/null | wc -l`
                                                COUNTER=`expr $COUNTER + 1`
                                                if test $COUNTER -ne `expr $RECORDS + 1`
                                                then
                                                        get_pkg $1 $COUNTER $3
                                                fi
                                                DONE=0

                                        fi
                                  fi
                              fi
                           }
                           if test $DONE -eq 1
                           then
                                   if [ -z "$2" ]; then
                                        get_pkg "$1.tgz" 1 "-a"
                                   else
                                        get_pkg "$1.tgz" 1 $2
                                   fi
                           fi
                           COUNTER=1
                           DONE=1

                        }
                        copy_pkg()
                        {
                           DONE=1
                           COUNTER=1
                           get_pkg()
                           {
                              SHORTPKG=`echo $1 | sed s/'.tgz'//`
                              if [ ! -f $1 ]; then
				ROOTS=`cat /etc/swaret.conf | grep -v "#" | grep "^ROOT=" | grep "file:" | cut -f2 -d'=' | sed s/'file:'//`
				for RR in $ROOTS
				do
                                  SWAPME=0
                                  if [[ "$3" = "-p" || "$3" = "-ap" ]]; then
                                        PACKAGE=`cat CHECKSUMS.patches 2>/dev/null | grep "/$1" | awk '{print$3}' | grep "/" | sed s/.//`
                                        SWAPME=1
                                  fi
                                  if [[ "$3" = "-e" || "$3" = "-ae" ]]; then
                                        PACKAGE=`cat CHECKSUMS.extra 2>/dev/null | grep "/$1" | awk '{print$3}' | grep "/" | sed s/.//`
                                        SWAPME=1
                                  fi
                                  if test $SWAPME -eq 0
                                  then
                                        PACKAGE=`cat CHECKSUMS 2>/dev/null | grep "/$1" | grep / | awk '{print$3}' | sed s/.//`
                                  fi
                                  if [ ! -z $RR ]; then
					TMPTRIGVAR=slackware
                                        SIZEPKGTMP=`cat CHECKSUMS 2>/dev/null | grep "/$1" | awk '{print$2}'`
                                        SIZEPKG=`echo $SIZEPKGTMP / 1024 | bc`
                                        MSG "--reinstall" "[ file:$RR ]"
                                        echo -n "### Copying $SHORTPKG ($SIZEPKG kB)... "
                                        SWAPME=0
                                        if [[ "$3" = "-p" || "$3" = "-ap" ]]; then
						copy_file "$RR" "$PACKAGE"
					  TMPTRIGVAR=patches
                                          SWAPME=1
                                        fi
                                        if [[ "$3" = "-e" || "$3" = "-ae" ]]; then
						copy_file "$RR" "$PACKAGE"
					  TMPTRIGVAR=extra
                                          SWAPME=1
                                        fi
                                        if test $SWAPME -eq 0
                                        then
						copy_file "$RR" "$PACKAGE"
					  TMPTRIGVAR=slackware
                                        fi
                                        if [ -f $1 ]; then
                                                FPKGSW=1
                                                FPKGTSIZE=`echo "$FPKGTSIZE + $SIZEPKG" | bc` 
                                                FPKGC=`echo "$FPKGC + 1" | bc`
                                                echo "DONE!"
                                                logme "--reinstall" "### Copying $SHORTPKG ($SIZEPKG kB)... DONE!"
                                                SWAPME=0
                                                if [[ "$3" = "-p" || "$3" = "-ap" ]]; then
                                                        checksum_patch $1
                                                        SWAPME=1
                                                fi
                                                if [[ "$3" = "-e" || "$3" = "-ae" ]]; then
                                                        checksum_extra $1
                                                        SWAPME=1
                                                fi
                                                if test $SWAPME -eq 0
                                                then
                                                        checksum_package $1
                                                fi
                                                DONE=0
						pgp_check_local "--reinstall" "$3" "$3" "$1"
						break
                                        else
                                                echo "FAILED!"
                                                logme "--reinstall" "### Copying $SHORTPKG ($SIZEPKG kB)... FAILED!"
                                        fi
                                  else
                                        SIZEPKGTMP=`cat CHECKSUMS 2>/dev/null | grep "/$1" | awk '{print$2}'`
                                        SIZEPKG=`echo $SIZEPKGTMP / 1024 | bc`
                                        MSG "--reinstall" "### Copying $SHORTPKG ($SIZEPKG kB)... FAILED!"
                                  fi
				done
                              else
                                        SWAPME=0
                                        SIZEPKGTMP=`cat CHECKSUMS 2>/dev/null | grep "/$1" | awk '{print$2}'`
                                        SIZEPKG=`echo $SIZEPKGTMP / 1024 | bc`
                                        if [[ "$3" = "-p" || "$3" = "-ap" ]]; then
                                                MSG "--reinstall" "Patch $SHORTPKG ($SIZEPKG kB) found in $CDIR!"
                                                res_local_pat $1
                                                SWAPME=1
                                        fi
                                        if [[ "$3" = "-e" || "$3" = "-ae" ]]; then
                                                MSG "--reinstall" "Extra Package $SHORTPKG ($SIZEPKG kB) found in $CDIR!"
                                                res_local_ext $1
                                                SWAPME=1
                                        fi
                                        if test $SWAPME -eq 0
                                        then
                                                MSG "--reinstall" "Package $SHORTPKG ($SIZEPKG kB) found in $CDIR!"
                                                res_local_pac $1
                                        fi
                              fi
                           }
                           if test $DONE -eq 1
                           then
                                   if [ -z "$2" ]; then
                                        get_pkg "$1.tgz" 1 "-a"
                                   else
                                        get_pkg "$1.tgz" 1 $2
                                   fi
                           fi
                           COUNTER=1
                           DONE=1
                        }

                        SWAPME=0
                        SHORTPKGTMP=`echo $2 | sed s/'.tgz'//`
                        FPKGSW=0
                        FPKGTSIZE=0
                        FPKGC=0
                        if [[ "$3" = "-p" || "$3" = "-ap" ]]; then
                          swap_to_patches
                          make_patches_list
                          CHECKPKG=`cat CHECKSUMS.md5.patches.tmp 2>/dev/null | grep "$2" | sort`
                          CHECK=`cat CHECKSUMS.md5.patches.tmp 2>/dev/null | grep "$2" | wc -l`
                          SWAPME=1
                        fi
                        if [[ "$3" = "-e" || "$3" = "-ae" ]]; then
                          swap_to_extra
                          make_extra_list
                          CHECKPKG=`cat CHECKSUMS.md5.extra.tmp 2>/dev/null | grep "$2" | sort`
                          CHECK=`cat CHECKSUMS.md5.extra.tmp 2>/dev/null | grep "$2" | wc -l`
                          SWAPME=1
                        fi
                        if test $SWAPME -eq 0
                        then
                          CHECKPKG=`cat CHECKSUMS.md5 2>/dev/null | grep "$2" | sed -e "s/.*\///g" | sort`
                          CHECK=`cat CHECKSUMS.md5 2>/dev/null | grep "$2" | wc -l`
                        fi
                        if test $CHECK -eq 0
                        then
                                SWAPME=0
                                if [[ "$3" = "-p" || "$3" = "-ap" ]]; then
                                        MSGERR "--reinstall [-p|-ap]" "No available Patches found matching Keyword: $2!"
                                        SWAPME=1
                                fi
                                if [[ "$3" = "-e" || "$3" = "-ae" ]]; then
                                        MSGERR "--reinstall [-e|-ae]" "No available Extra Packages found matching Keyword: $2!"
                                        SWAPME=1
                                fi
                                if test $SWAPME -eq 0
                                then
                                        MSGERR "--reinstall" "No available Packages found matching Keyword: $2!"
                                fi
				exit
                        fi
                        if test `ls -alL $PACKAGES_LOGDIR/$2* 2>/dev/null | wc -l` -eq 0; then
			  if test `echo "$2" | grep "/" | wc -l` -eq 0; then
                                SWAPME=0
                                if [[ "$3" = "-p" || "$3" = "-ap" ]]; then
                                        MSGERR "--reinstall [-p|-ap]" "No installed Patches found matching Keyword: $2!"
                                        SWAPME=1
                                fi
                                if [[ "$3" = "-e" || "$3" = "-ae" ]]; then
                                        MSGERR "--reinstall [-e|-ae]" "No installed Extra Packages found matching Keyword: $2!"
                                        SWAPME=1
                                fi
                                if test $SWAPME -eq 0
                                then
                                        MSGERR "--reinstall" "No installed Packages found matching Keyword: $2!"
                                fi
                                exit
			  fi
                        fi
                        if test $CHECK -gt 0
                        then
                                SWAPME=0
				TRIGVAR=""
                                if [[ "$3" = "-p" || "$3" = "-ap" ]]; then
                                        echo "Making a List of available Patches matching Keyword: $2..."
					TRIGVAR="Patches"
                                        SWAPME=1
                                fi
                                if [[ "$3" = "-e" || "$3" = "-ae" ]]; then
                                        echo "Making a List of available Extra Packages matching Keyword: $2..."
					TRIGVAR="Extra Packages"
                                        SWAPME=1
                                fi
                                if test $SWAPME -eq 0
                                then
                                        echo "Making a List of available Packages matching Keyword: $2..."
					TRIGVAR="Packages"
                                fi
                                SWITCH=0
                                if [[ "$3" = "-a" || "$3" = "-ap" || "$3" = "-ae" ]]; then
					XDL=0
					z=0
					xCOUNTER=0
					zCOUNTER=0
                                        for i in $CHECKPKG
                                        do
						xCOUNTER=`expr $xCOUNTER + 1`
					done
					for i in $CHECKPKG
					do
                                                FIX=`echo $i | sed s/'.tgz'//`
                                                SIZEPKGTMP=`cat $CDIR/CHECKSUMS 2>/dev/null | grep "/$i" | awk '{print$2}'`
                                                SIZEPKG=`echo "$SIZEPKGTMP / 1024" | bc`
						if [ -f $PACKAGES_LOGDIR/$FIX ]; then
							XDL=1
							echo "$FIX ($SIZEPKG kB)  "
                                                	zCOUNTER=`expr $zCOUNTER + 1`
							if [[ "$zCOUNTER" != "$xCOUNTER" ]]; then
                                                        	ls_break "$TRIGVAR"
                                                	fi
							touch $CDIR/$FIX.amp
						fi
                                        done
                                        echo
                                        if test $XDL -eq 0; then
                                                for i in `ls -alL $PACKAGES_LOGDIR/$2* | sed -e "s/.*\///g"`
                                                do
                                                        echo "Package '$i' not found in the List Files!"
                                                        echo "=> Re-Installing $i... FAILED!"
                                                done
                                        fi
                                        for i in $CHECKPKG
                                        do
                                                FIX=`echo $i | sed s/'.tgz'//`
                                                if [ ! -f $FIX.pmt ]; then
						   if [ -f $CDIR/$FIX.amp ]; then
                                                        if test `cat /etc/swaret.conf | grep -v "#" | grep "^ROOT=" | grep "file:" | wc -l` -ge 1
                                                        then
                                                                copy_pkg $FIX $3 $3
                                                        else
                                                                download_pkg $FIX $3
                                                        fi
						   fi
                                                fi
                                        done
                                        if [ ! -f $FIX.pmt ]; then
                                        if test $FPKGSW -eq 1
                                        then
                                         if test $FPKGC -ge 1
                                         then
                                          if test `cat /etc/swaret.conf | grep -v "#" | grep "^ROOT=" | grep "file:" | wc -l` -ge 1; then
                                            if test $FPKGC -eq 1
                                            then
                                                MSG "--reinstall" "Copied $FPKGC File with a Size of $FPKGTSIZE kB!"
                                            else
                                                MSG "--reinstall" "Copied $FPKGC Files with a Total Size of $FPKGTSIZE kB!"
                                            fi  
                                          else
                                            if test $FPKGC -eq 1
                                            then
                                                MSG "--reinstall" "Downloaded $FPKGC File with a Size of $FPKGTSIZE kB!"
                                            else
                                                MSG "--reinstall" "Downloaded $FPKGC Files with a Total Size of $FPKGTSIZE kB!"
                                            fi  
                                          fi
                                         fi
                                        fi
                                        fi
                                        for i in $CHECKPKG
                                        do
                                                FIX=`echo $i | sed s/'.tgz'//`
                                                if [ ! -f $FIX.pmt ]; then
						  if [ -f $CDIR/$FIX.amp ]; then
                                                        reinstall_pkg $FIX $3
						  fi
                                                fi
                                        done
                                        for i in $CHECKPKG
                                        do
                                                FIX=`echo $i | sed s/'.tgz'//`
                                                rm -f $FIX.pmt
						rm -f $FIX.amp
                                        done
                                        SWITCH=1
                                fi
                                if test $SWITCH -eq 0
                                then
                                        XDL=0
                                        z=0
                                        xCOUNTER=0
                                        zCOUNTER=0
                                        for i in $CHECKPKG
                                        do
                                                xCOUNTER=`expr $xCOUNTER + 1`
                                        done
                                        for i in $CHECKPKG
                                        do
                                                FIX=`echo $i | sed s/'.tgz'//`
                                                SIZEPKGTMP=`cat $CDIR/CHECKSUMS 2>/dev/null | grep "/$i" | awk '{print$2}'`
                                                SIZEPKG=`echo "$SIZEPKGTMP / 1024" | bc`
						if [ -f $PACKAGES_LOGDIR/$FIX ]; then
							XDL=1
							echo "$FIX ($SIZEPKG kB)  "
                                                	zCOUNTER=`expr $zCOUNTER + 1`
							if [[ "$zCOUNTER" != "$xCOUNTER" ]]; then
                                                        	ls_break "$TRIGVAR"
                                                	fi
							touch $CDIR/$FIX.amp
						fi
                                        done
                                        echo
					if test $XDL -eq 0; then
						for i in `ls -alL $PACKAGES_LOGDIR/$2* | sed -e "s/.*\///g"`
						do
							echo "Package '$i' not found in the List Files!"
							echo "=> Re-Installing $i... FAILED!"
						done
					fi
                                        for i in $CHECKPKG
                                        do
                                            SHORTPKG=`echo $i | sed s/'.tgz'//`
                                            if [ ! -f $SHORTPKG.pmt ]; then
					      if [ -f $CDIR/$SHORTPKG.amp ]; then
                                                echo -n "Re-Install $SHORTPKG? (y/n): [y]"
                                                read answer
                                                if [ -z "$answer" ]; then
                                                        answer="y"
                                                else
                                                        if [[ $answer != "y" ]]; then
                                                                answer="n"
                                                        fi
                                                fi
                                                logme "--reinstall" "Re-Install $SHORTPKG? (y/n): [$answer]"
                                                case $answer in 
                                                        "y")
                                                                echo $SHORTPKG >> PKGTOINSTALLLIST.list
                                                                ;;
                                                        "n")
                                                                ;;
                                                        *)
								invalid_charz
                                                                ;;
                                                esac
					      fi
                                            fi
                                        done
                                        if [ -f PKGTOINSTALLLIST.list ]; then
                                                PKGTOINSTALLLIST=`cat PKGTOINSTALLLIST.list 2>/dev/null`
                                                for i in $PKGTOINSTALLLIST
                                                do
                                                        FIX=`echo $i | sed s/'.tgz'//`
                                                        if [ ! -f $FIX.pmt ]; then
							  if [ -f $CDIR/$FIX.amp ]; then
                                                                if test `cat /etc/swaret.conf | grep -v "#" | grep "^ROOT=" | grep "file:" | wc -l` -ge 1
                                                                then
                                                                        copy_pkg $FIX $3 $3
                                                                else
                                                                        download_pkg $FIX $3
                                                                fi
							  fi
                                                        fi
                                                done
                                        if test $FPKGSW -eq 1
                                        then
                                         if test $FPKGC -ge 1
                                         then
                                          if test `cat /etc/swaret.conf | grep -v "#" | grep "^ROOT=" | grep "file:" | wc -l` -ge 1; then
                                            if test $FPKGC -eq 1
                                            then
                                                MSG "--reinstall" "Copied $FPKGC File with a Size of $FPKGTSIZE kB!"
                                            else
                                                MSG "--reinstall" "Copied $FPKGC Files with a Total Size of $FPKGTSIZE kB!"
                                            fi  
                                          else
                                            if test $FPKGC -eq 1
                                            then
                                                MSG "--reinstall" "Downloaded $FPKGC File with a Size of $FPKGTSIZE kB!"
                                            else
                                                MSG "--reinstall" "Downloaded $FPKGC Files with a Total Size of $FPKGTSIZE kB!"
                                            fi  
                                          fi
                                         fi
                                        fi
                                                for i in $PKGTOINSTALLLIST
                                                do
                                                        FIX=`echo $i | sed s/'.tgz'//`
                                                        if [ ! -f $FIX.pmt ]; then
							  if [ -f $CDIR/$FIX.amp ]; then
                                                                reinstall_pkg $FIX $3
							  fi
                                                        fi
                                                done
                                                for i in $PKGTOINSTALLLIST
                                                do      
                                                        FIX=`echo $i | sed s/'.tgz'//`
                                                        rm -f $FIX.pmt
							rm -f $FIX.amp
                                                done
                                        fi
                                fi
                        fi
                        if [ -z $5 ]; then
                                echo
                        fi
                        if [[ $VDEPENDENCY = 1 ]]; then
                                if test `cat $CDIR/TARFILES.tmp 2>/dev/null | wc -l` -gt 0; then
					echo
                                        if [[ "$DINTERACTIVE" = "1" ]]; then
                                                dependency_interactive_check
                                        else
                                                dependency_check
                                        fi
                                fi
                        fi
}

function_download()
{
			if [ -z $5 ]; then	
				echo
			fi
			URL

			copy_from_cache

			SWAPME=0
                        if [[ "$3" = "-p" || "$3" = "-ap" ]]; then
                                check_patch_files
				SWAPME=1
                        fi
                        if [[ "$3" = "-e" || "$3" = "-ae" ]]; then
                                check_extra_files
				SWAPME=1
                        fi
			if test $SWAPME -eq 0
			then
                                check_package_files
                        fi

                        if [ -z "$2" ]; then
			  if test `cat /etc/swaret.conf | grep -v "#" | grep "^ROOT=" | grep "file:" | wc -l` -ge 1; then
                                MSGERR "--download" "Please, provide a Keyword to Copy!"
			  else
				MSGERR "--download" "Please, provide a Keyword to Download!"	
			  fi
                        fi
                        export GO=0
                        echo "$2" | grep -q '^[[:alpha:]]\+' && export GO=1
                        if test $GO -eq 0
                        then
				invalid_charz
                        fi
			
			TRIGVAR=slackware
			SWAPME=0
			if [[ "$3" = "-p" || "$3" = "-ap" ]]; then
			  swap_to_patches
                          check_patch_files
			  make_patches_list
			  TRIGVAR=patches
			  PKGLIST=`cat CHECKSUMS.md5.patches.tmp 2>/dev/null | grep "$2" | sort`
			  COUNT=`cat CHECKSUMS.md5.patches.tmp 2>/dev/null | grep "$2" | wc -l`
			  SWAPME=1
			fi  
                        if [[ "$3" = "-e" || "$3" = "-ae" ]]; then
			  swap_to_extra
                          check_extra_files
			  make_extra_list
			  TRIGVAR=extra
                          PKGLIST=`cat CHECKSUMS.md5.extra.tmp 2>/dev/null | grep "$2" | sort`
                          COUNT=`cat CHECKSUMS.md5.extra.tmp 2>/dev/null | grep "$2" | wc -l`
                          SWAPME=1
                        fi
			if test $SWAPME -eq 0
			then
				PKGLIST=`cat CHECKSUMS.md5 2>/dev/null | grep "$2" | sed -e "s/.*\///g" | sort`
                        	COUNT=`cat CHECKSUMS.md5 2>/dev/null | grep "$2" | wc -l`
			fi
			if test $COUNT -eq 0
			then
			   SWAPME=0
			   if [[ "$3" = "-p" || "$3" = "-ap" ]]; then
                                MSGERR "--download [-p|-ap]" "No available Patches found matching Keyword: $2!"
				SWAPME=1
			   fi
			   if [[ "$3" = "-e" || "$3" = "-ae" ]]; then
				MSGERR "--download [-e|-ap]" "No available Extra Packages found matching Keyword: $2!"
				SWAPME=1
			   fi
			   if test $SWAPME -eq 0
			   then
				MSGERR "--download" "No available Packages found matching Keyword: $2!"
			   fi
                           exit
			fi
			if test $COUNT -ge 1
			then
				SWAPME=0
				TRIGVAR=""
				if [[ "$3" = "-p" || "$3" = "-ap" ]]; then
					echo "Making a List of available Patches matching Keyword: $2..."
					TRIGVAR="Patches"
					SWAPME=1
				fi
				if [[ "$3" = "-e" || "$3" = "-ae" ]]; then
					echo "Making a List of available Extra Packages matching Keyword: $2..."
					TRIGVAR="Extra Packages"
					SWAPME=1
				fi
				if test $SWAPME -eq 0
				then
					echo "Making a List of available Packages matching Keyword: $2..."
					TRIGVAR="Packages"
				fi
			fi
			if [[ "$3" = "-a" || "$3" = "-ap" || "$3" = "-ae" ]]; then
				answer="y"
			else
				answer="n"
			fi
			if test $COUNT -ge 1
			then 
				z=0
				xCOUNTER=0
				zCOUNTER=0
				for i in $PKGLIST
				do
					xCOUNTER=`expr $xCOUNTER + 1`
				done
                                for i in $PKGLIST
                                do
					FIX=`echo $i | sed s/'.tgz'//`
					SIZEPKGTMP=`cat $CDIR/CHECKSUMS 2>/dev/null | grep "/$i" | awk '{print$2}'`
					SIZEPKG=`echo "$SIZEPKGTMP / 1024" | bc`
					echo "$FIX ($SIZEPKG kB)  "
                                                zCOUNTER=`expr $zCOUNTER + 1`
						if [[ "$zCOUNTER" != "$xCOUNTER" ]]; then
                                                        ls_break "$TRIGVAR"
                                                fi
				done
				echo
			fi		
			FPKGSW=0
			FPKGTSIZE=0
			FPKGC=0
			case $answer in
				"y")
					DONE=1
					COUNTER=1
					for i in $PKGLIST
					do
                                                SHORTPKG=`echo $i | sed s/'.tgz'//`
						if [[ "$3" == "-ap" ]]; then
						  GETPKG=`cat CHECKSUMS.patches 2>/dev/null | grep "/$i" | awk '{print$3}' | grep "/" | sed s/.//`
						fi
                                                if [[ "$3" == "-ae" ]]; then
                                                  GETPKG=`cat CHECKSUMS.extra 2>/dev/null | grep "/$i" | awk '{print$3}' | grep "/" | sed s/.//`
                                                fi
						if [[ "$3" = "-a" ]]; then
						  GETPKG=`cat CHECKSUMS 2>/dev/null | grep "/$i" | awk '{print$3}' | grep "/" | sed s/.//`
						fi
						get_pkg()
						{
						     if [ -f $i ]; then
                                                          SIZEPKGTMP=`ls -alL $i 2>/dev/null | awk '{print$5}'`
                                                          SIZEPKG=`echo $SIZEPKGTMP / 1024 | bc`
							  if [[ "$2" = "-ap" ]]; then
							    MSG "--download [-ap]" "Patch $SHORTPKG ($SIZEPKG kB) found in $CDIR!"
							    check_for_broken_patches $i 1
							  fi
                                                          if [[ "$2" = "-ae" ]]; then
							    MSG "--download [-ae]" "Extra Package $SHORTPKG ($SIZEPKG kB) found in $CDIR!"
                                                            check_for_broken_extra $i 1
                                                          fi
                                                          if [[ "$2" = "-a" ]]; then
							    MSG "--download [-a]" "Package $SHORTPKG ($SIZEPKG kB) found in $CDIR!"
                                                            check_for_broken_packages $i 1
                                                          fi
						     else
						      if [ ! -f $i ]; then
						       PACKAGES_URL=`cat URL 2>/dev/null | awk '{ if(NR == '$1') print $1 }'`
						       SIZEPKGTMP=`cat CHECKSUMS 2>/dev/null | grep "/$i" | awk '{print$2}'`
						       SIZEPKG=`echo $SIZEPKGTMP / 1024 | bc`
						       if [ ! -z $PACKAGES_URL ]; then
							MSG "--download" "[ $PACKAGES_URL ]"
							echo $QS "### Fetching $SHORTPKG ($SIZEPKG kB)... "
							if test `echo $PACKAGES_URL | grep rsync | wc -l` -ge 1
							then
                                                		if [ ! -z $Q ]; then
									rsync_file "$PACKAGES_URL" "$GETPKG"
                                                        		count_size_rsync $i $2
                                                		else
									rsync_file_s "$PACKAGES_URL" "$GETPKG"
									touch_it "$i"
                                                        	fi
							else
                                                                if [ ! -z $Q ]; then
									wget_file "$PACKAGES_URL" "$GETPKG"
                                                                        count_size $i $2
                                                                else
									wget_file_s "$PACKAGES_URL" "$GETPKG"
									touch_it "$i"
                                                                fi
                                                	fi
							if [ -f $i.tmp ]; then
								FPKGSW=1
								FPKGTSIZE=`echo "$FPKGTSIZE + $SIZEPKG" | bc`
								FPKGC=`echo "$FPKGC + 1" | bc`
								if [ ! -z $Q ]; then
									echo " DONE!"
								fi
								logme "--download" "### Fetching $SHORTPKG ($SIZEPKG kB)... DONE!"
								rm -f $i.tmp
								SWAPME=0
								if [[ "$2" = "-ap" ]]; then
								  checksum_patch $i
								  SWAPME=1
								fi
								if [[ "$2" = "-ae" ]]; then
								  checksum_extra $i
								  SWAPME=1
								fi
								if test $SWAPME -eq 0
								then
								  checksum_package $i
								fi
								DONE=0
								pgp_check_remote "--download" "$3" "$3" "$i"
							else
								if [ ! -z $Q ]; then
									echo " FAILED!"
								fi
								logme "--download" "### Fetching $SHORTPKG ($SIZEPKG kB)... FAILED!"
								rm -f $i.tmp
								RECORDS=`cat URL 2>/dev/null | wc -l`
								COUNTER=`expr $COUNTER + 1`
								if test $COUNTER -ne `expr $RECORDS + 1`
								then
                                                                   get_pkg $COUNTER $2
								fi
								DONE=0
							fi
						       fi
						      fi
						     fi
						}
                        copy_pkg()
                        {
                              SHORTPKG=`echo $1 | sed s/'.tgz'//`
                              if [ ! -f $1 ]; then
				ROOTS=`cat /etc/swaret.conf | grep -v "#" | grep "^ROOT=" | grep "file:" | cut -f2 -d'=' | sed s/'file:'//`
			        for RR in $ROOTS
				do
                                  SWAPME=0
                                  if [[ "$3" = "-p" || "$3" = "-ap" ]]; then
                                        PACKAGE=`cat CHECKSUMS.patches 2>/dev/null | grep "/$1" | awk '{print$3}' | grep "/" | sed s/.//`
                                        SWAPME=1
                                  fi
                                  if [[ "$3" = "-e" || "$3" = "-ae" ]]; then
                                        PACKAGE=`cat CHECKSUMS.extra 2>/dev/null | grep "/$1" | awk '{print$3}' | grep "/" | sed s/.//`
                                        SWAPME=1
                                  fi
                                  if test $SWAPME -eq 0
                                  then
                                        PACKAGE=`cat CHECKSUMS 2>/dev/null | grep "/$1" | grep / | awk '{print$3}' | sed s/.//`
                                  fi
                                  if [ ! -z $RR ]; then
                                        TMPTRIGVAR=slackware
                                        SIZEPKGTMP=`cat CHECKSUMS 2>/dev/null | grep "/$1" | awk '{print$2}'`
                                        SIZEPKG=`echo $SIZEPKGTMP / 1024 | bc`
                                        MSG "--download" "[ file:$RR ]"
                                        echo -n "### Copying $SHORTPKG ($SIZEPKG kB)... "
                                        SWAPME=0
                                        if [[ "$3" = "-p" || "$3" = "-ap" ]]; then
						copy_file "$RR" "$PACKAGE"
                                          TMPTRIGVAR=patches
                                          SWAPME=1
                                        fi
                                        if [[ "$3" = "-e" || "$3" = "-ae" ]]; then
						copy_file "$RR" "$PACKAGE"
                                          TMPTRIGVAR=extra
                                          SWAPME=1
                                        fi
                                        if test $SWAPME -eq 0
                                        then
						copy_file "$RR" "$PACKAGE"
                                          TMPTRIGVAR=slackware
                                        fi
                                        if [ -f $1 ]; then
                                                FPKGSW=1
                                                FPKGTSIZE=`echo "$FPKGTSIZE + $SIZEPKG" | bc` 
                                                FPKGC=`echo "$FPKGC + 1" | bc`
                                                echo "DONE!"
                                                logme "--download" "### Copying $SHORTPKG ($SIZEPKG kB)... DONE!"
                                                SWAPME=0
                                                if [[ "$3" = "-p" || "$3" = "-ap" ]]; then
                                                        checksum_patch $1
                                                        SWAPME=1
                                                fi
                                                if [[ "$3" = "-e" || "$3" = "-ae" ]]; then
                                                        checksum_extra $1
                                                        SWAPME=1
                                                fi
                                                if test $SWAPME -eq 0
                                                then
                                                        checksum_package $1
                                                fi
                                                DONE=0
                                                pgp_check_local "--install" "$3" "$3" "$1"
						break
                                        else
                                                echo "FAILED!"
                                                logme "--download" "### Copying $SHORTPKG ($SIZEPKG kB)... FAILED!"
                                        fi
                                  else
                                        SIZEPKGTMP=`cat CHECKSUMS 2>/dev/null | grep "/$1" | awk '{print$2}'`
                                        SIZEPKG=`echo $SIZEPKGTMP / 1024 | bc`
                                        MSG "--download" "### Copying $SHORTPKG ($SIZEPKG kB)... FAILED!"
                                  fi
			        done
                              else
                                        SWAPME=0
                                        SIZEPKGTMP=`cat CHECKSUMS 2>/dev/null | grep "/$1" | awk '{print$2}'`
                                        SIZEPKG=`echo $SIZEPKGTMP / 1024 | bc`
                                        if [[ "$3" = "-p" || "$3" = "-ap" ]]; then
                                                MSG "--download" "Patch $SHORTPKG ($SIZEPKG kB) found in $CDIR!"
                                                res_local_pat $1
                                                SWAPME=1
                                        fi
                                        if [[ "$3" = "-e" || "$3" = "-ae" ]]; then
                                                MSG "--download" "Extra Package $SHORTPKG ($SIZEPKG kB) found in $CDIR!"
                                                res_local_ext $1
                                                SWAPME=1
                                        fi
                                        if test $SWAPME -eq 0
                                        then
                                                MSG "--download" "Package $SHORTPKG ($SIZEPKG kB) found in $CDIR!"
                                                res_local_pac $1
                                        fi
                              fi
                        }
						if test $DONE -eq 1	    
						then
						  if test `cat /etc/swaret.conf | grep -v "#" | grep "^ROOT=" | grep "file:" | wc -l` -ge 1; then
						    copy_pkg $i "$3" "$3"
						  else
							if [ -z "$3" ]; then
                                                                get_pkg 1 "-a"
							else
								get_pkg 1 $3
							fi
						  fi
						fi
						COUNTER=1
						DONE=1
					done
					;;
				"n")
					QSWAP=0
                                        for i in $PKGLIST
                                        do
						SWAPME=0
						SHORTPKG=`echo $i | sed s/'.tgz'//`
						if [[ "$3" == "-p" ]]; then
                                                  GETPKG=`cat CHECKSUMS.patches | awk '{print$3}' | grep "/" | sed s/.// | grep "/$i"`
						  SWAPME=1
                                                fi
                                                if [[ "$3" == "-e" ]]; then
                                                  GETPKG=`cat CHECKSUMS.extra | awk '{print$3}' | grep "/" | sed s/.// | grep "/$i"`
                                                  SWAPME=1
                                                fi
						if test $SWAPME -eq 0
					        then
                                                  GETPKG=`cat CHECKSUMS 2>/dev/null | grep "/$i" | awk '{print$3}' | sed s/.//`
						fi
					  if [ ! -f $CDIR/$i ]; then
						if [ ! -f $SHORTPKG.tmp ]; then
						   if [ ! -f $CDIR/$i ]; then
							if test `cat /etc/swaret.conf | grep -v "#" | grep "^ROOT=" | grep "file:" | wc -l` -ge 1; then
								echo -n "Copy $SHORTPKG? (y/n): [y]"
							else
								echo -n "Download $SHORTPKG? (y/n): [y]"
							fi
							read answer
							if [ -z "$answer" ]; then
								answer="y"
							else
								if [[ $answer != "y" ]]; then
									answer="n"
								fi
							fi
							if test `cat /etc/swaret.conf | grep -v "#" | grep "^ROOT=" | grep "file:" | wc -l` -ge 1; then
								logme "--download" "Copy $SHORTPKG? (y/n): [$answer]"
							else
								logme "--download" "Download $SHORTPKG? (y/n): [$answer]"
							fi
							case $answer in 
								"y")
									QSWAP=1
									echo $i >> DOWNLOADPKGSLIST.list 2>/dev/null
									;;
								"n")
									;;
								*)
									invalid_charz
									;;
							esac
						   fi
						fi
					  else
						SHORTPKG=`echo $i | sed s/'.tgz'//`
							SIZEPKGTMP=`ls -alL $CDIR/$i 2>/dev/null | awk '{print$5}'`
							SIZEPKG=`echo $SIZEPKGTMP / 1024 | bc`
							SWAPME=0
							if [[ "$3" = "-p" ]]; then
								MSG "--download [-p]" "Patch $SHORTPKG ($SIZEPKG kB) found in $CDIR!"
									SWAPME=1
									fi
									if [[ "$3" = "-e" ]]; then
										MSG "--download [-e]" "Extra Package $SHORTPKG ($SIZEPKG kB) found in $CDIR!"
											SWAPME=1
											fi
											if test $SWAPME -eq 0; then
												MSG "--download" "Package $SHORTPKG ($SIZEPKG kB) found in $CDIR!"
													fi
													fi
													done
													if test $QSWAP -eq 1; then
														echo
															fi
															if [ -f DOWNLOADPKGSLIST.list ]; then
																PKGSLIST=`cat DOWNLOADPKGSLIST.list 2>/dev/null`
																	DONE=1
																	COUNTER=1
																	SWAPME=0
																	for Z in $PKGSLIST
																		do
																			SHORTPKG=`echo $Z | sed s/'.tgz'//`
																				if [[ "$3" == "-p" ]]; then
																					GETPKG=`cat CHECKSUMS.patches 2>/dev/null | awk '{print$3}' | grep "/" | sed s/.// | grep "/$Z"`
							  SWAPME=1
							fi
							if [[ "$3" == "-e" ]]; then
						
                               				  GETPKG=`cat CHECKSUMS.extra 2>/dev/null | awk '{print$3}' | grep "/" | sed s/.// | grep "/$Z"`
                                                          SWAPME=1
                                                        fi
							if test $SWAPME -eq 0
							then
								GETPKG=`cat CHECKSUMS 2>/dev/null | grep "/$Z" | awk '{print$3}' | sed s/.//`
							fi
                        copy_pkg()
                        {
                              SHORTPKG=`echo $1 | sed s/'.tgz'//`
                              if [ ! -f $1 ]; then
				ROOTS=`cat /etc/swaret.conf | grep -v "#" | grep "^ROOT=" | grep "file:" | cut -f2 -d'=' | sed s/'file:'//`
				for RR in $ROOTS
				do
                                  SWAPME=0
                                  if [[ "$3" = "-p" || "$3" = "-ap" ]]; then
                                        PACKAGE=`cat CHECKSUMS.patches 2>/dev/null | grep "/$1" | awk '{print$3}' | grep "/" | sed s/.//`
                                        SWAPME=1
                                  fi
                                  if [[ "$3" = "-e" || "$3" = "-ae" ]]; then
                                        PACKAGE=`cat CHECKSUMS.extra 2>/dev/null | grep "/$1" | awk '{print$3}' | grep "/" | sed s/.//`
                                        SWAPME=1
                                  fi
                                  if test $SWAPME -eq 0
                                  then
                                        PACKAGE=`cat CHECKSUMS 2>/dev/null | grep "/$1" | grep / | awk '{print$3}' | sed s/.//`
                                  fi
                                  if [ ! -z $RR ]; then
                                        TMPTRIGVAR=slackware
                                        SIZEPKGTMP=`cat CHECKSUMS 2>/dev/null | grep "/$1" | awk '{print$2}'`
                                        SIZEPKG=`echo $SIZEPKGTMP / 1024 | bc`
                                        MSG "--download" "[ file:$RR ]"
                                        echo -n "### Copying $SHORTPKG ($SIZEPKG kB)... "
                                        SWAPME=0
                                        if [[ "$3" = "-p" || "$3" = "-ap" ]]; then
						copy_file "$RR" "$PACKAGE"
                                          TMPTRIGVAR=patches
                                          SWAPME=1
                                        fi
                                        if [[ "$3" = "-e" || "$3" = "-ae" ]]; then
						copy_file "$RR" "$PACKAGE"
                                          TMPTRIGVAR=extra
                                          SWAPME=1
                                        fi
                                        if test $SWAPME -eq 0
                                        then
						copy_file "$RR" "$PACKAGE"
                                          TMPTRIGVAR=slackware
                                        fi
                                        if [ -f $1 ]; then
                                                FPKGSW=1
                                                FPKGTSIZE=`echo "$FPKGTSIZE + $SIZEPKG" | bc` 
                                                FPKGC=`echo "$FPKGC + 1" | bc`
                                                echo "DONE!"
                                                logme "--download" "### Copying $SHORTPKG ($SIZEPKG kB)... DONE!"
                                                SWAPME=0
                                                if [[ "$3" = "-p" || "$3" = "-ap" ]]; then
                                                        checksum_patch $1
                                                        SWAPME=1
                                                fi
                                                if [[ "$3" = "-e" || "$3" = "-ae" ]]; then
                                                        checksum_extra $1
                                                        SWAPME=1
                                                fi
                                                if test $SWAPME -eq 0
                                                then
                                                        checksum_package $1
                                                fi
                                                DONE=0
                                                pgp_check_local "--install" "$3" "$3" "$1"
						break
                                        else
                                                echo "FAILED!"
                                                logme "--download" "### Copying $SHORTPKG ($SIZEPKG kB)... FAILED!"
                                        fi
                                  else
                                        SIZEPKGTMP=`cat CHECKSUMS 2>/dev/null | grep "/$1" | awk '{print$2}'`
                                        SIZEPKG=`echo $SIZEPKGTMP / 1024 | bc`
                                        MSG "--download" "### Copying $SHORTPKG ($SIZEPKG kB)... FAILED!"
                                  fi
				done
                              else
                                        SWAPME=0
                                        SIZEPKGTMP=`cat CHECKSUMS 2>/dev/null | grep "/$1" | awk '{print$2}'`
                                        SIZEPKG=`echo $SIZEPKGTMP / 1024 | bc`
                                        if [[ "$3" = "-p" || "$3" = "-ap" ]]; then
                                                MSG "--download" "Patch $SHORTPKG ($SIZEPKG kB) found in $CDIR!"
                                                res_local_pat $1
                                                SWAPME=1
                                        fi
                                        if [[ "$3" = "-e" || "$3" = "-ae" ]]; then
                                                MSG "--download" "Extra Package $SHORTPKG ($SIZEPKG kB) found in $CDIR!"
                                                res_local_ext $1
                                                SWAPME=1
                                        fi
                                        if test $SWAPME -eq 0
                                        then
                                                MSG "--download" "Package $SHORTPKG ($SIZEPKG kB) found in $CDIR!"
                                                res_local_pac $1
                                        fi
                              fi
                        }
							get_pkg()
							{
								if [ -f $Z ]; then
                                                        		SIZEPKGTMP=`ls -alL $Z 2>/dev/null | awk '{print$5}'`
                                                        		SIZEPKG=`echo $SIZEPKGTMP / 1024 | bc`
                                                        		SWAPME=0
                                                        		if [[ "$2" = "-p" ]]; then
										MSG "--download [-p]" "Patch $SHORTPKG ($SIZEPKG kB) found in $CDIR!"
                                                            			check_for_broken_patches $Z 1
                                                            			SWAPME=1
                                                        		fi
                                                        		if [[ "$2" = "-e" ]]; then
										MSG "--download [-e]" "Extra Package $SHORTPKG ($SIZEPKG kB) found in $CDIR!"
                                                            			check_for_broken_extra $Z 1
                                                            			SWAPME=1
                                                        		fi
                                                        		if test $SWAPME -eq 0
									then
										MSG "--download" "Package $SHORTPKG ($SIZEPKG kB) found in $CDIR!"
                                                            			check_for_broken_packages $Z 1
                                                        		fi
                                        	        	else
                                                        	    PACKAGES_URL=`cat URL 2>/dev/null | awk '{ if(NR == '$1') print $1 }'`
                                                       		    SIZEPKGTMP=`cat CHECKSUMS 2>/dev/null | grep "/$Z" | awk '{print$2}'`
								    SIZEPKG=`echo $SIZEPKGTMP / 1024 | bc`
								    if [ ! -z $PACKAGES_URL ]; then
                                                        		MSG "--download" "[ $PACKAGES_URL ]"
	                                                      		echo $QS "### Fetching $SHORTPKG ($SIZEPKG kB)... "
        	                                                	if test `echo $PACKAGES_URL | grep rsync | wc -l` -ge 1
                	                                        	then
                                                                                    if [ ! -z $Q ]; then
											    rsync_file "$PACKAGES_URL" "$GETPKG"
                                                                                            count_size_rsync $Z $2
                                                                                    else
											    rsync_file_s "$PACKAGES_URL" "$GETPKG"
											    touch_it "$Z"
                                                                                    fi
                                                                        else
                                                                                    if [ ! -z $Q ]; then
											    wget_file "$PACKAGES_URL" "$GETPKG"
                                                                                            count_size $Z $2
                                                                                    else
											    wget_file_s "$PACKAGES_URL" "$GETPKG"
											    touch_it "$Z"
                                                                                    fi
                                                        		fi
                                                       			if [ -f $Z.tmp ]; then
                                                                FPKGSW=1
                                                                FPKGTSIZE=`echo "$FPKGTSIZE + $SIZEPKG" | bc`
                                                                FPKGC=`echo "$FPKGC + 1" | bc`
                                                                if [ ! -z $Q ]; then
                                                                        echo " DONE!"
                                                                fi
                                                                logme "--download" "### Fetching $SHORTPKG ($SIZEPKG kB)... DONE!"
                                                                rm -f $Z.tmp 
                                                                SWAPME=0
                                                                if [[ "$2" = "-ap" ]]; then
                                                                  checksum_patch $Z
                                                                  SWAPME=1
                                                                fi      
                                                                if [[ "$2" = "-ae" ]]; then
                                                                  checksum_extra $Z
                                                                  SWAPME=1
                                                                fi              
                                                                if test $SWAPME -eq 0   
                                                                then            
                                                                  checksum_package $Z
                                                                fi              
                                                                DONE=0  
                                                                pgp_check_remote "--download" "$3" "$3" "$Z"
                                                       			else
										if [ ! -z $Q ]; then
											echo " FAILED!"
										fi
										logme "--download" "### Fetching $SHORTPKG ($SIZEPKG kB)... FAILED!"
                                                               			rm -f $Z.tmp
										RECORDS=`cat URL 2>/dev/null | wc -l`
										COUNTER=`expr $COUNTER + 1`
										if test $COUNTER -ne `expr $RECORDS + 1`
										then
											get_pkg $COUNTER $2
										fi
										DONE=0
                                                       			fi
								    fi
								fi
							}
							if test $DONE -eq 1
							then
							  if test `cat /etc/swaret.conf | grep -v "#" | grep "^ROOT=" | grep "file:" | wc -l` -ge 1; then
							    copy_pkg "$Z" "$3" "$3"
							  else
								if [ -z "$3" ]; then
									get_pkg 1 "-a"
								else
									get_pkg 1 $3
								fi
							  fi
							fi
							DONE=1
							COUNTER=1
                                        	done
					fi
					;;
			esac
                        if test $FPKGSW -eq 1
                        then
                                if test $FPKGC -ge 1
                                then
				  if test `cat /etc/swaret.conf | grep -v "#" | grep "^ROOT=" | grep "file:" | wc -l` -ge 1; then
                                        if test $FPKGC -eq 1
                                        then
                                                MSG "--download" "Copied $FPKGC File with a Size of $FPKGTSIZE kB!"
                                        else
                                                MSG "--download" "Copied $FPKGC Files with a Total Size of $FPKGTSIZE kB!"
                                        fi
				  else
                                        if test $FPKGC -eq 1
                                        then
                                                MSG "--download" "Downloaded $FPKGC File with a Size of $FPKGTSIZE kB!"
                                        else
                                                MSG "--download" "Downloaded $FPKGC Files with a Total Size of $FPKGTSIZE kB!"
                                        fi
				  fi
                                fi
                        fi
                        if [[ "$INFORMATION" == "1" ]]; then
                                echo
                                echo "INFORMATION: Downloads are saved in $CDIR!"
                                if [ ! -z $5 ]; then
                                        echo
                                fi
                        fi
			if [ -z $5 ]; then
				echo
			fi
}

function_resume()
{
			if [ -z $5 ]; then
				echo
			fi
                        URL

			copy_from_cache

			FPKGSW=0
			FPKGTSIZE=0
			FPKGC=0

			if [[ "$2" = "-p" ]]; then
			  swap_to_patches
                          COUNT=0
                          SWITCH=0
                          SWAPME=0
                          COUNT=`ls $CDIR/*.tgz 2>/dev/null | wc -l | awk '{print$1}'`
                          if [ ! -f $CDIR/CHECKSUMS.patches ]; then
                                COUNT=-1
                          fi
                          echo -n "<Please wait...>"
                          if test $COUNT -ge 1
                          then
                                for i in *.tgz
                                do
					if test `cat $CDIR/CHECKSUMS.patches | grep "/$i" | wc -l` -ge 1
					then
						if test `cat $CDIR/CHECKSUMS.md5.patches | grep "/$i" | wc -l` -ge 1
						then
							if test `cat /etc/swaret.conf | grep -v "#" | grep "^ROOT=" | grep "file:" | wc -l` -ge 1; then
								res_local_pat $i "" 1
							else
                                        			check_for_broken_patches $i 1 1
							fi
						fi
					fi
                                done
                          else
				printf "\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b"
                                echo -n "                "
				printf "\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b"
				MSGERR "--resume [-p]" "No Patches found to Resume!"
                          fi
                          if [ -z "$AZERTYCHK" ]; then
				printf "\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b"
                                echo -n "                "
				printf "\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b"
				MSGERR "--resume [-p]" "No broken Patches found to Resume!"
                          fi
                                        if test $FPKGSW -eq 1
                                        then
                                         if test $FPKGC -ge 1
                                         then
                                          if test `cat /etc/swaret.conf | grep -v "#" | grep "^ROOT=" | grep "file:" | wc -l` -ge 1; then                   
                                            if test $FPKGC -eq 1
                                            then
                                                MSG "--resume [-p]" "Copied $FPKGC File with a Size of $FPKGTSIZE kB!"
                                            else
                                                MSG "--resume [-p]" "Copied $FPKGC Files with a Total Size of $FPKGTSIZE kB!"
                                            fi
                                          else
                                            if test $FPKGC -eq 1
                                            then 
                                                MSG "--resume [-p]" "Downloaded $FPKGC File with a Size of $FPKGTSIZE kB!"
                                            else
                                                MSG "--resume [-p]" "Downloaded $FPKGC Files with a Total Size of $FPKGTSIZE kB!"
                                            fi
                                          fi    
                                         fi     
                                        fi          
				echo
			  exit
			fi
                        if [[ "$2" = "-e" ]]; then
			  swap_to_extra
                          COUNT=0
                          SWITCH=0
                          SWAPME=0
                          COUNT=`ls $CDIR/*.tgz 2>/dev/null | wc -l | awk '{print$1}'`
			  if [ ! -f $CDIR/CHECKSUMS.extra ]; then
				COUNT=-1
			  fi
                          echo -n "<Please wait...>"
                          if test $COUNT -ge 1
                          then
                                for i in *.tgz
                                do
					if test `cat $CDIR/CHECKSUMS.extra | grep "/$i" | wc -l` -ge 1
					then
						if test `cat $CDIR/CHECKSUMS.md5.extra | grep "/$i" | wc -l` -ge 1
						then
							if test `cat /etc/swaret.conf | grep -v "#" | grep "^ROOT=" | grep "file:" | wc -l` -ge 1; then
								res_local_extra $i "" 1
                                        		else
								check_for_broken_extra $i 1 1
							fi
						fi
					fi
                                done
                          else
				printf "\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b"
                                echo -n "                "
				printf "\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b"
				MSGERR "--resume [-e]" "No Extra Packages found to Resume!"
                          fi
                          if [ -z "$AZERTYCHK" ]; then
				printf "\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b"
                                echo -n "                "
				printf "\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b"
				MSGERR "--resume [-e]" "No broken Extra Packages found to Resume!"
                          fi
                                        if test $FPKGSW -eq 1
                                        then
                                         if test $FPKGC -ge 1
                                         then
                                          if test `cat /etc/swaret.conf | grep -v "#" | grep "^ROOT=" | grep "file:" | wc -l` -ge 1; then                   
                                            if test $FPKGC -eq 1
                                            then
                                                MSG "--resume [-e]" "Copied $FPKGC File with a Size of $FPKGTSIZE kB!"
                                            else
                                                MSG "--resume [-e]" "Copied $FPKGC Files with a Total Size of $FPKGTSIZE kB!"
                                            fi
                                          else
                                            if test $FPKGC -eq 1
                                            then 
                                                MSG "--resume [-e]" "Downloaded $FPKGC File with a Size of $FPKGTSIZE kB!"
                                            else
                                                MSG "--resume [-e]" "Downloaded $FPKGC Files with a Total Size of $FPKGTSIZE kB!"
                                            fi
                                          fi    
                                         fi     
                                        fi          
				echo
                          exit
                        fi
                        if [[ "$2" = "-s" ]]; then
                          swap_to_sources
                          COUNT=0
                          SWITCH=0
                          SWAPME=0
                          COUNT=`ls $CDIR/*.*z* 2>/dev/null | wc -l | awk '{print$1}'`
                          if [ ! -f $CDIR/CHECKSUMS.sources ]; then
                                COUNT=-1
                          fi
                          echo -n "<Please wait...>"
                          if test $COUNT -ge 1
                          then
                                for i in *.*z*
                                do
                                        if test `cat $CDIR/CHECKSUMS.sources | grep "/$i" | wc -l` -ge 1
                                        then
                                                if test `cat $CDIR/CHECKSUMS.md5.sources | grep "/$i" | wc -l` -ge 1
                                                then
							GETPKG=`cat CHECKSUMS.sources 2>/dev/null | awk '{print$3}' | grep "/" | sed s/'.\/'// | grep "/$i"`
                                                        if test `cat /etc/swaret.conf | grep -v "#" | grep "^ROOT=" | grep "file:" | wc -l` -ge 1; then
                                                                res_local_sources $i "$GETPKG" 1
                                                        else
                                                                check_for_broken_sources $i 1 1 "$GETPKG"
                                                        fi
                                                fi
                                        fi
                                done
                          else
                                printf "\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b"
                                echo -n "                "
                                printf "\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b"
                                MSGERR "--resume [-s]" "No Sources found to Resume!"
                          fi
                          if [ -z "$AZERTYCHK" ]; then
                                printf "\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b"
                                echo -n "                "
                                printf "\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b"
                                MSGERR "--resume [-s]" "No broken Sources found to Resume!"
                          fi
					FPKGTSIZE=`echo "$FPKGTSIZE / 1024" | bc`
                                        if test $FPKGSW -eq 1
                                        then
                                         if test $FPKGC -ge 1
                                         then
                                          if test `cat /etc/swaret.conf | grep -v "#" | grep "^ROOT=" | grep "file:" | wc -l` -ge 1; then                   
                                            if test $FPKGC -eq 1
                                            then
                                                MSG "--resume [-s]" "Copied $FPKGC File with a Size of $FPKGTSIZE kB!"
                                            else
                                                MSG "--resume [-s]" "Copied $FPKGC Files with a Total Size of $FPKGTSIZE kB!"
                                            fi
                                          else
                                            if test $FPKGC -eq 1
                                            then
                                                MSG "--resume [-s]" "Downloaded $FPKGC File with a Size of $FPKGTSIZE kB!"
                                            else
                                                MSG "--resume [-s]" "Downloaded $FPKGC Files with a Total Size of $FPKGTSIZE kB!"
                                            fi
                                          fi    
                                         fi     
                                        fi          
				echo
                          exit
                        fi
                        COUNT=0
                        SWITCH=0
                        SWAPME=0
                        COUNT=`ls $CDIR/*.tgz 2>/dev/null | wc -l | awk '{print$1}'`
                        echo -n "<Please wait...>"
                        if [ ! -f $CDIR/CHECKSUMS ]; then
                              COUNT=-1
                        fi
                        if test $COUNT -ge 1
                        then
                                for i in *.tgz
                                do
					if test `cat $CDIR/CHECKSUMS | grep "/$i" | wc -l` -ge 1
					then
						if test `cat $CDIR/CHECKSUMS.md5 | grep "/$i" | wc -l` -ge 1
                                        	then
							if test `cat /etc/swaret.conf | grep -v "#" | grep "^ROOT=" | grep "file:" | wc -l` -ge 1; then
								res_local_pac $i "" 1
							else
								check_for_broken_packages $i 1 1
							fi
						fi
					fi
                                done
                        else
				printf "\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b"
                                echo -n "                "
				printf "\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b"
				MSGERR "--resume" "No Packages found to Resume!"
                        fi
                        if [ -z "$AZERTYCHK" ]; then
				printf "\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b"
                                echo -n "                "
				printf "\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b"
				MSGERR "--resume" "No broken Packages found to Resume!"
                        fi
                                        if test $FPKGSW -eq 1
                                        then
                                         if test $FPKGC -ge 1
                                         then
                                          if test `cat /etc/swaret.conf | grep -v "#" | grep "^ROOT=" | grep "file:" | wc -l` -ge 1; then                   
                                            if test $FPKGC -eq 1
                                            then
                                                MSG "--resume" "Copied $FPKGC File with a Size of $FPKGTSIZE kB!"
                                            else
                                                MSG "--resume" "Copied $FPKGC Files with a Total Size of $FPKGTSIZE kB!"
                                            fi
                                          else
                                            if test $FPKGC -eq 1
                                            then
                                                MSG "--resume" "Downloaded $FPKGC File with a Size of $FPKGTSIZE kB!"
                                            else
                                                MSG "--resume" "Downloaded $FPKGC Files with a Total Size of $FPKGTSIZE kB!"
                                            fi
                                          fi    
                                         fi     
                                        fi          
				echo
				exit
}

invalid_charz()
{
                                        MSG "--upgrade" "You are using invalid characters!"
                                        MSGERR "--upgrade" "Please, restart swaret $VERSION!"
}

youneedshort()
{
        MSG "GLOBAL" "You need '$1' in order to use swaret $SVERSION!"
        MSGERR "GLOBAL" "'$1' can be found in the Slackware Packages Root slackware/$2/"
}

youneedlong()
{
        MSG "GLOBAL" "You need '$1' in order to use swaret $SVERSION!"
        MSG "GLOBAL" "'$1' has been merged in the Package '$2'"
        MSGERR "GLOBAL" "'$2' can be found in the Slackware Packages Root slackware/$3/"
}

if [[ "$1" != "--config" ]] && [[ "$1" != "--log" ]] && [[ "$1" != "--faq" ]] && [[ "$1" != "--help" ]] && [[ "$1" != "--morehelp" ]] && [[ "$1" != "--manual" ]]; then
        catch_signal()
       {
                trap "pgrep -P$$ 2>/dev/null | xargs kill -9 >/dev/null 2>/dev/null ; pgrep -P$$ 2>/dev/null | xargs kill -9 >/dev/null 2>/dev/null ; pgrep -P$$ 2>/dev/null | xargs kill -9  >/dev/null 2>/dev/null ; clear ; logme 'catch_signal()' '!!! swaret was interrupted !!!' ; printf 'swaret $SVERSION\n\n!!! swaret was interrupted !!!\n' ; exit" INT
        }
        catch_signal
fi

check_for_settings
check_for_version
if [[ "$1" != "--clean" ]] && [[ "$1" != "--clear" ]] && [[ "$1" != "--pgp" ]] && [[ "$1" != "--log" ]]; then
	check_for_network
fi
cleanup_quick

if test `ls /etc/slackware* 2>/dev/null | wc -l` -eq 0
then
	HEADER
        MSGERR "GLOBAL" "You need Slackware Linux in order to use swaret!"
fi

if [ ! "`id -u`" = "0" ]; then
	HEADER
        MSGERR "GLOBAL" "You must be root in order to use swaret $SVERSION!"
fi

if test `ls $PACKAGES_LOGDIR/*-* 2>/dev/null | wc -l` -eq 0
then
	HEADER
        MSG "GLOBAL" "You're NOT using Slackware Linux 8.1 or Higher or Current!"
        MSGERR "GLOBAL" "See FAQ for more Information!"
fi

if test `which bash 2>/dev/null | wc -l` -eq 0;
then
	HEADER
	youneedshort "bash" "a"
fi

if test `which awk 2>/dev/null | wc -l` -eq 0;
then
	HEADER
	youneedshort "gawk" "a"
fi

if test `which sed 2>/dev/null | wc -l` -eq 0;
then
	HEADER
	youneedshort "sed" "a"
fi

if test `which grep 2>/dev/null | wc -l` -eq 0;
then
	HEADER
	youneedshort "grep" "a"
fi

if test `which pgrep 2>/dev/null | wc -l` -eq 0;
then
	HEADER
	youneedlong "pgrep" "procps" "a"
fi

if test `which cut 2>/dev/null | wc -l` -eq 0;
then
	HEADER
	youneedlong "cut" "textutils" "a"
fi

if test `which cat 2>/dev/null | wc -l` -eq 0;
then
	HEADER
	youneedlong "cat" "textutils" "a"
fi

if test `which sort 2>/dev/null | wc -l` -eq 0;
then
	HEADER
	youneedlong "sort" "textutils" "a"
fi

if test `which md5sum 2>/dev/null | wc -l` -eq 0;
then
	HEADER
	youneedlong "md5sum" "textutils" "a"
fi

if test `which bc 2>/dev/null | wc -l` -eq 0;
then
	HEADER
	youneedshort "bc" "ap"
fi

if test `which ldd 2>/dev/null | wc -l` -eq 0;
then
	HEADER
	youneedlong "ldd" "glibc" "l"
fi

if [ -z $5 ]; then
        echo "$SWARET"
fi
logme "GLOBAL" "COMMAND: swaret $1 $2 $3 $4 $5 $6 $7"

case $1 in
	"--update")
			echo

			clean_cache
			URL	
			if test `cat /etc/swaret.conf | grep -v "#" | grep "^ROOT=" | grep "file:" | wc -l` -ge 1; then
				update_from_local_lists
			else
				update_lists 1
			fi

			if [[ "$VPACKAGES" != "1" ]]; then
				if [[ "$VPATCHES" != "1" ]]; then
					if [[ "$VEXTRA" != "1" ]]; then
						MSG "--update" "No List Files to retrieve!"
						MSGERR "--update" "Edit /etc/swaret.conf and set PACKAGES and/or PATCHES and/or EXTRA to 1!"
					fi
				fi
			fi
			echo
                        if [[ "$LOG" == "1" ]]; then
                                check_log_settings
                        fi
			;;
	"--upgrade")
			function_upgrade "" "$2" "$3" "$4" "$5"
			;;
	"--up-all")
			echo

                        URL
                        copy_from_cache

                        if [ -z $2 ]; then
                                swaret --upgrade "" "" "" 1
                                echo
                                echo
                                swaret --upgrade -p "" "" 1
                                echo
                                echo
                                swaret --upgrade -e "" "" 1
                                echo
                                exit
                        fi
                        if [[ "$2" == "-A" ]]; then
                                swaret --upgrade -a "" "" 1
                                echo
                                echo
                                swaret --upgrade -ap "" "" 1
                                echo
                                echo
                                swaret --upgrade -ae "" "" 1
                                echo
                                exit
                        fi
                        if [[ "$3" == "-A" ]]; then
                                swaret --upgrade $2 -a "" 1
                                echo
                                echo
                                swaret --upgrade $2 -ap "" 1
                                echo
                                echo
                                swaret --upgrade $2 -ae "" 1
                                echo
                                exit
                        else
                                swaret --upgrade $2 "" "" 1
                                echo
                                echo
                                swaret --upgrade $2 -p "" 1
                                echo
                                echo
                                swaret --upgrade $2 -e "" 1
                                echo
                                exit
                        fi
			;;
	"--install")
			function_install "" "$2" "$3" "$4" "$5"
			;;
        "--in-all")
                        echo

			URL
                        copy_from_cache

                        if [ -z $2 ]; then
                                swaret --help "" "" "" 1
                                exit
                        fi
                        if [[ "$3" == "-A" ]]; then
                                swaret --install $2 -a "" 1
                                echo
                                echo
                                swaret --install $2 -ap "" 1
                                echo
                                echo
                                swaret --install $2 -ae "" 1
                                echo
                                exit
                        else
                                swaret --install $2 "" "" 1
                                echo
                                echo
                                swaret --install $2 -p "" 1
                                echo
                                echo
                                swaret --install $2 -e "" 1
                                echo
                                exit
                        fi
                        ;;
        "--reinstall")
			function_reinstall "" "$2" "$3" "$4" "$5"
                        ;;
        "--rein-all")
                        echo

                        URL
                        copy_from_cache

                        if [ -z $2 ]; then
                                help
                                exit
                        fi
                        if [[ "$3" == "-A" ]]; then
                                swaret --reinstall $2 -a "" 1
                                echo
                                echo
                                swaret --reinstall $2 -ap "" 1
                                echo
                                echo
                                swaret --reinstall $2 -ae "" 1
                                echo
                                exit
                        else
                                swaret --reinstall $2 "" "" 1
                                echo
                                echo
                                swaret --reinstall $2 -p "" 1
                                echo
                                echo
                                swaret --reinstall $2 -e "" 1
                                echo
                                exit
                        fi
                        ;;
	"--remove")
			echo

                        if [ -z "$2" ]; then
	                        MSGERR "--remove" "Please, provide a Keyword to Remove!"
                        fi
                        export GO=0
                        echo "$2" | grep -q '^[[:alpha:]]\+' && export GO=1
                        if test $GO -eq 0
                        then
				invalid_charz
                        fi
			if test `ls $PACKAGES_LOGDIR/$2* 2>/dev/null | grep -v "dl$" | grep -v "rob$" | grep -v "mybuild$" | wc -l` -eq 0
			then
				MSGERR "--remove" "No installed Packages/Patches/Extra Packages found matching Keyword: $2!"
			fi
			PKGS=`ls -a $PACKAGES_LOGDIR/$2* 2>/dev/null | grep -v "dl$" | grep -v "rob$" | grep -v "mybuild$" | sed -e "s/.*\///g"` 
			if test `ls -alL $PACKAGES_LOGDIR/$2* 2>/dev/null | grep -v "dl$" | grep -v "rob$" | grep -v "mybuild$" | wc -l` -ge 1
			then
				z=0
				xCOUNTER=0
				zCOUNTER=0
				XDL=0
				echo "Making a List of installed Packages/Patches/Extra Packages matching Keyword: $2..."
				for i in $PKGS
				do
					xCOUNTER=`expr $xCOUNTER + 1`
				done
                                for i in $PKGS
                                do
						echo "$i "
                                                zCOUNTER=`expr $zCOUNTER + 1`
						if [[ "$zCOUNTER" != "$xCOUNTER" ]]; then
                                                        ls_break "Packages/Patches/Extra Packages"
                                                fi
				done
				echo
			fi
			if [[ "$3" = "-A" ]]; then
				for i in $PKGS
				do
					SHORTPKG=`echo $i | sed s/'.tgz'//`
					echo -n "=> Removing $SHORTPKG... "
					if [[ "$DESC" = "NO" ]]; then
						removepkg $i >/dev/null 2>&1
					else
						removepkg $i
					fi
					if [ ! -f $PACKAGES_LOGDIR/$i ]; then
						echo "DONE!"
						logme "--remove" "=> Removing $SHORTPKG... DONE!"
					else
						echo "FAILED!"
						logme "--remove" "=> Removing $SHORTPKG... FAILED!"
					fi
				done
			else
				QSWAP=0
				for i in $PKGS
				do
				    if [ ! -f $i.pmt ]; then
					SHORTPKG=`echo $i | sed s/'.tgz'//`
					echo -n "Remove $SHORTPKG? (y/n): [y]"
					read answer
					if [ -z "$answer" ]; then
						answer="y"
					else
						if [[ $answer != "y" ]]; then
							answer="n"
						fi
					fi
					logme "--remove" "Remove $SHORTPKG? (y/n): [$answer]"
					case $answer in
						"y")
							QSWAP=1
							echo $i >> REMOVEPKGSLIST.list
							;;
						"n")
							;;
						*)
							invalid_charz
							;;
					esac
				    fi
				done 
                                        if test $QSWAP -eq 1; then
                                                echo
                                        fi
				if [ -f REMOVEPKGSLIST.list ]; then
					for i in `cat REMOVEPKGSLIST.list 2>/dev/null`
					do
						 SHORTPKG=`echo $i | sed s/'.tgz'//`
                                                 echo -n "=> Removing $SHORTPKG... "
						 if [[ "$DESC" = "NO" ]]; then
						 	removepkg $i >/dev/null 2>&1
						 else
							removepkg $i
						 fi
                                                 if [ ! -f $PACKAGES_LOGDIR/$i ]; then
                                                         echo "DONE!"
							 logme "--remove" "=> Removing $SHORTPKG... DONE!"
                                                 else
                                                         echo "FAILED!"
							 logme "--remove" "=> Removing $SHORTPKG... FAILED!"
                                                 fi
					done
				fi
			fi
			echo
			;;
	"--list")
			echo

			copy_from_cache

			SWAPME=0
                        if [[ "$2" = "-p" || "$2" = "-up" ]]; then
                                check_patch_files
				SWAPME=1
                        fi
                        if [[ "$2" = "-e" || "$2" = "-ue" ]]; then
                                check_extra_files
				SWAPME=1
                        fi
			if test $SWAPME -eq 0
			then
                                check_package_files
                        fi

			if [[ "$2" = "-i" ]]; then
        	                LIST=`ls $PACKAGES_LOGDIR/*-* 2>/dev/null | grep -v "dl$" | grep -v "rob$" | grep -v "mybuild$" | sed -e "s/.*\///g"`
				echo "Making a List of installed Packages..."
                                z=0
                                xCOUNTER=0
                                zCOUNTER=0
                                for i in $LIST
                                do
                                        xCOUNTER=`expr $xCOUNTER + 1`
                                done
				zME=0
				for i in $LIST
                        	do
					zME=`expr $zME + 1`
					echo $i | sed s/'.tgz'//
                                        zCOUNTER=`expr $zCOUNTER + 1`
                                        if [[ "$zCOUNTER" != "$xCOUNTER" ]]; then
                                                ls_break "Packages"
                                        fi
	                        done
				echo
				if test $zME -eq 1
				then
					MSGERR "--list -i" "1 Package"
				else
					MSGERR "--list -i" "$zME Packages"
				fi
				exit
			fi
			if [[ "$2" == "-n" ]]; then
				LIST=`cat CHECKSUMS.md5 2>/dev/null | awk '{print$2}' | sed -e "s/.*\///g" | sort`
				echo "Making a List of none installed Packages..."
                                z=0
                                xCOUNTER=0
                                zCOUNTER=0
                                for i in $LIST
                                do
                                        xCOUNTER=`expr $xCOUNTER + 1`
                                done
				zME=0
				for i in $LIST
				do
					SHORT=`echo $i | sed s/'.tgz'//`
					if [ ! -f $PACKAGES_LOGDIR/$SHORT ]; then
                                                SHORTPKG=`echo $i | sed s/'.tgz'//`
                                                SIZEPKGTMP=`cat CHECKSUMS 2>/dev/null | grep "/$i" | awk '{print$2}'`
                                                SIZEPKG=`echo $SIZEPKGTMP / 1024 | bc`
						zME=`expr $zME + 1`
                                                echo "$SHORTPKG ($SIZEPKG kB) "
                                        	zCOUNTER=`expr $zCOUNTER + 1`
                                        	if [[ "$zCOUNTER" != "$xCOUNTER" ]]; then
                                                	ls_break "Packages"
                                        	fi
					fi
				done
				echo
				if test $zME -eq 1
				then
					MSGERR "--list -n" "1 Package"
				else
					MSGERR "--list -n" "$zME Packages"
				fi
				exit
			fi
                        if [[ "$2" == "-np" ]]; then
                         	swap_to_patches
                          	check_patch_files
                          	make_patches_list
                                LIST=`cat CHECKSUMS.md5.patches.tmp 2>/dev/null | sort`
                                echo "Making a List of none installed Patches..."
                                z=0
                                xCOUNTER=0
                                zCOUNTER=0
                                for i in $LIST
                                do
                                        xCOUNTER=`expr $xCOUNTER + 1`
                                done
				zME=0
                                for i in $LIST
                                do
                                        SHORT=`echo $i | sed s/'.tgz'//`
                                        if [ ! -f $PACKAGES_LOGDIR/$SHORT ]; then
                                                SHORTPKG=`echo $i | sed s/'.tgz'//`
                                                SIZEPKGTMP=`cat CHECKSUMS 2>/dev/null | grep "/$i" | awk '{print$2}'`
                                                SIZEPKG=`echo $SIZEPKGTMP / 1024 | bc`
						zME=`expr $zME + 1`
                                                echo "$SHORTPKG ($SIZEPKG kB) "
                                                zCOUNTER=`expr $zCOUNTER + 1`
                                                if [[ "$zCOUNTER" != "$xCOUNTER" ]]; then
                                                        ls_break "Patches"
                                                fi
                                        fi
                                done
                                echo
                                if test $zME -eq 1
                                then
                                        MSGERR "--list -np" "1 Patch"
                                else
                                        MSGERR "--list -np" "$zME Patches"
                                fi
                          	exit
                        fi
                        if [[ "$2" == "-ne" ]]; then
                         	swap_to_extra
                          	check_extra_files
                          	make_extra_list
				LIST=`cat CHECKSUMS.md5.extra.tmp 2>/dev/null | sort`
                                echo "Making a List of none installed Extra Packages..."
                                z=0
                                xCOUNTER=0
                                zCOUNTER=0
                                for i in $LIST
                                do
                                        xCOUNTER=`expr $xCOUNTER + 1`
                                done
				zME=0
                                for i in $LIST
                                do
                                        SHORT=`echo $i | sed s/'.tgz'//`
                                        if [ ! -f $PACKAGES_LOGDIR/$SHORT ]; then
                                		SHORTPKG=`echo $i | sed s/'.tgz'//`
                                		SIZEPKGTMP=`cat CHECKSUMS 2>/dev/null | grep "/$i" | awk '{print$2}'`
                                		SIZEPKG=`echo $SIZEPKGTMP / 1024 | bc`
						zME=`expr $zME + 1`
                                                echo "$SHORTPKG ($SIZEPKG kB) "
                                                zCOUNTER=`expr $zCOUNTER + 1`
                                                if [[ "$zCOUNTER" != "$xCOUNTER" ]]; then
                                                        ls_break "Extra Packages"
                                                fi
                                        fi
                                done
                                echo
                                if test $zME -eq 1
                                then
                                        MSGERR "--list -ne" "1 Extra Package"
                                else
                                        MSGERR "--list -ne" "$zME Extra Packages"
                                fi
                          	exit
                        fi
			if [[ "$2" == "-u" || "$2" == "-up" || "$2" == "-ue" ]]; then
			z=0
                        SWAPME=0
                        if [[ "$2" = "-p" || "$2" = "-up" ]]; then
                              check_patch_files
                                        PKGS=`ls $PACKAGES_LOGDIR/* 2>/dev/null`
                                        NPKGS=`ls $PACKAGES_LOGDIR/* 2>/dev/null | wc -l`
                                        if [[ "$WARNINGS" == "1" ]]; then
                                                echo "WARNING: This will take some time. Be patient!"
                                                if [[ "$INFORMATION" != "1" ]]; then
                                                        echo
                                                fi
                                        fi
                                        if [[ "$INFORMATION" == "1" ]]; then
                                                printf "INFORMATION: When you see different versions of a Patch,\n"
                                                printf "             you will need to remove all versions of that Patch,\n"
                                                printf "             but not the most recent one!\n"
                                                printf "             Hit 'CTRL + C' and use 'swaret --remove PATCH-VERSION'\n"
                                                printf "             to solve this problem and restart!\n\n"
                                        fi
                              echo "Making a List of installed Patches to Upgrade..."
                              SWAPME=1
                        fi
                        if [[ "$2" = "-e" || "$2" = "-ue" ]]; then
                              check_extra_files
                                        PKGS=`ls $PACKAGES_LOGDIR/ 2>/dev/null`
                                        NPKGS=`ls $PACKAGES_LOGDIR/ 2>/dev/null | wc -l`
                                        if [[ "$WARNINGS" == "1" ]]; then
                                                echo "WARNING: This will take some time. Be patient!"
                                                if [[ "$INFORMATION" != "1" ]]; then
                                                        echo
                                                fi
                                        fi
                                        if [[ "$INFORMATION" == "1" ]]; then
                                                printf "INFORMATION: When you see different versions of a Extra Package,\n"
                                                printf "             you will need to remove all versions of that Extra Package,\n"
                                                printf "             but not the most recent one!\n"
                                                printf "             Hit 'CTRL + C' and use 'swaret --remove EXTRA-PACKAGE-VERSION'\n"
                                                printf "             to solve this problem and restart!\n\n"
                                        fi
                              echo "Making a List of installed Extra Packages to Upgrade..."
                              SWAPME=1
                        fi
                        if test $SWAPME -eq 0
                        then
                              check_package_files
                                        PKGS=`ls $PACKAGES_LOGDIR/ 2>/dev/null`
                                        NPKGS=`ls $PACKAGES_LOGDIR/ 2>/dev/null | wc -l`
                                        if [[ "$WARNINGS" == "1" ]]; then
                                                echo "WARNING: This will take some time. Be patient!"
                                                if [[ "$INFORMATION" != "1" ]]; then
                                                        echo
                                                fi
                                        fi
                                        if [[ "$INFORMATION" == "1" ]]; then
                                                printf "INFORMATION: When you see different versions of a Package,\n"
                                                printf "             you will need to remove all versions of that Package,\n"
                                                printf "             but not the most recent one!\n"
                                                printf "             Hit 'CTRL + C' and use 'swaret --remove PACKAGE-VERSION'\n"
                                                printf "             to solve this problem and restart!\n\n"
                                        fi
                              echo "Making a List of installed Packages to Upgrade..."
                        fi
                        SWAPUS=0
                        if test $NPKGS -eq 0; then
                          NPKGS=`ls $PACKAGES_LOGDIR/* 2>/dev/null | wc -l`
                          NPKGS=`echo $NPKGS | awk '{print$1}'`
                          if test $NPKGS -eq 0; then
                            echo
                            if [[ "$3" = "-p" || "$3" = "-ap" ]]; then
                              MSGERR "--list [-u|-up|-ue]" "No installed Patches found!"
                              SWAPUS=1
                            fi
                            if [[ "$3" = "-e" || "$3" = "-ae" ]]; then
                              MSGERR "--list [-u|-up|-ue]" "No installed Extra Packages found!"
                              SWAPUS=1
                            fi
                            if test $SWAPUS -eq 0; then
                              MSGERR "--list [-u|-up|-ue]" "No installed Packages found!"
                            fi
                          fi
                        fi
                        NPKGS=`echo $NPKGS | awk '{print$1}'`
                        SWAPME=0
                        if [[ "$2" = "-up" ]]; then
                          SWAPME=1
                          swap_to_patches
                          make_patches_list
			  SORT_OF_PKG="Patches"
                        fi
                        if [[ "$2" = "-ue" ]]; then
                          SWAPME=1
                          swap_to_extra
                          make_extra_list
                          SWAPME=1
			  SORT_OF_PKG="Extra Packages"
                        fi
                        if test $SWAPME -eq 0
                        then
                          cat CHECKSUMS.md5 2>/dev/null | sed -e "s/.*\///g" > CHECKSUMS.md5.upgrade
			  SORT_OF_PKG="Packages"
                        fi
			z=0
			zME=0
			SWAPME=0
			IPKGS=`ls -a $PACKAGES_LOGDIR/ 2>/dev/null | grep -v "dl$" | grep -v "rob$" | grep -v "mybuild$" | sed -e "s/.*\///g" | grep "-"`
                        for i in $IPKGS
                        do
                                iTMP=`echo $i | sed s/'.tgz'// | sed -e "s/.*\///g" | sed -e s/-[0-9].*//`
				iTMP2=`echo $i | sed -e 's/-[0-9\.]*\(_[^-]*\).*/-\1/' | sed -e s/-[0-9].*//`
                                APKGS=`cat CHECKSUMS 2>/dev/null | grep "/$iTMP" | sed s/'.tgz'// | sed -e "s/.*\///g"`
                                for x in $APKGS
                                do
                                        aTMP=`echo $x | sed -e s/-[0-9].*//`
                                        aTMP2=`echo $x | sed -e 's/-[0-9\.]*\(_[^-]*\).*/-\1/' | sed -e s/-[0-9].*//`
                                        if [[ "$iTMP" == "$aTMP" ]]; then
                                          if [[ "$iTMP2" == "$aTMP2" ]]; then
                                                if test `ls $REMOVED_PACKAGES_LOGDIR/$i* 2>/dev/null | wc -l` -eq 0; then
                                                        if test `ls $REMOVED_PACKAGES_LOGDIR/$x* 2>/dev/null | wc -l` -eq 0; then
                                                                if [ ! -f $PACKAGES_LOGDIR/$x ]; then
									zME=`expr $zME + 1`
									upgradefromoldtonew
									ls_break "$SORT_OF_PKG"
                                                                fi
                                                        fi
                                                fi
					  fi
                                        fi
                                done
                        done

			echo
                        SWAPME=0
                        if [[ "$2" = "-p" || "$3" = "-p" || "$2" = "-up" || "$3" = "-up" ]]; then
                           if test $zME -eq 0
                           then
                            MSGERR "--list [-p|-up]" "Installed Patches are up to date!"
                           else
                            if test $zME -eq 1
                            then
                              MSGERR "--list [-p|-up]" "$zME Patch!"
                            else
                              MSGERR "--list [-p|-up]" "$zME Patches!"
                            fi
                           fi
                           SWAPME=1
                        fi
                        if [[ "$2" = "-e" || "$3" = "-e" || "$2" = "-ue" || "$3" = "-ue" ]]; then
                         if test $SWAPME -eq 0
			 then
                            if test $zME -eq 0
                            then
                              MSGERR "--list [-e|-ue]" "Installed Extra Packages are up to date!"
                            else
                             if test $zME -eq 1
                             then
                              MSGERR "--list [-e|-ue]" "$zME Extra Package"
                             else
                              MSGERR "--list [-e|-ue]" "$zME Extra Packages"
                             fi
                            fi
                            SWAPME=1
                         fi
                        fi
                        if test $SWAPME -eq 0
                        then
                           if test $zME -eq 0
                           then
			     MSGERR "--list [-u]" "Installed Packages are up to date!"
                           else
                            if test $zME -eq 1
                            then
                              MSGERR "--list [-u]" "$zME Package"
                            else
                              MSGERR "--list [-u]" "$zME Packages"
                            fi
                           fi
                        fi
			exit
			fi
                        if [[ "$2" = "-p" ]]; then
			  swap_to_patches
			  check_patch_files
			  make_patches_list
                          LIST=`cat CHECKSUMS.md5.patches.tmp 2>/dev/null | sort`
                          echo "Making a List of available Patches..."
                          z=0
                          xCOUNTER=0
                          zCOUNTER=0
                          for i in $LIST 
                          do
                                xCOUNTER=`expr $xCOUNTER + 1`
                          done
			  zME=0
                          for i in $LIST
                          do
                                SHORTPKG=`echo $i | sed s/'.tgz'//`
                                SIZEPKGTMP=`cat CHECKSUMS 2>/dev/null | grep "/$i" | awk '{print$2}'`
                                SIZEPKG=`echo $SIZEPKGTMP / 1024 | bc`
				zME=`expr $zME + 1`
                                echo -n "$SHORTPKG ($SIZEPKG kB) "
                                if [ -f $PACKAGES_LOGDIR/$SHORTPKG ]; then
                                        echo "(Status: Installed)"
                                else
                                        echo "(Status: Not Installed)"
                                fi
                                zCOUNTER=`expr $zCOUNTER + 1`
                                if [[ "$zCOUNTER" != "$xCOUNTER" ]]; then
                                      ls_break "Patches"
                                fi
                          done
                          echo
                          if test $zME -eq 1
                          then
                                MSGERR "--list [-p]" "$zME Patch!"
                          else
                                MSGERR "--list [-p]" "$zME Patches!"
                          fi
                          exit
                        fi
                        if [[ "$2" = "-e" ]]; then
			  swap_to_extra
                          check_extra_files
			  make_extra_list
                          LIST=`cat CHECKSUMS.md5.extra.tmp 2>/dev/null | sort`
                          echo "Making a List of available Extra Packages..."
                          z=0
                          xCOUNTER=0
                          zCOUNTER=0
                          for i in $LIST
                          do
                                xCOUNTER=`expr $xCOUNTER + 1`
                          done
			  zME=0
                          for i in $LIST
                          do
                                SHORTPKG=`echo $i | sed s/'.tgz'//`
                                SIZEPKGTMP=`cat CHECKSUMS 2>/dev/null | grep "/$i" | awk '{print$2}'`
                                SIZEPKG=`echo $SIZEPKGTMP / 1024 | bc`
				zME=`expr $zME + 1`
                                echo -n "$SHORTPKG ($SIZEPKG kB) "
                                if [ -f $PACKAGES_LOGDIR/$SHORTPKG ]; then
                                        echo "(Status: Installed)"
                                else
                                        echo "(Status: Not Installed)"
                                fi
                                zCOUNTER=`expr $zCOUNTER + 1`
                                if [[ "$zCOUNTER" != "$xCOUNTER" ]]; then
                                      ls_break "Extra Packages"
                                fi
                          done
                          echo
                          if test $zME -eq 1
                          then
                                MSGERR "--list [-e]" "$zME Extra Package!"
                          else
                                MSGERR "--list [-e]" "$zME Extra Packages!"
                          fi
                          exit
                        fi
                        if [[ "$2" = "-s" ]]; then
                          swap_to_sources
                          check_source_files
                          LIST=`cat CHECKSUMS.sources 2>/dev/null | grep -vi build | sed -e "s/.*\///g" | sort`
                          echo "Making a List of available Sources..."
                          z=0
                          xCOUNTER=0
                          zCOUNTER=0
                          for i in $LIST
                          do
                                xCOUNTER=`expr $xCOUNTER + 1`
                          done
			  zME=0
                          for i in $LIST
                          do
                            SHORTPKG=`echo $i | sed s/'.tar.gz'//`
                            SHORTPKG=`echo $SHORTPKG | sed s/'.gz'//`
                            SHORTPKG=`echo $SHORTPKG | sed s/'.tar.bz2'//`
                            SHORTPKG=`echo $SHORTPKG | sed s/'.bz2'//`
                            if test `cat CHECKSUMS 2>/dev/null | grep "/$i" | wc -l` -eq 1; then
				SIZEPKGTMP=`cat CHECKSUMS 2>/dev/null | grep "/$i" | awk '{print$2}'`
                                SIZEPKG=`echo $SIZEPKGTMP / 1024 | bc`
				zME=`expr $zME + 1`
				if test $SIZEPKG -eq 0; then
                                	echo "$SHORTPKG ($SIZEPKGTMP B) "
				else
					echo "$SHORTPKG ($SIZEPKG kB) "
				fi
                                zCOUNTER=`expr $zCOUNTER + 1`
                                if [[ "$zCOUNTER" != "$xCOUNTER" ]]; then
                                      ls_break "Sources"
                                fi
			    fi
                          done  
                          echo
                          if test $zME -eq 1
                          then
                                MSGERR "--list [-s]" "$zME Source!"
                          else  
                                MSGERR "--list [-s]" "$zME Sources!"
                          fi
                          exit
                        fi
			LIST=`cat CHECKSUMS.md5 2>/dev/null | awk '{print$2}' | sed -e "s/.*\///g" | sort`
			echo "Making a List of available Packages..."
                        z=0
                        xCOUNTER=0
                        zCOUNTER=0
                        for i in $LIST
                        do
                                xCOUNTER=`expr $xCOUNTER + 1`
                        done
			zME=0
			for i in $LIST
			do
				SHORTPKG=`echo $i | sed s/'.tgz'//`
				SIZEPKGTMP=`cat CHECKSUMS 2>/dev/null | grep "/$i" | awk '{print$2}'`
				SIZEPKG=`echo $SIZEPKGTMP / 1024 | bc`
				zME=`expr $zME + 1`
				echo -n "$SHORTPKG ($SIZEPKG kB) "
				if [ -f $PACKAGES_LOGDIR/$SHORTPKG ]; then
					echo "(Status: Installed)"
				else
					echo "(Status: Not Installed)"
				fi
                                zCOUNTER=`expr $zCOUNTER + 1`
                                if [[ "$zCOUNTER" != "$xCOUNTER" ]]; then
                                      ls_break "Packages"
                                fi
			done
			echo
			if test $zME -eq 1
			then
				MSGERR "--list" "$zME Package"
			else
				MSGERR "--list" "$zME Packages"
			fi
			;;
	"--search")
			echo

			copy_from_cache

                        SWAPME=0
                        if [[ "$3" = "-p" || "$3" = "-up" ]]; then
                                check_patch_files
                                SWAPME=1
                        fi
                        if [[ "$3" = "-e" || "$3" = "-ue" ]]; then
                                check_extra_files
                                SWAPME=1
                        fi
                        if test $SWAPME -eq 0
                        then
                                check_package_files
                        fi
			
			COUNT=0
			if [ -z "$2" ]; then
				MSGERR "--search" "Please, provide a Keyword to Search!"
			fi
			export GO=0
			echo "$2" | grep -q '^[[:alpha:]]\+' && export GO=1
			if test $GO -eq 0
			then
				invalid_charz
			fi
			SHORTPKGTMP=`echo $2 | sed s/'.tgz'//`
			if [[ "$3" = "-i" ]]; then
				LIST=`ls $PACKAGES_LOGDIR/$2* 2>/dev/null | grep -v "dl$" | grep -v "rob$" | grep -v "mybuild$" | sed -e "s/.*\///g"`
				echo "Making a List of installed Packages matching Keyword: $2..."
                        	z=0
                        	xCOUNTER=0
                        	zCOUNTER=0
                        	for i in $LIST 
                        	do
                                	xCOUNTER=`expr $xCOUNTER + 1`
                        	done
				zME=0
				for i in $LIST
				do
					zME=`expr $zME + 1`
                                        echo $i | sed s/'.tgz'//
                                	zCOUNTER=`expr $zCOUNTER + 1`
                                	if [[ "$zCOUNTER" != "$xCOUNTER" ]]; then
                                        	ls_break "Packages"
                                	fi
				done
				echo 
				if test $zME -ge 1
				then
					if test $zME -eq 1
					then
						MSGERR "--search [-i]" "$zME Package is matching the Keyword: $2!"
					else
						MSGERR "--search [-i]" "$zME Packages are matching the Keyword: $2!"
					fi
				else
					MSGERR "--search [-i]" "No installed Packages found matching Keyword: $2!"
				fi
				exit
			fi
			if [[ "$3" = "-n" ]]; then
				LIST=`cat CHECKSUMS.md5 2>/dev/null | grep "/$2" | awk '{print$2}' | sed -e "s/.*\///g"`
				echo "Making a List of none installed Packages matching Keyword: $2..."
                                z=0
                                xCOUNTER=0
                                zCOUNTER=0
                                for i in $LIST
                                do
                                        xCOUNTER=`expr $xCOUNTER + 1`
                                done
				zME=0
				for i in $LIST
				do
					SHORT=`echo $i | sed s/'.tgz'//`
					if [ ! -f $PACKAGES_LOGDIR/$SHORT ]; then
                                                SHORTPKG=`echo $i | sed s/'.tgz'//`
                                                SIZEPKGTMP=`cat CHECKSUMS 2>/dev/null | grep "/$i" | awk '{print$2}'`
                                                SIZEPKG=`echo $SIZEPKGTMP / 1024 | bc`
						zME=`expr $zME + 1`
                                                echo "$SHORTPKG ($SIZEPKG kB) "
                                        	zCOUNTER=`expr $zCOUNTER + 1`
                                        	if [[ "$zCOUNTER" != "$xCOUNTER" ]]; then
                                                	ls_break "Packages"
                                        	fi
					fi
				done
				echo 
				if test $zME -ge 1
				then
					if test $zME -eq 1
					then
						MSGERR "--search [-n]" "$zME Package is matching the Keyword: $2!"
					else
						MSGERR "--search [-n]" "$zME Packages are matching the Keyword: $2!"
					fi
				else
					MSGERR "--search [-n]" "No Packages found matching Keyword: $2!"
				fi
				exit
			fi
                        if [[ "$3" = "-np" ]]; then
                         	swap_to_patches
                          	check_patch_files
                          	make_patches_list
                                LIST=`cat CHECKSUMS.md5.patches.tmp 2>/dev/null | grep "/$2" | sort`
				echo "Making a List of none installed Patches matching Keyword: $2..."
                                z=0
                                xCOUNTER=0
                                zCOUNTER=0
                                for i in $LIST
                                do
                                        xCOUNTER=`expr $xCOUNTER + 1`
                                done
				zME=0
                                for i in $LIST
                                do
                                        SHORT=`echo $i | sed s/'.tgz'//`
                                        if [ ! -f $PACKAGES_LOGDIR/$SHORT ]; then
                                                SHORTPKG=`echo $i | sed s/'.tgz'//`
                                                SIZEPKGTMP=`cat CHECKSUMS 2>/dev/null | grep -w "$SHORTPKG" | awk '{print$2}'`
                                                SIZEPKG=`echo $SIZEPKGTMP / 1024 | bc`
						zME=`expr $zME + 1`
                                                echo "$SHORTPKG ($SIZEPKG kB) "
                                                zCOUNTER=`expr $zCOUNTER + 1`
                                                if [[ "$zCOUNTER" != "$xCOUNTER" ]]; then
                                                        ls_break "Patches"
                                                fi
                                        fi
                                done
				echo 
                                if test $zME -ge 1
                                then
                                        if test $zME -eq 1
                                        then
                                                MSG "--search [-np]" "$zME Patch is matching the Keyword: $2!"
                                        else
                                                MSG "--search [-np]" "$zME Patches are matching the Keyword: $2!"
                                        fi
                                else
					MSG "--search [-np]" "No Patches found matching Keyword: $2!"
                                fi
                          	exit
                        fi
                        if [[ "$3" = "-ne" ]]; then
                         	swap_to_extra
                          	check_extra_files
                          	make_extra_list
				LIST=`cat CHECKSUMS.md5.extra.tmp 2>/dev/null | grep "$2" | sort`
				echo "Making a List of none installed Extra Packages matching Keyword: $2..."
                                z=0
                                xCOUNTER=0
                                zCOUNTER=0
                                for i in $LIST
                                do
                                        xCOUNTER=`expr $xCOUNTER + 1`
                                done
				zME=0
                                for i in $LIST
                                do
                                        SHORT=`echo $i | sed s/'.tgz'//`
                                        if [ ! -f $PACKAGES_LOGDIR/$SHORT ]; then
                                                SHORTPKG=`echo $i | sed s/'.tgz'//`
                                                SIZEPKGTMP=`cat CHECKSUMS 2>/dev/null | grep "/$i" | awk '{print$2}'`
                                                SIZEPKG=`echo $SIZEPKGTMP / 1024 | bc`
						zME=`expr $zME + 1`
                                                echo "$SHORTPKG ($SIZEPKG kB) "
                                                zCOUNTER=`expr $zCOUNTER + 1`
                                                if [[ "$zCOUNTER" != "$xCOUNTER" ]]; then
                                                        ls_break "Extra Packages"
                                                fi
                                        fi
                                done
				echo 
                                if test $zME -ge 1
                                then
                                        if test $zME -eq 1
                                        then
                                                MSG "--search [-ne]" "$zME Extra Package is matching the Keyword: $2!"
                                        else
                                                MSG "--search [-ne]" "$zME Extra Packages are matching the Keyword: $2!"
                                        fi
                                else
					MSG "--search [-ne]" "No Extra Packages round matching Keyword: $2!"	
                                fi
                          	exit
                        fi
			if [[ "$3" = "-u" || "$3" = "-up" || "$3" = "-ue" ]]; then
			 z=0
                         SWAPME=0
                         if [[ "$3" = "-p" || "$3" = "-up" ]]; then
                               check_patch_files
                                        PKGS=`ls $PACKAGES_LOGDIR/$2* 2>/dev/null`
                                        NPKGS=`ls $PACKAGES_LOGDIR/$2* 2>/dev/null | wc -l`
                                        if [[ "$WARNINGS" == "1" ]]; then
                                                echo "WARNING: This will take some time. Be patient!"
                                                if [[ "$INFORMATION" != "1" ]]; then
                                                        echo
                                                fi
                                        fi
                                        if [[ "$INFORMATION" == "1" ]]; then
                                                printf "INFORMATION: When you see different versions of a Patch,\n"
                                                printf "             you will need to remove all versions of that Patch,\n"
                                                printf "             but not the most recent one!\n"
                                                printf "             Hit 'CTRL + C' and use 'swaret --remove PATCH-VERSION'\n"
                                                printf "             to solve this problem and restart!\n\n"
                                        fi
                               echo "Making a List of installed Patches to Upgrade matching Keyword: $2..."
                               SWAPME=1
                         fi
                         if [[ "$3" = "-e" || "$3" = "-ue" ]]; then
                               check_extra_files
                                        PKGS=`ls $PACKAGES_LOGDIR/$2* 2>/dev/null`
                                        NPKGS=`ls $PACKAGES_LOGDIR/$2* 2>/dev/null | wc -l`
                                        if [[ "$WARNINGS" == "1" ]]; then
                                                echo "WARNING: This will take some time. Be patient!"
                                                if [[ "$INFORMATION" != "1" ]]; then
                                                        echo
                                                fi
                                        fi
                                        if [[ "$INFORMATION" == "1" ]]; then
                                                printf "INFORMATION: When you see different versions of a Extra Package,\n"
                                                printf "             you will need to remove all versions of that Extra Package,\n"
                                                printf "             but not the most recent one!\n"
                                                printf "             Hit 'CTRL + C' and use 'swaret --remove EXTRA-PACKAGE-VERSION'\n"
                                                printf "             to solve this problem and restart!\n\n"
                                        fi
                               echo "Making a List of installed Extra Packages to Upgrade matching Keyword: $2..."
                               SWAPME=1
                         fi
                         if test $SWAPME -eq 0
                         then
                               check_package_files
                                        PKGS=`ls $PACKAGES_LOGDIR/$2* 2>/dev/null`
                                        NPKGS=`ls $PACKAGES_LOGDIR/$2* 2>/dev/null | wc -l`
                                        if [[ "$WARNINGS" == "1" ]]; then
                                                echo "WARNING: This will take some time. Be patient!"
                                                if [[ "$INFORMATION" != "1" ]]; then
                                                        echo
                                                fi
                                        fi
                                        if [[ "$INFORMATION" == "1" ]]; then
                                                printf "INFORMATION: When you see different versions of a Package,\n"
                                                printf "             you will need to remove all versions of that Package,\n"
                                                printf "             but not the most recent one!\n"
                                                printf "             Hit 'CTRL + C' and use 'swaret --remove PACKAGE-VERSION'\n"
                                                printf "             to solve this problem and restart!\n\n"
                                        fi
                               echo "Making a List of installed Packages to Upgrade matching Keyword: $2..."
                         fi
                         SWAPUS=0
                         if test $NPKGS -eq 0; then
                           NPKGS=`ls $PACKAGES_LOGDIR/$2* 2>/dev/null | wc -l`
                           NPKGS=`echo $NPKGS | awk '{print$1}'`
                           if test $NPKGS -eq 0; then
                             echo
                             if [[ "$3" = "-p" || "$3" = "-ap" ]]; then
                               MSGERR "--search [-u|-up|-ue]" "No installed Patches found matching Keyword: $2!"
                               SWAPUS=1
                             fi
                             if [[ "$3" = "-e" || "$3" = "-ae" ]]; then
                               MSGERR "--search [-u|-up|-ue]" "No installed Extra Packages found matching Keyword: $2!"
                               SWAPUS=1
                             fi
                             if test $SWAPUS -eq 0; then
                               MSGERR "--search [-u|-up|-ue]" "No installed Packages found matching Keyword: $2!"
                             fi
                             exit
                           fi
                         fi
                         NPKGS=`echo $NPKGS | awk '{print$1}'`
                         SWAPME=0
                         if [[ "$3" = "-up" ]]; then
                          SWAPME=1
                          swap_to_patches
                          make_patches_list
			  SORT_OF_PKG="Patches"
                         fi
                         if [[ "$3" = "-ue" ]]; then
                          SWAPME=1
                          swap_to_extra
                          make_extra_list
			  SORT_OF_PKG="Extra Packages"
                         fi
                         if test $SWAPME -eq 0
                         then
                          cat CHECKSUMS.md5 2>/dev/null | sed -e "s/.*\///g" > CHECKSUMS.md5.upgrade
			  SORT_OF_PKG="Packages"
                         fi
                         z=0
			 zME=0
                         SWAPME=0
                         IPKGS=`ls -a $PACKAGES_LOGDIR/$2* 2>/dev/null | grep -v "dl$" | grep -v "rob$" | grep -v "mybuild$" | sed -e "s/.*\///g" | grep "-"`
                         for i in $IPKGS
                         do
                                iTMP=`echo $i | sed s/'.tgz'// | sed -e "s/.*\///g" | sed -e s/-[0-9].*//`
				iTMP2=`echo $i | sed -e 's/-[0-9\.]*\(_[^-]*\).*/-\1/' | sed -e s/-[0-9].*//`
                                APKGS=`cat CHECKSUMS 2>/dev/null | grep "/$iTMP" | sed s/'.tgz'// | sed -e "s/.*\///g"`
                                for x in $APKGS
                                do
                                        aTMP=`echo $x | sed -e s/-[0-9].*//`
                                        aTMP2=`echo $x | sed -e 's/-[0-9\.]*\(_[^-]*\).*/-\1/' | sed -e s/-[0-9].*//`
                                        if [[ "$iTMP" == "$aTMP" ]]; then
                                          if [[ "$iTMP2" == "$aTMP2" ]]; then
                                                if test `ls $REMOVED_PACKAGES_LOGDIR/$i* 2>/dev/null | wc -l` -eq 0; then
                                                        if test `ls $REMOVED_PACKAGES_LOGDIR/$x* 2>/dev/null | wc -l` -eq 0; then
                                                                if [ ! -f $PACKAGES_LOGDIR/$x ]; then
									zME=`expr $zME + 1`
									upgradefromoldtonew
									ls_break "$SORT_OF_PKG"
                                                                fi
                                                        fi
                                                fi
					  fi
                                        fi
                                done
                          done

			  echo
                          SWAPME=0
                          if [[ "$3" = "-p" || "$3" = "-up" ]]; then
                           if test $zME -eq 0
                           then
			       MSGERR "--search [-p|-up]" "Installed Patches matching Keyword '$2' are up to date!";
                           else
                            if test $zME -eq 1
                            then
                              MSGERR "--search [-p|-up]" "$zME Patch!"
                            else
                              MSGERR "--search [-p|-up]" "$zME Patches!"
                            fi
                           fi
                           SWAPME=1
                          fi
                          if [[ "$3" = "-e" || "$3" = "-ue" ]]; then
			   if test $SWAPME -eq 0
			   then
                            if test $zME -eq 0
                            then
                              MSGERR "--search [-e|-ue]" "Installed Extra Packages matching Keyword '$2' are up to date!"
                            else
                             if test $zME -eq 1
                             then
                              MSGERR "--search [-e|-ue]" "$zME Extra Package"
                             else
                              MSGERR "--search [-e|-ue]" "$zME Extra Packages"
                             fi
                            fi
                            SWAPME=1
			   fi
                          fi
                          if test $SWAPME -eq 0
                          then
                           if test $zME -eq 0
                           then
                            MSG "--search [-u]" "Installed Packages matching Keyword '$2' are up to date!"
                           else
                            if test $zME -eq 1
                            then
                              MSG "--search [-u]" "$zME Package"
                            else
                              MSG "--search [-u]" "$zME Packages"
                            fi
                           fi
                          fi
			  exit
			fi
			if [[ "$3" = "-p" ]]; then
			  swap_to_patches
			  check_patch_files
			  make_patches_list
			  LIST=`cat CHECKSUMS.md5.patches.tmp 2>/dev/null | grep "/$2" | sort`
                          echo "Making a List of available Patches matching Keyword: $2..."
                          z=0
                          xCOUNTER=0
                          zCOUNTER=0
                          for i in $LIST 
                          do
                                xCOUNTER=`expr $xCOUNTER + 1`
                          done
			  zME=0
                          for i in $LIST
                          do
                                SHORTPKG=`echo $i | sed s/'.tgz'//`
                                SIZEPKGTMP=`cat CHECKSUMS 2>/dev/null | grep "/$i" | awk '{print$2}'`
                                SIZEPKG=`echo $SIZEPKGTMP / 1024 | bc`
				zME=`expr $zME + 1`
                                echo -n "$SHORTPKG ($SIZEPKG kB) "
                                if [ -f $PACKAGES_LOGDIR/$SHORTPKG ]; then
                                        echo "(Status: Installed)"
                                else
                                        echo "(Status: Not Installed)"
                                fi
                                zCOUNTER=`expr $zCOUNTER + 1`
                                if [[ "$zCOUNTER" != "$xCOUNTER" ]]; then
                                      ls_break "Patches"
                                fi
                          done
		 	  echo
                          if test $zME -ge 1
                          then
                                if test $zME -eq 1
                                then
                                        MSGERR "--search [-p]" "$zME Patch is matching the Keyword: $2!"
                                else
                                        MSGERR "--search [-p]" "$zME Patches are matching the Keyword: $2!"
                                fi
                          else
				MSGERR "--search [-p]" "No available Patches found matching Keyword: $2!"
                          fi
			  exit
			fi
                        if [[ "$3" = "-e" ]]; then
			  swap_to_extra
			  check_extra_files
			  make_extra_list
                          LIST=`cat CHECKSUMS.md5.extra.tmp 2>/dev/null | grep "$2" | sort`
                          echo "Making a List of available Extra Packages matching Keyword: $2..."
                          z=0
                          xCOUNTER=0
                          zCOUNTER=0
                          for i in $LIST 
                          do
                                xCOUNTER=`expr $xCOUNTER + 1`
                          done
			  zME=0
                          for i in $LIST
                          do
                                SHORTPKG=`echo $i | sed s/'.tgz'//`
                                SIZEPKGTMP=`cat CHECKSUMS 2>/dev/null | grep "/$i" | awk '{print$2}'`
                                SIZEPKG=`echo $SIZEPKGTMP / 1024 | bc`
				zME=`expr $zME + 1`
                                echo -n "$SHORTPKG ($SIZEPKG kB) "
                                if [ -f $PACKAGES_LOGDIR/$SHORTPKG ]; then
                                        echo "(Status: Installed)"
                                else
                                        echo "(Status: Not Installed)"
                                fi
                                zCOUNTER=`expr $zCOUNTER + 1`
                                if [[ "$zCOUNTER" != "$xCOUNTER" ]]; then
                                      ls_break "Extra Packages"
                                fi
                          done
                          echo
                          if test $zME -ge 1
                          then
                                if test $zME -eq 1
                                then
                                        MSGERR "--search [-e]" "$zME Extra Package is matching the Keyword: $2!"
                                else
                                        MSGERR "--search [-e]" "$zME Extra Packages are matching the Keyword: $2!"
                                fi
                          else
				MSGERR "--search [-e]" "No available Extra Packages found matching Keyword: $2!"
                          fi
                          exit
                        fi
                        if [[ "$3" = "-s" ]]; then
                          swap_to_sources
                          check_source_files
                          LIST=`cat CHECKSUMS.sources 2>/dev/null | grep -vi build | grep "/$2" | sed -e "s/.*\///g" | sort`
                          echo "Making a List of available Sources matching Keyword: $2..."
                          z=0
                          xCOUNTER=0
                          zCOUNTER=0
                          for i in $LIST 
                          do
                                xCOUNTER=`expr $xCOUNTER + 1`
                          done
			  zME=0
                          for i in $LIST
                          do
                            SHORTPKG=`echo $i | sed s/'.tar.gz'//`
                            SHORTPKG=`echo $SHORTPKG | sed s/'.gz'//`
                            SHORTPKG=`echo $SHORTPKG | sed s/'.tar.bz2'//`
                            SHORTPKG=`echo $SHORTPKG | sed s/'.bz2'//`
                            if test `cat CHECKSUMS 2>/dev/null | grep "/$i" | wc -l` -eq 1; then
                                SIZEPKGTMP=`cat CHECKSUMS 2>/dev/null | grep "/$i" | awk '{print$2}'`
                                SIZEPKG=`echo $SIZEPKGTMP / 1024 | bc`
				zME=`expr $zME + 1`
				if test $SIZEPKG -eq 0; then
                                	echo "$SHORTPKG ($SIZEPKGTMP B) "
				else
					echo "$SHORTPKG ($SIZEPKG kB) "
				fi
                                zCOUNTER=`expr $zCOUNTER + 1`
                                if [[ "$zCOUNTER" != "$xCOUNTER" ]]; then
                                      ls_break "Sources"
                                fi
                            fi
                          done 
                          echo
                          if test $zME -ge 1
                          then
                                if test $zME -eq 1
                                then
                                        MSGERR "--search [-s]" "$zME Source is matching the Keyword: $2!"
                                else
                                        MSGERR "--search [-s]" "$zME Sources are matching the Keyword: $2!"
                                fi
                          else
                                MSGERR "--search [-s]" "No available Sources found matching Keyword: $2!"
                          fi
                          exit
                        fi
                        LIST=`cat CHECKSUMS.md5 2>/dev/null | grep "/$2" | sed -e "s/.*\///g" | sort`
                        echo "Making a List of available Packages matching Keyword: $2..."
			z=0
			xCOUNTER=0
			zCOUNTER=0
                        for i in $LIST
                        do
				xCOUNTER=`expr $xCOUNTER + 1`
			done
			zME=0
			for i in $LIST
			do
                		SHORTPKG=`echo $i | sed s/'.tgz'//`
                		SIZEPKGTMP=`cat CHECKSUMS 2>/dev/null | grep "/$i" | awk '{print$2}'`
                		SIZEPKG=`echo $SIZEPKGTMP / 1024 | bc`
				zME=`expr $zME + 1`
                                echo -n "$SHORTPKG ($SIZEPKG kB) "
                                if [ -f $PACKAGES_LOGDIR/$SHORTPKG ]; then
                                        echo "(Status: Installed)"
                                else
                                        echo "(Status: Not Installed)"
                                fi
				zCOUNTER=`expr $zCOUNTER + 1`
				if [[ "$zCOUNTER" != "$xCOUNTER" ]]; then
					ls_break "Packages"
				fi
                        done
			echo
                        if test $zME -ge 1
                        then
                                if test $zME -eq 1
                                then
                                        MSGERR "--search" "$zME Package is matching the Keyword: $2!"
                                else
                                        MSGERR "--search" "$zME Packages are matching the Keyword: $2!"
                                fi
                        else
				MSGERR "--search" "No available Packages found matching Keyword: $2!"
                        fi
			;;
	"--download")
			function_download "" "$2" "$3" "$4" "$5"
			;;
        "--do-all")
                        echo

                        URL
                        copy_from_cache

                        if [ -z $2 ]; then
                                swaret --help "" "" "" 1
                                exit
                        fi
                        if [[ "$3" == "-A" ]]; then
                                swaret --download $2 -a "" 1
                                echo
                                echo
                                swaret --download $2 -ap "" 1
                                echo
                                echo
                                swaret --download $2 -ae "" 1
                                echo
                                exit
                        else
                                swaret --download $2 "" "" 1
                                echo
                                echo
                                swaret --download $2 -p "" 1
                                echo
                                echo
                                swaret --download $2 -e "" 1
                                echo
                                exit
                        fi
			;;
        "--sources")
                        if [ -z $5 ]; then
                                echo
                        fi

                        URL

                        copy_from_cache

                        if [ -z "$2" ]; then
				if test `cat /etc/swaret.conf | grep -v "#" | grep "^ROOT=" | grep "file:" | wc -l` -ge 1; then
                                	MSGERR "--sources" "Please, provide a Keyword to Copy!"
				else
					MSGERR "--sources" "Please, provide a Keyword to Download!"
				fi
                        fi
                        export GO=0
                        echo "$2" | grep -q '^[[:alpha:]]\+' && export GO=1
                        if test $GO -eq 0
                        then
				invalid_charz
                        fi

                        swap_to_sources
                        check_source_files
                        PKGLIST=`cat CHECKSUMS.sources 2>/dev/null | grep "/$2" | grep -vi build | awk '{print$3}' | sed -e "s/.*\///g" | sort`
                        COUNT=`cat CHECKSUMS.sources 2>/dev/null | grep "/$2" | grep -vi build | wc -l`

                        if test $COUNT -eq 0
                        then
                           MSGERR "--sources" "No available Sources found matching Keyword: $2!"
                           exit
                        fi
                        echo "Making a List of available Sources matching Keyword: $2..."
                        if [[ "$3" = "-A" ]]; then
                                answer="y"
                        else
                                answer="n"
                        fi

                        if test $COUNT -ge 1
                        then
                        z=0
                        xCOUNTER=0
                        zCOUNTER=0
                        for i in $LIST
                        do
                                xCOUNTER=`expr $xCOUNTER + 1`
                        done
                        zME=0
                                for i in $PKGLIST
                                do
					zME=`expr $zME + 1`
                                        FIX=`echo "$i" | sed s/'.tar.gz'//`
                                        FIX=`echo $FIX | sed s/'.gz'//`
					FIX=`echo $FIX | sed s/'.tar.bz2'//`
                                        FIX=`echo $FIX | sed s/'.bz2'//`
                                        SIZEPKGTMP=`cat $CDIR/CHECKSUMS.sources 2>/dev/null | grep "/$i" | grep -vi build | awk '{print$2}'`
					for s in $SIZEPKGTMP
					do
                                        	SIZEPKG=`echo "$s / 1024" | bc`
						if test $SIZEPKG -eq 0; then
                                        		echo "$FIX ($s B)  "
						else
							echo "$FIX ($SIZEPKG kB)  "
						fi
                                		zCOUNTER=`expr $zCOUNTER + 1`
                                		if [[ "$zCOUNTER" != "$xCOUNTER" ]]; then
                                        		ls_break "Sources"
                                		fi
					done

                                done
                                echo
                        fi
			echo
                        FPKGSW=0
                        FPKGTSIZE=0
                        FPKGC=0
                        case $answer in
                                "y")
                                        DONE=1
                                        COUNTER=1
                                        for i in $PKGLIST
                                        do
                                                SHORTPKG=`echo $i | sed s/'.tar.gz'//`
                                                SHORTPKG=`echo $SHORTPKG | sed s/'.gz'//`
                                                SHORTPKG=`echo $SHORTPKG | sed s/'.tar.bz2'//`
                                                SHORTPKG=`echo $SHORTPKG | sed s/'.bz2'//`
                     				GETPKG=`cat CHECKSUMS.sources 2>/dev/null | awk '{print$3}' | grep "/" | sed s/'.\/'// | grep "/$i"`
					     if [ ! -f $CDIR/sources/$i ]; then
                        copy_pkg()
                        {
			  ROOTS=`cat /etc/swaret.conf | grep -v "#" | grep "^ROOT=" | grep "file:" | cut -f2 -d'=' | sed s/'file:'//`
			  for RR in $ROOTS
		          do
                              SHORTPKG=`echo "$1" | sed s/'.tar.gz'//`
                              SHORTPKG=`echo $SHORTPKG | sed s/'.gz'//`
                              SHORTPKG=`echo $SHORTPKG | sed s/'.tar.bz2'//`
                              SHORTPKG=`echo $SHORTPKG | sed s/'.bz2'//`
                              if [ ! -f $1 ]; then
                                  SWAPME=0
				  PACKAGE=`cat CHECKSUMS.sources 2>/dev/null | grep "$GETPKG" | grep "/$1" | awk '{print$3}' | grep "/" | sed s/'.\/'//`
                                  if [ ! -z $RR ]; then
					SIZEPKGTMP=`cat $CDIR/CHECKSUMS.sources 2>/dev/null | grep "$GETPKG" | grep "/$1" | awk '{print$2}'`
					SIZEPKG=`echo $SIZEPKGTMP / 1024 | bc`
                                        MSG "--install" "[ file:$RR ]"
					if test $SIZEPKG -eq 0; then
                                        	echo -n "### Copying $SHORTPKG ($SIZEPKGTMP B)... "
					else
						echo -n "### Copying $SHORTPKG ($SIZEPKG kB)... "
					fi
					copy_file "$RR" "$GETPKG"
                                        if [ -f $1 ]; then
                                                FPKGSW=1
                                                FPKGTSIZE=`echo "$FPKGTSIZE + $SIZEPKG" | bc` 
                                                FPKGC=`echo "$FPKGC + 1" | bc`
                                                echo "DONE!"
						if test $SIZEPKG -eq 0; then
							logme "--sources" "### Copying $SHORTPKG ($SIZEPKGTMP B)... DONE!"
						else
							logme "--sources" "### Copying $SHORTPKG ($SIZEPKG kB)... DONE!"
						fi
						BSWAP=0
						BSPATH=`cat $CDIR/CHECKSUMS.sources 2>/dev/null | grep "/$1" | sed s/$1// | awk '{print$3}'`
						BSLIST=`cat $CDIR/CHECKSUMS.sources 2>/dev/null | grep $BSPATH | grep -i build | awk '{print$3}' | sed s/.//`
						BUILDSLIST="$BSLIST"
                                                for b in $BUILDSLIST
                                                do
                                                  if test $BSWAP -eq 0; then
                                                    echo -n "### Copying Build Script for $SHORTPKG... "
                                                    BSWAP=1
                                                  fi
                                                  copy_file "$RR" "$b"
                                                  BFILENAME=`echo $b | sed -e "s/.*\///g"`
                                                  mv $CDIR/$BFILENAME $CDIR/sources/$SHORTPKG-$BFILENAME 2>/dev/null
                                                done
						    					   if test $BSWAP -eq 1; then
                                                                                          	echo "DONE!"
												logme "--sources" "### Copying Build Script for $SHORTPKG... DONE!"
											   fi
                                                checksum_source $1 "$GETPKG"
						mv $1 $CDIR/sources/ 2>/dev/null
                                                DONE=0
						break
                                        else
                                                echo "FAILED!"
						if test $SIZEPKG -eq 0; then
							logme "--sources" "### Copying $SHORTPKG ($SIZEPKGTMP B)... FAILED!"
						else
							logme "--sources" "### Copying $SHORTPKG ($SIZEPKG kB)... FAILED!"	
						fi
                                        fi
                                  else
					SIZEPKGTMP=`cat CHECKSUMS.sources 2>/dev/null | grep "$GETPKG" | grep "/$1" | awk '{print$2}'`
					SIZEPKG=`echo $SIZEPKGTMP / 1024 | bc`
					if test $SIZEPKG -eq 0; then
                                        	MSG "--sources" "### Copying $SHORTPKG ($SIZEPKGTMP B)... FAILED!"
					else
						MSG "--sources" "### Copying $SHORTPKG ($SIZEPKG kB)... FAILED!"
					fi
                                  fi
			      else
                                        SWAPME=0
                			SIZEPKGTMP=`cat CHECKSUMS.sources 2>/dev/null | grep "$GETPKG" | grep "/$1" | awk '{print$2}'`
                			SIZEPKG=`echo $SIZEPKGTMP / 1024 | bc`
					if test $SIZEPKG -eq 0; then
                                        	MSG "--sources" "Source $SHORTPKG ($SIZEPKGTMP B) found in $CDIR!"
					else
						MSG "--sources" "Source $SHORTPKG ($SIZEPKG kB) found in $CDIR!"
					fi
					res_local_sources $1 "$GETPKG"
                              fi
			  done
                        }
                                                get_pkg()
                                                {
                                                     if [ -f $i ]; then
                                                          SIZEPKGTMP=`ls -alL $i 2>/dev/null | awk '{print$5}'`
                                                          SIZEPKG=`echo $SIZEPKGTMP / 1024 | bc`
							  if test $SIZEPKG -eq 0; then
                                                          	MSG "--sources" "Source $SHORTPKG ($SIZEPKGTMP B) found in $CDIR!"
							  else
								MSG "--sources" "Source $SHORTPKG ($SIZEPKG kB) found in $CDIR!"
							  fi
							  check_for_broken_sources $i 1 "" "$GETPKG"
							  mv $i $CDIR/sources/ 2>/dev/null
                                                     else
                                                      if [ ! -f $i ]; then
                                                       PACKAGES_URL=`cat URL 2>/dev/null | awk '{ if(NR == '$1') print $1 }'`
                      				       SIZEPKGTMP=`cat CHECKSUMS.sources 2>/dev/null | grep "$GETPKG" | grep "/$i" | awk '{print$2}'`
                                                       SIZEPKG=`echo $SIZEPKGTMP / 1024 | bc`
                                                       if [ ! -z $PACKAGES_URL ]; then
                                                        MSG "--sources" "[ $PACKAGES_URL ]"
							if test $SIZEPKG -eq 0; then
                                                        	echo $QS "### Fetching $SHORTPKG ($SIZEPKGTMP B)... "
							else
								echo $QS "### Fetching $SHORTPKG ($SIZEPKG kB)... "
							fi
                                                        if test `echo $PACKAGES_URL | grep rsync | wc -l` -ge 1
                                                        then
                                                                if [ ! -z $Q ]; then
									rsync_file "$PACKAGES_URL" "$GETPKG"
                                                                        count_sources_size_rsync $i $2 "$GETPKG"

                                                                else
									rsync_file_s "$PACKAGES_URL" "$GETPKG"
									touch_it "$i"
                                                                fi
                                                        else
                                                                if [ ! -z $Q ]; then
								echo "$PACKAGES_URL $GETPKG"
									wget_file "$PACKAGES_URL" "$GETPKG"
                                                                        count_sources_size $i $2 "$GETPKG"
                                                                else
									wget_file_s "$PACKAGES_URL" "$GETPKG"
									touch_it "$i"
                                                                fi
                                                        fi

                                                        if [ -f $i.tmp ]; then
                                                                FPKGSW=1
                                                                FPKGTSIZE=`echo "$FPKGTSIZE + $SIZEPKG" | bc`
                                                                FPKGC=`echo "$FPKGC + 1" | bc`
                                                                if [ ! -z $Q ]; then
                                                                        echo " DONE!"
								else
									echo
								fi
								if test $SIZEPKG -eq 0; then
									logme "--sources" "### Fetching $SHORTPKG ($SIZEPKGTMP B)... DONE!"
								else
									logme "--sources" "### Fetching $SHORTPKG ($SIZEPKG kB)... DONE!"
								fi
									BSWAP=0
									if test `echo $PACKAGES_URL | grep rsync | wc -l` -ge 1
									then
										BSPATH=`cat $CDIR/CHECKSUMS.sources 2>/dev/null | grep "/$i" | sed s/$i// | awk '{print$3}'`
										BSLIST=`cat $CDIR/CHECKSUMS.sources 2>/dev/null | grep $BSPATH | grep -i build | awk '{print$3}' | sed s/.//`
										BUILDSLIST="$BSLIST"
                                                for b in $BUILDSLIST
                                                do
                                                  if test $BSWAP -eq 0; then
                                                    echo -n "### Fetching Build Script for $SHORTPKG... "
                                                    BSWAP=1
                                                  fi
                                                  rsync_file_buildscript "$PACKAGES_URL" "$b"
                                                  BFILENAME=`echo $b | sed -e "s/.*\///g"`
                                                  mv $CDIR/$BFILENAME $CDIR/sources/$SHORTPKG-$BFILENAME 2>/dev/null
                                                done
											    if test $BSWAP -eq 1; then
												if [ ! -z $Q ]; then
                                                                                            		echo "DONE!"
												fi
												logme "--sources" "### Fetching Build Script for $SHORTPKG... DONE!"
											    fi
									else
										BSPATH=`cat $CDIR/CHECKSUMS.sources 2>/dev/null | grep "/$i" | sed s/$i// | awk '{print$3}'`
										BSLIST=`cat $CDIR/CHECKSUMS.sources 2>/dev/null | grep $BSPATH | grep -i build | awk '{print$3}' | sed s/.//`
										BUILDSLIST="$BSLIST"
                                                for b in $BUILDSLIST
						do
                                                  if test $BSWAP -eq 0; then
					 	    echo -n "### Fetching Build Script for $SHORTPKG... "
						    BSWAP=1
					          fi
					          wget_file_buildscript "$PACKAGES_URL" "$b"
                                                  BFILENAME=`echo $b | sed -e "s/.*\///g"`
                                                  mv $CDIR/$BFILENAME $CDIR/sources/$SHORTPKG-$BFILENAME 2>/dev/null
						done
											    if test $BSWAP -eq 1; then
												if [ ! -z $Q ]; then
                                                                                            		echo "DONE!"
												fi
												logme "--sources" "### Fetching Build Script for $SHORTPKG... DONE!"
											    fi
									fi
                                                                rm -f $i.tmp
                                                                checksum_source $i "$GETPKG"
								mv $i $CDIR/sources/ 2>/dev/null
                                                                DONE=0
                                                        else
                                                                if [ ! -z $Q ]; then
                                                                        echo " FAILED!"
                                                                fi
                                                                if test $SIZEPKG -eq 0; then
                                                                logme "--sources" "### Fetching $SHORTPKG ($SIZEPKGTMP B)... FAILED!"
                                                                else
                                                                logme "--sources" "### Fetching $SHORTPKG ($SIZEPKG kB)... FAILED!"
                                                                fi
                                                                rm -f $i.tmp
                                                                RECORDS=`cat URL 2>/dev/null | wc -l`
                                                                COUNTER=`expr $COUNTER + 1`
                                                                if test $COUNTER -ne `expr $RECORDS + 1`
                                                                then
                                                                    get_pkg $COUNTER $2
                                                                fi
                                                                DONE=0
                                                        fi
						       fi
                                                      fi
                                                     fi
                                                }

                                                if test $DONE -eq 1
                                                then
						  if test `cat /etc/swaret.conf | grep -v "#" | grep "^ROOT=" | grep "file:" | wc -l` -ge 1; then
							copy_pkg "$i" "$3" "$3"
						  else
                                                        if [ -z "$3" ]; then
                                                                get_pkg 1 "-a"
                                                        else
                                                                get_pkg 1 $3
                                                        fi
						  fi
                                                fi
                                                COUNTER=1
                                                DONE=1
					  else
                                                SHORTPKG=`echo $i | sed s/'.tar.gz'//`
                                                SHORTPKG=`echo $SHORTPKG | sed s/'.gz'//`
                                                SHORTPKG=`echo $SHORTPKG | sed s/'.tar.bz2'//`
                                                SHORTPKG=`echo $SHORTPKG | sed s/'.bz2'//`
                                                SIZEPKGTMP=`ls -alL $CDIR/sources/$i 2>/dev/null | awk '{print$5}'`
                                                SIZEPKG=`echo $SIZEPKGTMP / 1024 | bc`
						if test $SIZEPKG -eq 0; then
							MSG "--sources" "Source $SHORTPKG ($SIZEPKGTMP B) found in $CDIR/sources!"
						else
							MSG "--sources" "Source $SHORTPKG ($SIZEPKG kB) found in $CDIR/sources!"
						fi
					  fi
                                        done
                                        ;;
                                "n")
                                        QSWAP=0
                                        for i in $PKGLIST
                                        do
                                                SHORTPKG=`echo $i | sed s/'.tar.gz'//`
                                                SHORTPKG=`echo $SHORTPKG | sed s/'.gz'//`
                                                SHORTPKG=`echo $SHORTPKG | sed s/'.tar.bz2'//`
                                                SHORTPKG=`echo $SHORTPKG | sed s/'.bz2'//`
						SOURCEPKG="$SHORTPKG"
                                                GETPKG=`cat CHECKSUMS.sources 2>/dev/null | awk '{print$3}' | grep "/" | sed s/'.\/'// | grep "/$i"`
					  if [ ! -f $CDIR/sources/$i ]; then
                                                if [ ! -f $SHORTPKG.tmp ]; then
							if test `cat /etc/swaret.conf | grep -v "#" | grep "^ROOT=" | grep "file:" | wc -l` -ge 1; then
                                                        	echo -n "Copy $SHORTPKG? (y/n): [y]"
							else
								echo -n "Download $SHORTPKG? (y/n): [y]"	
							fi
                                                        read answer
                                                        if [ -z "$answer" ]; then
                                                                answer="y"
                                                        else
                                                                if [[ $answer != "y" ]]; then
                                                                        answer="n"
                                                                fi
                                                        fi
							if test `cat /etc/swaret.conf | grep -v "#" | grep "^ROOT=" | grep "file:" | wc -l` -ge 1; then
                                                        	logme "--sources" "Copy $SHORTPKG? (y/n): [$answer]"
							else
								logme "--sources" "Download $SHORTPKG? (y/n): [$answer]"	
							fi
                                                        case $answer in
                                                                "y")
                                                                        QSWAP=1
                                                                        echo $i >> DOWNLOADPKGSLIST.list 2>/dev/null
                                                                        ;;
                                                                "n")
                                                                        ;;
                                                                *)
									invalid_charz
                                                                        ;;
                                                        esac
                                                fi
					  else
                                                SHORTPKG=`echo $i | sed s/'.tar.gz'//`
                                                SHORTPKG=`echo $SHORTPKG | sed s/'.gz'//`
                                                SHORTPKG=`echo $SHORTPKG | sed s/'.tar.bz2'//`
                                                SHORTPKG=`echo $SHORTPKG | sed s/'.bz2'//`
                                                SIZEPKGTMP=`ls -alL $CDIR/sources/$i 2>/dev/null | awk '{print$5}'`
                                                SIZEPKG=`echo $SIZEPKGTMP / 1024 | bc`
						if test $SIZEPKG -eq 0; then
							MSG "--sources" "Source $SHORTPKG ($SIZEPKGTMP B) found in $CDIR/sources!"
						else
							MSG "--sources" "Source $SHORTPKG ($SIZEPKG kB) found in $CDIR/sources!"
						fi
					  fi
                                        done
                                        if test $QSWAP -eq 1; then
                                                echo
                                        fi
                                        if [ -f DOWNLOADPKGSLIST.list ]; then
                                                PKGSLIST=`cat DOWNLOADPKGSLIST.list 2>/dev/null`
                                                DONE=1
                                                COUNTER=1
                                                SWAPME=0
                                                for Z in $PKGSLIST
                                                do
                                                        SHORTPKG=`echo $Z | sed s/'.tar.gz'//`
                                                        SHORTPKG=`echo $SHORTPKG | sed s/'.gz'//`
                                                        SHORTPKG=`echo $SHORTPKG | sed s/'.tar.bz2'//`
                                                        SHORTPKG=`echo $SHORTPKG | sed s/'.bz2'//`
                           				GETPKG=`cat CHECKSUMS.sources | awk '{print$3}' | grep "/" | sed s/'.\/'// | grep "/$Z"`
                        copy_pkg()
                        {
			  ROOTS=`cat /etc/swaret.conf | grep -v "#" | grep "^ROOT=" | grep "file:" | cut -f2 -d'=' | sed s/'file:'//`
			  for RR in $ROOTS
			  do
                              SHORTPKG=`echo "$1" | sed s/'.tar.gz'//`
                              SHORTPKG=`echo $SHORTPKG | sed s/'.gz'//`
                              SHORTPKG=`echo $SHORTPKG | sed s/'.tar.bz2'//`
                              SHORTPKG=`echo $SHORTPKG | sed s/'.bz2'//`
                              if [ ! -f $1 ]; then
                                  SWAPME=0
                                  PACKAGE=`cat CHECKSUMS.sources 2>/dev/null | grep "$GETPKG" | grep "/$1" | awk '{print$3}' | grep "/" | sed s/'.\/'//`
                                  if [ ! -z $RR ]; then
                                        SIZEPKGTMP=`cat CHECKSUMS.sources 2>/dev/null | grep "$GETPKG" | grep "/$1" | awk '{print$2}'`
                                        SIZEPKG=`echo $SIZEPKGTMP / 1024 | bc`
                                        MSG "--install" "[ file:$RR ]"
					if test $SIZEPKG -eq 0; then
						echo -n "### Copying $SHORTPKG ($SIZEPKGTMP B)... "
					else
                                        	echo -n "### Copying $SHORTPKG ($SIZEPKG kB)... "
					fi
					copy_file "$RR" "$GETPKG"
                                        if [ -f $1 ]; then
                                                FPKGSW=1
                                                FPKGTSIZE=`echo "$FPKGTSIZE + $SIZEPKG" | bc` 
                                                FPKGC=`echo "$FPKGC + 1" | bc`
                                                echo "DONE!"
						if test $SIZEPKG -eq 0; then
							logme "--sources" "### Copying $SHORTPKG ($SIZEPKGTMP B)... DONE!"
						else
							logme "--sources" "### Copying $SHORTPKG ($SIZEPKG kB)... DONE!"
						fi
											    BSWAP=0
BSPATH=`cat $CDIR/CHECKSUMS.sources 2>/dev/null | grep "/$1" | sed s/$1// | awk '{print$3}'`
BSLIST=`cat $CDIR/CHECKSUMS.sources 2>/dev/null | grep $BSPATH | grep -i build | awk '{print$3}' | sed s/.//`
BUILDSLIST="$BSLIST"
                                                for b in $BUILDSLIST
                                                do
                                                  if test $BSWAP -eq 0; then
                                                    echo -n "### Copying Build Script for $SHORTPKG... "
                                                    BSWAP=1
                                                  fi
                                                  copy_file "$RR" "$b"
                                                  BFILENAME=`echo $b | sed -e "s/.*\///g"`
                                                  mv $CDIR/$BFILENAME $CDIR/sources/$SHORTPKG-$BFILENAME 2>/dev/null
                                                done
											    if test $BSWAP -eq 1; then
                                                                                            	echo "DONE!"
												logme "--sources" "### Copying Build Script for $SHORTPKG... DONE!"
											    fi
                                                checksum_source $1 "$GETPKG"
						mv $1 $CDIR/sources/ 2>/dev/null
                                                DONE=0
						break
                                        else
                                                echo "FAILED!"
						if test $SIZEPKG -eq 0; then
                                                	logme "--sources" "### Copying $SHORTPKG ($SIZEPKGTMP B)... FAILED!"
						else
							logme "--sources" "### Copying $SHORTPKG ($SIZEPKG kB)... FAILED!"
						fi
                                        fi
                                  else
                                        SIZEPKGTMP=`cat CHECKSUMS.sources 2>/dev/null | grep "$GETPKG" | grep "/$1" | awk '{print$2}'`
                                        SIZEPKG=`echo $SIZEPKGTMP / 1024 | bc`
					if test $SIZEPKG -eq 0; then
                                        	MSG "--sources" "### Copying $SHORTPKG ($SIZEPKGTMP B)... FAILED!"
					else
						MSG "--sources" "### Copying $SHORTPKG ($SIZEPKG kB)... FAILED!"
					fi
                                  fi
			      fi
			  done
                        }
                                                        get_pkg()
                                                        {
                                                                if [ -f $Z ]; then
                                                                        SIZEPKGTMP=`ls -alL $Z 2>/dev/null | awk '{print$5}'`
                                                                        SIZEPKG=`echo $SIZEPKGTMP / 1024 | bc`
									if test $SIZEPKG -eq 0; then
                                                                        	MSG "--sources" "Source $SHORTPKG ($SIZEPKGTMP B) found in $CDIR!"
									else
										MSG "--sources" "Source $SHORTPKG ($SIZEPKG kB) found in $CDIR!"
									fi
									check_for_broken_sources $Z 1 "" "$GETPKG"
									mv $Z $CDIR/sources/ 2>/dev/null
                                                                else
                                                                    PACKAGES_URL=`cat URL 2>/dev/null | awk '{ if(NR == '$1') print $1 }'`
                                                                    SIZEPKGTMP=`cat CHECKSUMS.sources 2>/dev/null | grep "$GETPKG" | grep "$Z" | awk '{print$2}'`
                                                                    SIZEPKG=`echo $SIZEPKGTMP / 1024 | bc`
                                                                    if [ ! -z $PACKAGES_URL ]; then
                                                                        MSG "--sources" "[ $PACKAGES_URL ]"
									if test $SIZEPKG -eq 0; then
                                                                        	echo $QS "### Fetching $SHORTPKG ($SIZEPKGTMP B)... "
									else
										echo $QS "### Fetching $SHORTPKG ($SIZEPKG kB)... "
									fi
                                                                        if test `echo $PACKAGES_URL | grep rsync | wc -l` -ge 1
                                                                        then
                                                                                    if [ ! -z $Q ]; then
											    rsync_file "$PACKAGES_URL" "$GETPKG"
                                                                                            count_sources_size_rsync $Z $2 "$GETPKG"
                                                                                    else
											    rsync_file_s "$PACKAGES_URL" "$GETPKG"
											    touch_it "$Z"
                                                                                    fi
                                                                        else
                                                                                    if [ ! -z $Q ]; then
											    wget_file "$PACKAGES_URL" "$GETPKG"
                                                                                            count_sources_size $Z $2 "$GETPKG"
                                                                                    else
											    wget_file_s "$PACKAGES_URL" "$GETPKG"
											    touch_it "$Z"
                                                                                    fi
                                                                        fi
                                                                        if [ -f $Z.tmp ]; then
                                                                                FPKGSW=1
                                                                                FPKGTSIZE=`echo "$FPKGTSIZE + $SIZEPKG" | bc`
                                                                                FPKGC=`echo "$FPKGC + 1" | bc`
                                                                                if [ ! -z $Q ]; then
                                                                                        echo " DONE!"
										else
											echo
										fi
										if test $SIZEPKG -eq 0; then
                                                                                	logme "--sources" "### Fetching $SHORTPKG ($SIZEPKGTMP B)... DONE!"
										else
											logme "--sources" "### Fetching $SHORTPKG ($SIZEPKG kB)... DONE!"
										fi
											BSWAP=0
											if test `echo $PACKAGES_URL | grep rsync | wc -l` -ge 1
											then
BSPATH=`cat $CDIR/CHECKSUMS.sources 2>/dev/null | grep "/$i" | sed s/$i// | awk '{print$3}'`
BSLIST=`cat $CDIR/CHECKSUMS.sources 2>/dev/null | grep $BSPATH | grep -i build | awk '{print$3}' | sed s/.//`
BUILDSLIST="$BSLIST"
                                                for b in $BUILDSLIST
                                                do
                                                  if test $BSWAP -eq 0; then
                                                    echo -n "### Fetching Build Script for $SHORTPKG... "
                                                    BSWAP=1
                                                  fi
                                                  rsync_file_buildscript "$PACKAGES_URL" "$b"
                                                  BFILENAME=`echo $b | sed -e "s/.*\///g"`
                                                  mv $CDIR/$BFILENAME $CDIR/sources/$SHORTPKG-$BFILENAME 2>/dev/null
                                                done
											    if test $BSWAP -eq 1; then
												if [ ! -z $Q ]; then
                                                                                            		echo "DONE!"
												fi
                                                                                		logme "--sources" "### Fetching Build Script for $SHORTPKG... DONE!"
											    fi
											else
BSPATH=`cat $CDIR/CHECKSUMS.sources 2>/dev/null | grep "/$i" | sed s/$i// | awk '{print$3}'`
BSLIST=`cat $CDIR/CHECKSUMS.sources 2>/dev/null | grep $BSPATH | grep -i build | awk '{print$3}' | sed s/.//`
BUILDSLIST="$BSLIST"
                                                for b in $BUILDSLIST
                                                do
                                                  if test $BSWAP -eq 0; then
                                                    echo -n "### Fetching Build Script for $SHORTPKG... "
                                                    BSWAP=1
                                                  fi
                                                  wget_file_buildscript "$PACKAGES_URL" "$b"
                                                  BFILENAME=`echo $b | sed -e "s/.*\///g"`
                                                  mv $CDIR/$BFILENAME $CDIR/sources/$SHORTPKG-$BFILENAME 2>/dev/null
                                                done
											    if test $BSWAP -eq 1; then
												if [ ! -z $Q ]; then
                                                                                            		echo "DONE!"
												fi
                                                                                		logme "--sources" "### Fetching Build Script for $SHORTPKG... DONE!"
											    fi
											fi
                                                                                rm -f $Z.tmp
                                                                                SWAPME=0
										mv $Z $CDIR/sources/ 2>/dev/null
                                                                                DONE=0
                                                                        fi
                                                                    fi
                                                                fi
                                                        }
                                                        if test $DONE -eq 1
                                                        then
                                                          if test `cat /etc/swaret.conf | grep -v "#" | grep "^ROOT=" | grep "file:" | wc -l` -ge 1; then
                                                            	copy_pkg "$Z" "$3" "$3"
						          else
                                                                if [ -z "$3" ]; then
                                                                        get_pkg 1 "-a"
                                                                else
                                                                        get_pkg 1 $3
                                                                fi
							  fi
                                                        fi
                                                        DONE=1
                                                        COUNTER=1
                                        	done
					fi
                                        ;;
                        esac
                        if test $FPKGSW -eq 1
                        then
                                if test $FPKGC -ge 1
                                then
				    if test `cat /etc/swaret.conf | grep -v "#" | grep "^ROOT=" | grep "file:" | wc -l` -ge 1; then
                                        if test $FPKGC -eq 1
                                        then
                                                MSG "--sources" "Copied $FPKGC File with a Size of $FPKGTSIZE kB!"
                                        else
                                                MSG "--sources" "Copied $FPKGC Files with a Total Size of $FPKGTSIZE kB!"
                                        fi
				    else
                                        if test $FPKGC -eq 1
                                        then
                                                MSG "--sources" "Downloaded $FPKGC File with a Size of $FPKGTSIZE kB!"
                                        else
                                                MSG "--sources" "Downloaded $FPKGC Files with a Total Size of $FPKGTSIZE kB!"
                                        fi
				    fi
                                fi
                        fi
			if [[ "$INFORMATION" == "1" ]]; then
				echo
				echo "INFORMATION: Sources are saved in $CDIR/sources!"
				if [ ! -z $5 ]; then
					echo
				fi
			fi
                        if [ -z $5 ]; then
                                echo
                        fi
                        ;;
        "--resume")
			function_resume "" "$2" "$3" "$4" "$5"
                        ;;
        "--re-all")
			echo

                        URL
                        copy_from_cache

                        swaret --resume "" "" "" 1
			echo
			echo
                        swaret --resume -p "" "" 1
                        echo
                        echo
                        swaret --resume -e "" "" 1
                        echo
                        echo
                        swaret --resume -s "" "" 1
			echo
			;;
	"--dep")
                        echo

			URL
                        copy_from_cache

			if [ -z $2 ]; then
				echo -n "=> Creating a List... "
				FILES=`ls $PACKAGES_LOGDIR/* 2>/dev/null`
				for i in $FILES
				do
					FILE=`basename $i`
					cat $PACKAGES_LOGDIR/$FILE 2>/dev/null | grep bin/ | sed -e 's/.*/'$FILE':&/' >> $CDIR/TARFILES.tmp
				done
			else
			  if [[ "$2" == "-A" ]]; then
                                echo -n "=> Creating a List... "
                                FILES=`ls $PACKAGES_LOGDIR/* 2>/dev/null`
                                for i in $FILES
                                do
                                        FILE=`basename $i`
                                        cat $PACKAGES_LOGDIR/$FILE 2>/dev/null | grep bin/ | sed -e 's/.*/'$FILE':&/' >> $CDIR/TARFILES.tmp
                                done
			  else
				echo -n "=> Creating a List matching Keyword: $2... "
				FILES=`ls $PACKAGES_LOGDIR/$2* 2>/dev/null`
				for i in $FILES
				do
					FILE=`basename $i`
		 			cat $PACKAGES_LOGDIR/$FILE 2>/dev/null | grep bin/ | sed -e 's/.*/'$FILE':&/' >> $CDIR/TARFILES.tmp
				done
			  fi
			fi
			echo "DONE!"
			echo
                        if [[ "$2" == "-A" ]] || [[ "$3" == "-A" ]]; then
				dependency_check
			else
                                dependency_interactive_check
                        fi
			;;
        "--show")
                        echo

                        if [ -z "$2" ]; then
                                MSGERR "--search" "Please, provide a Keyword to Show!"
                        fi
                        export GO=0
                        echo "$2" | grep -q '^[[:alpha:]]\+' && export GO=1
                        if test $GO -eq 0
                        then
                                invalid_charz
                        fi

                        if test `ls $PACKAGES_LOGDIR/$2* 2>/dev/null | wc -l` -eq 0; then
                                MSGERR "--show" "No installed Packages/Patches/Extra Packages found matching Keyword: $2!"
                        else
				z=0
				xCOUNTER=0
				zCOUNTER=0
                                for i in `ls $PACKAGES_LOGDIR/$2* 2>/dev/null | sed -e "s/.*\///g"`
                                do
					xCOUNTER=`expr $xCOUNTER + 1`
				done
                                for i in `ls $PACKAGES_LOGDIR/$2* 2>/dev/null | sed -e "s/.*\///g"`
                                do
					SHORTPKG=`echo $i | sed -e s/-[0-9].*//`
					echo "Description for $i:"
					echo "----------------------------------------------------------------------"
					if test `cat $PACKAGES_LOGDIR/$i* 2>/dev/null | grep "$SHORTPKG:" | wc -l` -eq 0; then
						echo "No Description found for $i!"
					else	
						cat $PACKAGES_LOGDIR/$i* 2>/dev/null | grep "$SHORTPKG: " | sed s/$SHORTPKG': '// | awk '{if(NR != 1) print $0}'
					fi
					echo "----------------------------------------------------------------------"	
                                        zCOUNTER=`expr $zCOUNTER + 1`
                                        if [[ "$zCOUNTER" != "$xCOUNTER" ]]; then
						echo
						echo -n "Press ENTER Key to view the next Description..."
						read
						echo
					else
						echo 
					fi
                                done
                        fi
			;;
        "--clean")
			echo
                        cleanup
                        MSG "--clean" "Cleanup DONE!"
                        ;;
        "--clear")
                        echo
			rm -f $LF 2>/dev/null	
			touch $LF 2>/dev/null
			MSGERR "--clear -l" "swaret Log File has been cleared!"
                        ;;
	"--log")
			log $2
			;;
	"--pgp")
			cd $USERPWD/
			echo
			echo -n "=> Importing PGP Key... "
			if [ -f $3 ]; then
				gpg --import $3 2>/dev/null
				echo "DONE!"
			else
				echo "FAILED!"
			fi
			echo
			;;
	*)
			help
                        ;;
esac
