Download packages via apt without root privlidges

I'm working on a script to show differences between config files on a system and those provided in the original package. I have pretty much all of it working, except for using apt to download packages without being root. Is there a simple way to do this?


Edit: I've looked into the 'hacky' wget scripting type options, but the main issue I have is how you would determine which repo to attempt to get the package from. It's not included in any apt-cache output that I can see.


Solution 1:

Simply aptitude download it:

$ ls vim*.deb
ls: vim*.deb: No such file or directory

$ aptitude download vim
[...]
Fetched 835kB in 0s (2933kB/s)

$ ls vim*.deb
vim_1%3a7.0-122+1etch5_amd64.deb

$ id
uid=1000(earl) gid=100(users) groups=100(users)

Solution 2:

You could set up passwordless sudo for aptitude --download-only? Or you could parse the output of various apt commands and manually download the file from there. There are 3rd party libraries for dealing with libapt, like python-apt