0

how to determine which packages from official Ubuntu repositories need to be updated (in respect to current state) and to download these packages Thanks.

Hey Denarsson, your script was very helpful thank you.

The command apt-get update -o Dir::Etc::sourcelist='sources.list' \ -o Dir::Etc::sourceparts='-' -o APT::Get::List-Cleanup='0' update the package lists from official Ubuntu repositories.

Yes it is fine but what equally I need first, before updating the data, is to see the list of packages (name of packages) from official Ubuntu repositories that need to be update and after that to confirm to update.

For example like this command : apt-get upgrade --show-upgraded that print out a list of all packages that are to be upgraded.

Output: The following packages will be upgraded:

apache2 apache2-mpm-prefork apache2-utils apache2.2-bin apache2.2-common apparmor apport apport-symptoms apt apt-transport-https apt-utils apt-xapian-index aptitude avahi-daemon cups-client cups-common cups-driver-gutenprint cups-filters cups-ppdc curl dbus dmsetup dnsutils dosfstools dovecot-core dovecot-imapd dovecot-pop3d dpkg file fontconfig-config …….

Or for example with sudo /usr/lib/update-notifier/update-motd-updates-available

Out for ex:

35 packages can be updated.

22 updates are security updates.

As output is the number of packages that can be updated but I need also to see the list of packages with the name for example.

So which combination of command do you think is appropriate to print first the list of packages need to be updated and after that to confirm to update that list?

Thank for your time.

1
  • I'm not sure i understand the question? Ubuntu regularly checks for new updates on its own, and will notify you to upgrade your packages to the newest version from the Ubuntu repositories. If you want the absolutely newest version of a package you will probably have to manually add that specific repo of the package.
    – asgerbj
    Feb 22, 2014 at 12:40

1 Answer 1

0

In the beginning, you'll want to update the package lists. You could simply use apt-get update, but since you only want the official sources, this would take unnecessarily long. To speed up things a bit, use the following:

apt-get update -o Dir::Etc::sourcelist='sources.list' \
-o Dir::Etc::sourceparts='-' -o APT::Get::List-Cleanup='0'

Now that your package lists are up to date, you have to get the URLs of the individual packages. The following code is borrowed from apt-fast, you might need to adjust it to your needs.

DLLIST="/tmp/packages.list"
# Add header to overwrite file:
echo "# package download list: $(date)" > "$DLLIST"
# We use --print-uris to get the uris of the packages instead of downloading them
for urimd5 in $(apt-get -y --print-uris upgrade |
    egrep "^'(http(s|)|(s|)ftp)://[^']+'.+ MD5Sum:\S+\s*$" |
    sed "s/^'\(.\+\)'.*MD5Sum:\(\S\+\)\s*$/\1::MD5Sum:\2/"); do
  uri="${urimd5%::MD5Sum:*}"
  checksum="${urimd5#*::MD5Sum:}"
  # Here we are checking if the package comes from the official sources,
  # only then it's written to the list:
  if [[ $uri == *ubuntu.com* ]]; then
    echo "$(get_mirrors "$uri")" >> "$DLLIST"
    echo " checksum=md5=$checksum" >> "$DLLIST"
    # Here you can specify where the files go.
    # Change path to the location where you want the packages to be downloaded.
    echo " out=/path/$(basename $uri)" >> "$DLLIST"
  fi
done

Now you have a list of the URLs to the package files you want to download at /tmp/packages.list. To download the packages, we use aria2c, which you can install from the default repositories by running sudo apt-get install aria2. Here we go:

aria2c -i $DLLIST

Just put the above together in your script. It will have to be run as root of course.

8
  • First thanks for your reply, I appreciate. Yes I need to create a script to determine which packages from official Ubuntu repositories need to be updated (in respect to current state) so I need the command to see which packages need to be updated and after that I need to download
    – user251077
    Feb 22, 2014 at 13:33
  • It would be helpful to know a bit more about what you're trying to achieve. What is the script supposed to do exactly? Is it important to only update packages from official repositories while leaving third-party applications untouched?
    – Donarsson
    Feb 22, 2014 at 13:36
  • The purpose of script is find which packages from only official Ubuntu repositories need to be updated (in respect to current state), and after getting it, to download them
    – user251077
    Feb 22, 2014 at 13:41
  • Should it just download the packages or install them aswell?
    – Donarsson
    Feb 22, 2014 at 13:49
  • Yes, it should just download the packages but not to install
    – user251077
    Feb 22, 2014 at 13:51

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .