John John - 11 months ago 51
Linux Question

Automating installation of tripwire via python in Linux

I am trying to automate installation of tripwire via apt-get through Python's subprocess module in Ubuntu Linux. The problem I have is that during the installation process, Tripwire is prompting me for Postfix mail configuration, setting site.key and local.key through different set of configuration pages (see picture attached) which appear after apt-get has installed.

How can I use subprocess module to interact with these pages?

from subprocess import *
p=Popen("apt-get install tripwire",stdout=PIPE,stdin=PIPE,stderr=PIPE,shell=True)
p.communicate(input="Y\n") # Y = Yes to confirm installation of the package through apt-get

I tried to use "stdin=PIPE", but there are a couple of challenges with interacting with these terminal pages:

  1. These pages appear after the package is downloaded and is being
    configured, so I have to implement some kind of delay for the
    page to appear

  2. Also, I need to implement up and down arrow keys to choose the various options.



enter image description here


Launch the install with auto-confirm and quiet mode enabled and set this flag:

export DEBIAN_FRONTEND=noninteractive

apt-get install -y -q tripwire

This way you won't need to communicate with the post-install config. You can also pass along pre-exising config files with -c (or specify configuration options with -o).

I would probably try:

from subprocess import call
p = call(["apt-get", "install", "-y", "-q", "-c", "config.cfg", "tripwire", shell=False])