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.
you could add a post process command to wipe out the empty directories created.
wget -np -nH --cut-dirs=X -c -N -r -l 0 \
-I /dir1,/dir2,...,/some_dir -A acclist \
http://hostname/X_sub_directories/ \
&& find -depth -type d -empty -exec rmdir {} \;
Best Answer
You can use
fuser
, orlsof
.The output looks like so: