Truly non-interactive / unattended apt-get install
I’ve recently begun tinkering with Amazon Web Services (specifically their EC2 service) and RightScale. The major difference between these “Cloud” computing platforms and others is that the “instance” (i.e A running virtual machine) is temporary. Once it is shut down, all the data is gone. Additionally, the RightScale (and fairly common) way about going things is to use a “clean” machine image and script the install of the specific packages you need on Launch. So you can use the same image for an Application server, or DB server, or mail server – just have their respective packages installed on boot.
For Debian/Ubuntu (I happen to be using Ubuntu 8.10 Intrepid Ibex), you have the joy of apt-get. If you run apt-get with -q -y, it will assume “yes” to everything (and do it quietly). Now the only major problem is that some packages ask post install questions using whiptail (The blue configuration screen). In my case it it was MySQL demanding a root password. But I was informed of an easy way around that, exporting a value before install.
Below is an example of what to run:
# export DEBIAN_FRONTEND=noninteractive
# apt-get -q -y install mysql-server-5.0
This will install and start MySQL without so much as a peep until it is all done. Of course you get a blank root password which is a security issue, but that is easy to fix later. Piece of cake, if you happen to know about these magical exports.
If you are using sudo to run apt-get, you will need to tell sudo to pass the environment variable. You can use the -E flag to sudo (which exports everything, which may be a security hole), or the env_keep option in the sudo configuration, as described here: http://stackoverflow.com/questions/8633461/how-to-keep-environment-variables-when-using-sudo
Whoever is interested in debconf preconfiguration, here’s how to do:
sudo debconf-set-selections <<< 'mysql-server- mysql-server/root_password password your_password’
sudo debconf-set-selections <<< 'mysql-server- mysql-server/root_password_again password your_password’
sudo apt-get -y install mysql-server
The only drawback is once you’ve setup your scripts with the proper version number and there’s a newer mysql-server this preconfiguration will not work anymore. I prefer the method described here using noninteractive setup and changing the root password afterwards.
Oops …. let’s try again:
sudo debconf-set-selections <<< ‘mysql-server-<version> mysql-server/root_password password your_password’
sudo debconf-set-selections <<< ‘mysql-server-<version> mysql-server/root_password_again password your_password’
sudo apt-get -y install mysql-server
Excellent! Alternatives!
yes it is!! thanks the comments were especially helpful!
Ha, 4 years later and your post is still useful. Thanks!
You can use debconf to preconfigure things required by apt.
Please note that this method may be affected by /etc/sudoers settings (reset_env), subprocesses that do not read shell dot files and so on. You can configure apt (man 5 apt.conf) to assume “yes” by default, see https://github.com/travis-ci/travis-cookbooks/commit/22a33eb345f797187f59df9c11861a21f0e9567d for example
Awesome Info ! ! !
Saved me soo much timeee !!!
Did not think environment variable would come to the rescue :)
Any idea how to do it in Ubuntu?
Define “do it in Ubuntu” because when I did the above post, it was in Ubuntu.
If you mean, do this on a desktop machine… that’s a different story. In that case you’d either need to install one machine and capture the image with something like clonezilla. Then redeploy that to all your other machines. OR, if they are different, you’d have to modify the Ubuntu installer to fetch your post install script. You might want to check out: https://help.ubuntu.com/community/InstallCDCustomization — Specifically the portion about preseeing.
Good luck!
You can preconfigure the passwords using debconf preseeding.
So how would you provide a preconfigured password to this mysql installation?
I don’t know how to provide the password to the setup, but you could add a line afterwards to set the password (since it is blank by default). The following line will do that:
mysqladmin -u root password NEWPASSWORD