So we have our software product, which I'm currently working on a way to automate its installation. The way it will be done is:
- I have a
config.cfg
file, which has all the information aboutApache
,Tomcat
andMySQL's
user and password, as well as port numbers. - I use
ConfigParser
to have that information available.
The installer script is iterative: you execute it like sudo foo.run
and it prompts the command line so the person doing the installation can enter the inputs mentioned above. For example:
Apache user: **[foo]**
Apache password: **[bar]**
and after that information is entered, the installer actually installs the product. However, I want to automate the full process, including inputting those informations using Python
.
So far I came with this:
1 from subprocess import Popen, call, PIPE, STDOUT
2 import errno
3 import os
4 fname = "/home/ec2-user/foo.run"
5 os.chmod(fname, 0777) # make it executable
6 cmd = "sudo %s" % fname
7 print cmd
9 p = Popen(cmd, stdin=PIPE, stdout=PIPE,
10 stderr=STDOUT, shell=True)
11 # now is actually the missing part ... reading from the stdout and writing
12 # to stdin ... how could I accomplish that? Is there a easier way of doing it?
13 p.wait()
So I'm having a little trouble designing how that stdin
/ stdout
part would work ...
I need a while
loop to read from it until stdout
is empty, and then I would inject the data contained in ConfigParser
.
Could someone please give an example how that could be done? Is there any other easier way of doing it? I'm open to any suggestions ... A first step for me could be doing a manual installer from python, using Python's
p.stdin.write()
to give the informations to the installer.