Auto yes to the License Agreement on sudo apt-get

2019-01-30 03:19发布

问题:

The Oracle Java package for Ubuntu interactively asks about the License Agreement. So I have to say 'OK' and then 'yes' every time, but I'd like to automate it. What I do is this:

sudo add-apt-repository -y ppa:webupd8team/java
sudo apt-get update
sudo apt-get -y install oracle-java7-installer 

Is there a simple way to automate the agreement process without using expect?

回答1:

try this out:

sudo add-apt-repository -y ppa:webupd8team/java
sudo apt-get update
echo debconf shared/accepted-oracle-license-v1-1 select true | sudo debconf-set-selections
echo debconf shared/accepted-oracle-license-v1-1 seen true | sudo debconf-set-selections
sudo apt-get -y install oracle-java7-installer 

running 3rd and 4th command on my debian 7.1 helps, so I think the same can help on ubuntu as well



回答2:

If you are using Ansible for automation you may want to put this into your playbook:

tasks:

  - name: add java PPA
    apt_repository:
      repo: "ppa:webupd8team/java"

  - name: accept oracle license
    debconf:
      name: "oracle-java7-installer"
      question: "shared/accepted-oracle-license-v1-1"
      value: "true"
      vtype: "select"

  - name: install jdk
    apt:
      name: "oracle-java7-installer"

Note: The value argument in debconf must be set to "true", including the quotes, as per comment by Roy Wood.



回答3:

If you are using Chef for provisioning your servers with Oracle Java you can do the following in a bash execute resource.

Working off maxym's answer above

bash 'java-licence-agree' do
  code <<-EOH
    echo debconf shared/accepted-oracle-license-v1-1 select true | debconf-set-selections
    echo debconf shared/accepted-oracle-license-v1-1 seen true | debconf-set-selections
  EOH
end