Skip to content

Instantly share code, notes, and snippets.

@SergKolo
Created July 25, 2016 00:57
Show Gist options
  • Save SergKolo/234bb049ac18385744cbdec322a2b68b to your computer and use it in GitHub Desktop.
Save SergKolo/234bb049ac18385744cbdec322a2b68b to your computer and use it in GitHub Desktop.
import subprocess
import os
import sys
# This is a function that simplifies calling
# commands. Instead of writing that same try-except
# block over and over, write it once
def run_cmd(cmdlist):
proc = None
try:
# output gets saved to proc , only stderr
# gets printed
proc = subprocess.check_output(cmdlist)
except subprocess.CalledProcessError:
pass
# To install something with apt-get
# you must run script as root. Check
# if we are root, and if we are not
#
try:
if os.getuid() != 0:
raise Exception('The script must run with sudo')
except Exception as error_text:
print('!!! ' + repr(error_text))
else:
# subprocess expects a list of command + parameters
# Package list can be left as a long string and turned
# into a list with the .split() function.
# But quite frankly this would be horrible formating,
# going over 79 chars in line (which is standard for )
# python
packages_list=[ 'python-pip', 'python-sqlalchemy', 'mongodb',
'python-bson', 'python-dpkt', 'python-jinja2',
'python-magic', 'python-gridfs', 'python-libvirt',
'python-bottle', 'python-pefile', 'python-chardet'
'git', 'build-essential', 'autoconf', 'automake',
'libtool', 'dh-autoreconf', 'libcurl4-gnutls-dev',
'libmagic-dev', 'python-dev', 'tcpdump', 'libcap2-bin',
'virtualbox', 'dkms', 'python-pyrex' ]
command_list = [ 'apt-get','install' ]
for package in package_list:
full_command = command_list + package
run_cmd(full_command)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment