#!/bin/sh

# informations on stderr
# obsoletes files on stdout, delete with "$0 | xargs rm"

cd /var/cache/apt/archives

total_size=0
for package in `ls -1 *deb | sed "s/_.*//" | sort -u`
do
        echo -n "Package '$package' : " > /dev/stderr
        apt-cache show $package | grep -q "W: Unable to locate package $package"
        if (test $? -eq 0)
        then
                echo " ERROR : apt-cache show doesn't know about it" > 
/dev/stderr
                continue
        fi
        apt-cache show $package | grep -q "Filename: "
        if (test $? -eq 1)
        then
                echo " ERROR : apt-cache show doesn't show the file name" > 
/dev/stderr
                continue
        fi
        installed_file=`apt-cache show $package | grep "Filename: " | sed 
"s/.*\/\([^/]\)/\1/"`
        echo $installed_file > /dev/stderr
        for file in `ls -1 $package\_*`
        do
                translated_file=`echo $file | sed "s/[0-9]%3a//"`
                if (test $translated_file != $installed_file)
                then
                        size=`stat $file | grep "Size:" | awk '{print $2}'`
                        echo "   Obsolete file $file ($size bytes)" > 
/dev/stderr
                        total_size=`echo "$total_size+$size" | bc`
                        echo $file
                fi
        done
done

total_size_mb=`echo "$total_size/1024^2" | bc`
echo "Total size of obsolete files : $total_size_mb MBytes" > /dev/null


Reply via email to