#########################################################################
#
# Subroutine for the 'clean' command
#
#########################################################################
#
# Copyright Rainer Wichmann (2005)
#
# License Information:
# 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.
#

commandCLEAN() {
    printINFO "About to run \"$action\""

    cd "${basedir}/source" || printFATAL "could not cd to ${basedir}/source"

    LIST=`ls samhain*.tar.gz 2>/dev/null`
    if test x$? != x0
    then
	printINFO "No sources available."
    fi

    for ff in $LIST
    do
	sh_version=`echo "$ff" | sed 's/.*samhain\-//g' | sed 's/\.tar\.gz//g'`
	if test x"${sh_version}" = x
	then
	    printFATAL "Cannot determine version for $ff"
	fi

	if test "$ff" != "samhain-${sh_version}.tar.gz"
	then
	    printFATAL "Version number not correctly extracted from $ff"
        fi

	if test -f "samhain-${sh_version}.tar.gz.asc"
	then
	    printINFO "REMOVE samhain-${sh_version}.tar.gz.asc"
	    if test x"$simulate" = x0
	    then
	        rm -f "samhain-${sh_version}.tar.gz.asc"
	    else
	        printINFO "rm -f samhain-${sh_version}.tar.gz.asc"
	    fi
        fi

	if test -f "samhain-${sh_version}.tar.gz"
	then
	    printINFO "REMOVE samhain-${sh_version}.tar.gz"
	    if test x"$simulate" = x0
	    then
	        rm -f "samhain-${sh_version}.tar.gz"
	    else
	        printINFO "rm -f samhain-${sh_version}.tar.gz"
	    fi
        fi
    done
	      
    printLOG "Cleaned sources in ${basedir}/source/"

    dbSHOWPKG dontshow delete
 
    printLOG "Cleaned unused packages in ${basedir}/archpkg/"

    return 0
}
