#!/bin/bash # # script "rpmsz" - RPM package size # GPL December 2003, Giles Orr (giles at dreaming dot org). # Please let me know about any modifications. # # The concept here is to find the size of the selected rpm packages. # # It's slow, but better than the previous version. Main slowness is # in the big "rpm -qa" call, which is unavoidable. # if [ "x$*" = "x" ] then echo "rpmsz RPM-package-name(s)" echo " \"RPM-package-name(s)\" is/are a glob pattern: no " echo " wildcard indicators allowed." echo "" echo " Example:" echo "" echo " rpmsz gnome kde" echo "" exit 1 fi allRpmFile="/tmp/$(basename ${0}).all.$$.txt" selectRpmFile="/tmp/$(basename ${0}).select.$$.txt" # Loop through command line items, and compile a list of matching RPMS rpm -q --queryformat "%{NAME}-%{VERSION}-%{RELEASE}-%{ARCH} %{SIZE}\n" --all > ${allRpmFile} let i=$# rpmlist="" while [ "$i" -ge "1" ] do grep -i ${1} ${allRpmFile} >> ${selectRpmFile} shift let i=${i}-1 done # Sort numerically by second field (size), in place (man page says okay): cat ${selectRpmFile} | sort -n -k 2,2 -o ${selectRpmFile} # Loop through the packages: list them and their size, and sum it up TotalSize=0 while read package packagesize do # Determine the length of the package name: let strLen=$(echo -n "${package}" | wc -c | tr -d " ") # Line the "size" up nicely: let fillsize=45-$strLen if [ "$fillsize" -lt "2" ] then fill=" " else fill="" while [ "$fillsize" -gt "0" ] do fill="${fill} " let fillsize=${fillsize}-1 done fi echo "${package}${fill}size (bytes) = ${packagesize}" let TotalSize=${TotalSize}+${packagesize} done < ${selectRpmFile} # Let'm know the total damage echo echo -e "Total size of packages: \t$(( $TotalSize / 1024 )) Kb" echo # Clean up and exit: rm ${allRpmFile} ${selectRpmFile} exit 0