Take the 2-minute tour ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

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.

share|improve this question
    
Can I ask the purpose behind this solution? Is it for security or a type of pseudo version control? If the latter is the goal have you considered something like puppet or cfengine? Based on some of your answers below I would guess some sort of consulting audits. –  Geek404 Aug 22 '09 at 7:29
    
There's no specific purpose, just the result of a converation I had last week, with a "hey, a script like that could be pretty handy" moment. –  theotherreceive Aug 22 '09 at 19:18

6 Answers 6

up vote 3 down vote accepted
+100

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)
share|improve this answer

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

share|improve this answer
    
I want it to be fairly portable, and especially since it doesn't need to do any root stuff i wouldn't want to give it sudo access. Hacky parsing is something i'll consider, but i'd rather find a better way if possible. –  theotherreceive Aug 18 '09 at 15:28

dget does exactly what you want. From the man page:

In the second form, dget downloads a binary package (i.e., a .deb file) from the Debian mirror configured in /etc/apt/sources.list(.d). Unlike apt-get install -d, it does not require root privileges, writes to the current directory, and does not download dependencies.

share|improve this answer

wget can be used to download packages to a user writable directory, which answers your question, unless you have a hidden requirement in your question to actually INSTALL the packages.

share|improve this answer
    
The problem with wget is that the script would have to work out the url of the package, which was one of the options Rory suggested. I'd like to avoid this approach if possible. There's no requirement to install the packages, I'd be most likely deleting them once they'd been diff'd. –  theotherreceive Aug 18 '09 at 16:26

Try using the underlying pkg_apt libraries? Although, they are likely to make your script somewhat more complex, and iirc, are in perl, so require you using that.

share|improve this answer
    
But, you know I don't like perl... –  theotherreceive Aug 18 '09 at 20:48

The locations of the repositories are in /etc/apt/sources.list and /etc/apt/sources.list.d/* so you could use those to work out the list of repositories. Then try all of them with wget for the location of the package. It is brute force but would work.

For example, this entry deb http: / / us.archive.ubuntu.com/ubuntu/ jaunty-updates multiverse becomes wget http://us.archive.ubuntu.com/ubuntu/jaunty-updates/multiverse/i386/packagename

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.