Monday, May 6, 2024
 Popular · Latest · Hot · Upcoming
1
rated 0 times [  1] [ 0]  / answers: 1 / hits: 1375  / 3 Years ago, fri, may 21, 2021, 4:57:27

The following is no duplicate of How to determine the size of a package while using apt prior to downloading?, it is more an additional question.



Consider the following two implementations to get the required disk space:



#!/bin/bash
echo n | sudo apt-get install $LIST | grep "disk space" | awk '{ print $4, $5 }'


and



#!/bin/bash

PACKAGE_LIST=$(dpkg --get-selections | awk '{ print $1 }' | grep -v -e "-dbg" | cut -f1 -d":")

getsize () {
size=$(apt-cache --no-all-versions show $1 | grep Installed-Size | awk '{ print $2 }')
((NEEDED+=$size))
}

for package in $LIST; do
getsize $package
DEPENDENCIES=$(apt-cache depends $package | grep Depends | awk '{ print $2 }')
for dependency in $DEPENDENCIES; do
if [[ ! $PACKAGE_LIST =~ [^.[:alnum:]-]"$dependency"[^.[:alnum:]-] ]]; then
getsize $dependency
fi
done
done

echo "$NEEDED kb"


In theory they should return similar results, but for big packages in $LIST they return very different results, the second implementation returns much bigger results (for example 13.5 GB vs 16.2 GB).
I know the second implementation is slower, because it tries to do the job of apt-get in bash, which is a lot slower, but my intention of writing the second version was to get the result in kb, because I was not able to find out how to get the result in kb from the first implementation, mainly because apt-get scales the unit, from bytes up to gigabytes and I do not know, whats the biggest unit it considers.



Could someone help me find out why there is such a big difference?


More From » apt

 Answers
6

The first seems to be accurate.



The second one looks like it might be considering the size of all the dependencies instead of the needed dependencies.



apt-cache depends


brings up all dependencies.



Example:



If I were to install "potrace" I would only need "potrace" and "libpotrace0" but the list of dependencies from apt-cache depends also brings up "libc6" and "zlib1g" which are both already installed on my system.


[#23864] Sunday, May 23, 2021, 3 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
ticrew

Total Points: 190
Total Questions: 111
Total Answers: 99

Location: Fiji
Member since Wed, Jul 14, 2021
3 Years ago
;