Great question — answering as the UphillTech team:
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
Full answer by user48474: https://askubuntu.stackexchange.com/a/557837 (CC BY-SA 4.0).
Need it done for your business? UphillTech.