7

I want to write a bash or perl script to install a number of packages on my debian based machine.

I want it to be something like :

aptitude install package1 
aptitude install package2

But, I do not know how how to automatically say "yes" through the script at the prompt to confirm you want to install that package. Can someone give me an example in perl and bash ?

gratz!

4 Answers 4

26

aptitude install -y package1 package2 package3

3
  • what happens when it needs extra libs ? Jul 31, 2011 at 11:58
  • 4
    Dependencies are resolved automatically, and installed/upgraded as necessary. Jul 31, 2011 at 12:22
  • this answer is the one that really answers OP's request +1
    – hmontoliu
    Jul 31, 2011 at 14:57
14

I guess this isn't really a script, but you could install puppet and use the package type. Then it will simply be a matter of creating a file with a bunch of package directives.

For example:

package { zsh:
        ensure => latest
}

package { vim-enhanced:
        ensure => latest,
        name => $operatingsystem ? {
                'centos' => 'vim-enhanced',
                'ubuntu' => 'vim',
        }

}

You could also use puppet to customize a bunch of other things like your shell, and your .rc files etc if you get in the mood to extend your scope. It might sound like overkill, but in the long run the little bit of extra effort will likely pay off.

10

In addition to using the -y flag for yes answers you will also want to set DEBIAN_FRONTEND=noninteractive to prevent debconf setting questions from popping up.

DEBIAN_FRONTEND=noninteractive apt-get install PACKAGE -y

That being said, it might be a better road in the long run to follow Kyle's suggestion and take a look at a configuration management system such as Puppet.

1

My answer is a slightly wider scope than the original question, but if you want to do this repeatedly, from scratch, across multiple machines you are setting up then I'd recommend spending the time looking into pxeboot. (I'm assuming you are a debian derivative mentioning aptitude). The learning curve is steep, the documentation a bit patchy but worth persisting if you need it.

If you have to do machines like this on a semi regular basis it's a no brainer. We have machines build from blank to fully configured in around 8 minutes with a ton of custom packages, auto installed.

For bonus points, look into some sort of apt caching mechanism as well.

A perfectly good setup is to make a build server / apt cache out of a virtual machine image to avoid polluting an existing machine

You must log in to answer this question.

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