The simple approach
If you are using another machine, one which is connected to the internet, to upgrade your target computer, you can simply use the same sources.list
file on the two machines, run apt-get update
and then copy the package lists over:
$ sudo mv /etc/apt/sources.list /etc/apt/sources.list.orig
$ sudo mv target_computer_sources.list /etc/apt/sources.list
$ sudo apt-get update
apt
stores its repository file lists in /var/lib/apt/lists/
, so afer running the command above, you cam copy everything in /var/lib/apt/lists/
to the target machine and then revert to the original sources.list
:
$ sudo mv /etc/apt/sources.list.orig /etc/apt/sources.list
The complex way
I for whatever reason the method above does not work for you, you can do it the way you were suggesting, you just need to parse the output of apt-get update --print-uris
. The following are from my LMDE system but the idea is the same:
$ sudo apt-get update --print-uris -y | head
'ftp://ftp.debian.org/debian/dists/testing/main/source/Sources.bz2' ftp.debian.org_debian_dists_testing_main_source_Sources 0 :
'ftp://ftp.debian.org/debian/dists/testing/contrib/source/Sources.bz2' ftp.debian.org_debian_dists_testing_contrib_source_Sources 0 :
'ftp://ftp.debian.org/debian/dists/testing/non-free/source/Sources.bz2' ftp.debian.org_debian_dists_testing_non-free_source_Sources 0 :
'ftp://ftp.debian.org/debian/dists/testing/InRelease' ftp.debian.org_debian_dists_testing_InRelease 0
'http://packages.linuxmint.com/dists/debian/main/source/Sources.bz2' packages.linuxmint.com_dists_debian_main_source_Sources 0 :
'http://packages.linuxmint.com/dists/debian/upstream/source/Sources.bz2' packages.linuxmint.com_dists_debian_upstream_source_Sources 0 :
'http://packages.linuxmint.com/dists/debian/import/source/Sources.bz2' packages.linuxmint.com_dists_debian_import_source_Sources 0 :
'http://packages.linuxmint.com/dists/debian/main/binary-amd64/Packages.bz2' packages.linuxmint.com_dists_debian_main_binary-amd64_Packages 0 :
'http://packages.linuxmint.com/dists/debian/upstream/binary-amd64/Packages.bz2' packages.linuxmint.com_dists_debian_upstream_binary-amd64_Packages 0 :
'http://packages.linuxmint.com/dists/debian/import/binary-amd64/Packages.bz2' packages.linuxmint.com_dists_debian_import_binary-amd64_Packages 0 :
In the output above, the 1st field is the URL and the 2nd is the name the file will be saved under. As I mentioned before, apt
stores its repository file lists in /var/lib/apt/lists/
, you can verify this by running locate
on one of the 2nd fields above:
$ locate packages.linuxmint.com_dists_debian_main_source_Sources
/var/lib/apt/lists/packages.linuxmint.com_dists_debian_main_source_Sources
So, if you want to download and update each of those lists, you will need to parse the output of apt-get update --print-uris
and tell wget
to use the 2nd field as the output name:
$ sudo apt-get update --print-uris -y | sed "s/'//g" | cut -d ' ' -f 1,2 |
while read url target; do wget $url -O ./$target; done
This will download each package list and save it in the current directory using the appropriate name. You can now copy these files over to the /var/lib/apt/lists/
directory of the target machine.
Best Answer
If you already have a list of URLs, just add the POST data to that list. Something like:
Then, instead of using
-i
, read the file in a bash loop and pass the data to wget:To run them in parallel so that multiple files are downloaded at the same time, use
&
instead of;
. Careful though, this will launch a separatewget
process for each URL.One trick I use for launching this type of thing is keeping track of how many are currently running and only running the next one if the number is below a threshold, 10 for example:
That will launch the first 10 URLs, then wait for one to finish and launch the next.