How can I automate dpkg/apt-get?
Asked Answered
H

6

10

I'm trying to create a script that automatically downloads packages for new servers. However, some things like 'mysql-server' can not installed automatically cause you need to configure them in the ncurses interface first. I've looked through the man pages and can't find anything appropriate.

I don't care if I have to upload/edit a conf file later -- I just need the appropriate packages installed.

Anyone know what to do besides grabbing tarballs and building them myself?

UPDATE found out that for things like mysql-server you can just do:

DEBIAN_FRONTEND='noninteractive' apt-get install -yq mysql-server

however expect looks like something I'll need for sun-java6-jdk; haven't evaluated it yet

Hawks answered 31/3, 2009 at 17:53 Comment(1)
Great to know for making Dockerfiles, too!Stannum
W
6

For packages that ask questions through debconf (which is what puts up the ncurses display), you can pre-answer the questions. For sun-java, the questions can be pre-answered by following the instructions at http://www.davidpashley.com/blog/debian/java-license

Whisenhunt answered 1/4, 2009 at 12:13 Comment(0)
E
9

Answer from ossramblings.com:

First, install your package normally; then, extract the configuration answers from the debconf data files:

sudo apt-get install debconf-utils
sudo debconf-get-selections | grep mypackage > something.seed

Then, for other installations, you can apply it before installing the package:

sudo debconf-set-selections ./something.seed
Elisabetta answered 21/11, 2011 at 20:2 Comment(0)
S
8

Any Debian package which uses debconf to get configuration values can be run unattended. The trick is that debconf will first search for pre-installed answers to any config question which a given package has.

Pre-install config answers

Just create a file in the following format,

# Use one line for each question
package-name question-name question-type answer
package-name question-name question-type really long \
answer here
package-name question-name question-type answer
...

and feed it into the system like so:

$ debconf-set-selections my-selections-file

Now, you're ready to apt-get install, as usual.

One-off

Since this command also reads from stdin, you can do:

$ echo "man-db man-db/auto-update boolean true" | debconf-set-selections

Finding default answers

How do you know which packages use these configuration answers? Well, if you've already installed the package in question interactively, you can query your local system to see what values are currently configured. debconf-get-selections prints a list of all config answers for the current system. For example

$ debconf-get-selections | grep '^man'

returns the following on my system:

man-db  man-db/install-setuid   boolean false
man-db  man-db/auto-update      boolean true

You may need to install the debconf-utils package to make this command available.

Sample

# Preset values to questions which would otherwise be asked while
# installing packages.
# Use debconf-set-selections to install
openssh-server  openssh-server/permit-root-login        boolean false
man-db  man-db/install-setuid   boolean false
man-db  man-db/auto-update      boolean true

Sources

Stannum answered 12/8, 2016 at 2:19 Comment(0)
W
6

For packages that ask questions through debconf (which is what puts up the ncurses display), you can pre-answer the questions. For sun-java, the questions can be pre-answered by following the instructions at http://www.davidpashley.com/blog/debian/java-license

Whisenhunt answered 1/4, 2009 at 12:13 Comment(0)
P
0

I'm not sure exactly what configuration mysql-server needs, but you could try something like expect

Pavement answered 31/3, 2009 at 18:8 Comment(1)
thanks for the suggestion -- I remember coming across that years ago and totally disregarded it -- looks like it's the hot ticket here howeverHawks
E
0

I would look into cron-apt. I haven't tried it myself, but it's package description sounds promising.

Evetta answered 22/5, 2009 at 23:20 Comment(0)
D
0

Worth to mentioned is that debconf-get-selections seems not to be able to handle notes. To be able not confirm them start aptor dpkg with DEBIAN_FRONTEND=noninteractive. e.g. sudo DEBIAN_FRONTEND=noninteractive apt install foobar

Donnettedonni answered 23/12, 2023 at 0:19 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.