Question

I would like to write the following Bash Script:

When installing LAMP like this, it would ask me a root password for the MySQL installation. I would like to bash script it.

sudo apt-get install lamp-server^

Can I do it like this to pass the variable as a parameter so it would not ask me about it during installation?

rootPassword="MyRootPassword";

sudo apt-get install lamp-server^ -y $rootPassword
Was it helpful?

Solution

In order to answer debconf questions non-interactively, you will need the debconf-utils package. The debconf-set-selections command can be used to manually insert things into the debconf database that will normally be asked interactively. This can also be done at OS install time using FAI or preseeding.

export DEBIAN_FRONTEND=noninteractive
debconf-set-selections < 'mysql-server-5.1 mysql-server/root_password select PASSWORD'
debconf-set-selections < 'mysql-server-5.1 mysql-server/root_password_again select PASSWORD'

You will likely need to change the name of the mysql-server package name to the version used by your distribution. Note that the package "mysql" is a virtual package which points to the real package (which includes the version number).

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top