How can I automate dpkg/apt-get?

后端 未结 5 1211
清歌不尽
清歌不尽 2020-12-06 02:34

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 ne

5条回答
  •  余生分开走
    2020-12-06 03:12

    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

    • Anthony Towns' answer & bit-rotting link
    • Man debconf-set-selections(1)
    • Duplicate answer on ServerFault

提交回复
热议问题