10

I'd like to know how to use the results of debconf-show with debconf-set-selections to pre-configure deb packages with the command line or within a shell script

For example, if I use

sudo debconf-get-selections | grep java7 > result; cat result

I get the following

oracle-java7-installer  shared/present-oracle-license-v1-1  note    
oracle-java7-installer  oracle-java7-installer/local    string  
oracle-java7-installer  shared/accepted-oracle-license-v1-1 boolean true
oracle-java7-installer  shared/error-oracle-license-v1-1    error   
oracle-java7-installer  oracle-java7-installer/not_exist    error

How would the right debconf-set-selections line look like to configure the two dialogs that appear trough the installation?

In general how is the right syntax of debconf-set-selections? I assume there are not only booleans like true or false and yes or no

I guess there is much more an other example will be how to select the default desktop manager if lightdm and gdm installed by a bash script.

Is there a general proofed approach to determine and the right values for a debconf package and write a proper bash script that installs something like the webupt8 java package and preselect the values that the user normally would be asked for?

Josh
  • 1,460

3 Answers3

2

You need to use pre-seeding. The debconf-set-selections command presets answers asked by debconf before installing the package.

E.G.

sudo debconf-set-selections <<< "shared/accepted-oracle-license-v1-1 boolean true"

Then install the package.

sudo apt-get install -y oracle-java7-installer
NGRhodes
  • 9,680
1

Here is how you do it step-by-step:

  1. apt update as always.
  2. apt install debconf-utils to get access to debconf-get-selections
  3. With package foo not yet installed, debconf-get-selections | grep foo won't show you what you need.
  4. apt install foo and go through the process manually.
  5. debconf-get-selections | grep foo to see the exact strings you need. For example:
    debconf-get-selections | grep postfix
    
    postfix postfix/mailbox_limit   string  0
    postfix postfix/chattr  boolean false
    postfix postfix/root_address    string  
    postfix postfix/bad_recipient_delimiter error   
    postfix postfix/protocols   select  
    postfix postfix/recipient_delim string  +
    postfix postfix/mailname    string  /etc/mailname
    postfix postfix/main_mailer_type    select  No configuration
    postfix postfix/mynetworks  string  127.0.0.0/8 [::ffff:127.0.0.0]/104 [::1]/128
    postfix postfix/rfc1035_violation   boolean false
    postfix postfix/not_configured  error   
    postfix postfix/relayhost   string  
    postfix postfix/main_cf_conversion_warning  boolean true
    postfix postfix/newaliases  boolean false
    postfix postfix/dynamicmaps_conversion_warning  boolean 
    postfix postfix/destinations    string  
    postfix postfix/compat_conversion_warning   boolean true
    postfix postfix/procmail    boolean 
    
  6. Copy the lines you need and modify them. It may require some trial and error to know which ones are relevant and which ones are not used in your specific situation. For example, I needed these two to skip the postfix config all together:
    postfix postfix/mailname    string  /etc/mailname
    postfix postfix/main_mailer_type    select  No configuration
    
    I have gathered from trial and error that:
    • Invalid options are ignored silently without errors. It's very picky.
    • Tabs may be replaced by spaces.
    • The value comes last. Don't quote it. I put single quotes around 'No configuration' and it caused it to not work until I removed the quotes.
  7. Uninstall the package and its config: apt purge foo.
  8. Now use debconf-set-selections and pipe in the strings you copied in step 6. For example:
    debconf-set-selections <<< "postfix postfix/mailname string $(hostname)"
    debconf-set-selections <<< "postfix postfix/main_mailer_type select No configuration"
    
  9. Use debconf-get-selections to check what you have done.
  10. apt install -y foo. This time, you should not see the interactive prompt. However, if it requires an option which you have not set using debconf-set-selections, or if it does not like the option you have set using debconf-set-selections, it will still prompt for it. This is where the trial and error comes in. Rinse and repeat from step 5 until you get it right.
  11. Write your install script.
0

Debconf accepts only a restricted set of possible type values, for instance, boolean, string, note, select, and others, and it's very peaky about it.

In your question, I assume you want to automate the Java license debconf value, so you may run something like this:

echo "oracle-java7-installer shared/accepted-oracle-license-v1-1 boolean true" | sudo debconf-set-selections

If you need to add a string value, run something like this:

echo "oracle-java7-installer oracle-java7-installer/local string java" | sudo debconf-set-selections

If you need a select value you may run:

echo "oracle-java7-installer oracle-java7-installer/legacy select true" | sudo debconf-set-selections

NOTE: after running these commands ensure the right values are set with something like sudo debconf-show oracle-java7-installer and then, of course, test it on a real server installation.

TIP: Instead of > result;cat result you may just use | tee result it works very similar but does not wait until the first command completes to show you the content