#########################################################################
#
# Subroutine for the 'clean' command
#
#########################################################################

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
}
