5

Say I need to install a package using dpkg -i, which would prompt user for some values such as username and password.

I can easily do it from terminal and proceed with installation.

But going by this plan I cannot automate the installation, for example if I want to write a script for installation of a package which takes the parameters interactively.

So I want a dpkg installation plan which is interactive (prompting for username and password) but can still be able to be invoked from a script so that the installation process is automated.

How can I go about this? Are there any alternatives?

2 Answers 2

4

You can create a preconfiguration file using tools in the debconf-utils package. You can create a preconfiguration file manually with:

<owner> <question> <type> <value> 

or as an example:

my-package username string Bob
my-package password string I$aN1ceGuy

Easier is to install it on your machine and run:

debconf-get-selections | grep my-package

Use the output to create a file.

Once you have the file, use:

debconf-set-selections <filename>.  
dpkg -i my-package

The selections listed in filename will be used by default and the package will install silently.

http://www.debian.org/releases/stable/i386/apbs03.html.en

3

For such things you can write an expect script. It's not very difficult to handle.

First you have to install the interpreter:

apt-get install expect

Then you can write something like this for example:

#!/usr/bin/expect -f
set timeout 30
set password "pass"
set username "user"

#run the command
spawn dpkg -i package.deb

# Look for username prompt
expect "*?sername:*" #<--- this statement is important it wait's for a prompt "username:"
send "$username\r"

# Look for passwod prompt
expect "*?assword:*" #<--- the same with the "password:" prompt
send "$password\r"

#dpkg -i continues

The script must be executable, of course. Expect is perfect for controlling interactive terminal programs via script (ssh, ftp, ...)

You must log in to answer this question.

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