apt-get install -y doesn't work with license agreements, how to automate that?

Solution 1:

There are some ways to do this:

  1. Pre-answer with debconf by executing the following command before installing:

    echo sun-java6-jdk shared/accepted-sun-dlj-v1-1 select true | \
        /usr/bin/debconf-set-selections
    
  2. Use expect:

    #!/usr/bin/expect -f
    sudo apt-get -y install sun-java6-jre
    expect "[y/n]"
    sleep 1
    send -- "yes\r"