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!
aptitude install -y package1 package2 package3
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 ofpackage
directives.For example:
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.
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.
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.
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