Reputation: 1815
I'm trying to write a script which checks for prerequisite software in Ubuntu and if not installed, goes ahead and installs it.
I'm a newbie to Python and I understand that Python's subprocess
module can be used to achieve this goal.
I have written this below sample code but not sure why it is failing.
import subprocess
c = subprocess.Popen(['sudo','apt-get','install','git'], stdout=subprocess.PIPE, stdin=subprocess.PIPE, stderr=subprocess.STDOUT)
grep_stdout = c.communicate(input='root')[0]
print(grep_stdout)
When I run this program, i get the following error...
sudo: no tty present and no askpass program specified
Sorry, try again.
sudo: no tty present and no askpass program specified
Sorry, try again.
sudo: no tty present and no askpass program specified
Sorry, try again.
sudo: 3 incorrect password attempts
Am i missing something here?
Upvotes: 0
Views: 743
Reputation: 11
import subprocess
c = subprocess.Popen(['sudo','yum','install','git','-y'],
stdout=subprocess.PIPE, stdin=subprocess.PIPE, stderr=subprocess.STDOUT)
grep_stdout = c.communicate(input='root')[0]
print(grep_stdout)
Upvotes: 1
Reputation: 174662
There are significant amount of pre-requisite . I just thought asking user to install all of them would be a pain in the neck. so just thought of writing a function which will test the software and if something not installed will go ahead and install for him
There are a few approaches to this:
Check if software is there, if it isn't exit the program with a message listing the missing components to be installed.
Provide a list of software that needs to be installed in README
or documentation.
Create a debian package listing the dependencies required; and have the user install this with their preferred method.
If your program must install the software itself (does it really have to?), then instruct the user to run your script with elevated privileges. In your documentation, ask them to run it as root
.
By the way sudo
may not be installed on all systems.
Upvotes: 4