Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
Installer script for Apache open office 4.0 or 4.1 on ubuntu 14.04
#!/usr/bin/env python
import subprocess
import optparse
import platform
install = []
uninstall = ["sudo apt-get purge openoffice*.* && sudo apt-get autoremove"]
PLATFORM = platform.system()
ARCHITECTURE = platform.architecture()[0]
#------------------------------------------Running commands------------------------------------------------------
def run_commands(cmds):
Function which run all the commands.
for cmd in cmds:, shell=True)
#-------------------------------------------Option parsing-------------------------------------------------------
def controller():
Function which does parsing on options received from command line and
also prepares a list of commands that are used for installation.
global VERBOSE, install, uninstall
#Create instance of OptionParser Module, included in Standard Library and add options to it.
p = optparse.OptionParser(description='For installing Apache open office',
version='install-open-office 0.1',
usage= '%prog [option]')
p.add_option('--install','-i', action="store_true", help='installs open office')
p.add_option('--uninstall', '-u', action="store_true", help='uninstalls open office')
p.add_option('--Version', '-V', help='specifying version')
p.add_option('--verbose', '-v',
action = 'store_true',
help='prints verbosely',
#Option Handling passes correct parameter to runBash
options, arguments = p.parse_args()
if options.verbose:
if options.install:
#----------------------------------------setting commands------------------------------------------------
#Removing libreoffice
INSTALL.append("sudo apt-get remove --purge libreoffice* libexttextcat-data* && sudo apt-get autoremove")
#removing openoffice
INSTALL.append("sudo apt-get purge openoffice*.* && sudo apt-get autoremove")
#change to /tmp
INSTALL.append("cd /tmp")
#download the application
if PLATFORM == "Linux":
##For 4.0.1
if options.Version == "4.0":
if ARCHITECTURE == "32bit":
elif ARCHITECTURE == "64bit":
elif options.Version == "4.1":
if PLATFORM == "Linux":
if ARCHITECTURE == "32bit":
elif ARCHITECTURE == "64bit":
print "Wrong operating system detected."
INSTALL.append("tar -xvf Apache_OpenOffice*.tar.gz")
#install deb
INSTALL.append("sudo dpkg -i en-US/DEBS/*.deb")
#install the desktop-integration
INSTALL.append("sudo dpkg -i en-US/DEBS/desktop-integration/*.deb")
value = run_commands(INSTALL)
elif options.uninstall:
value = run_commands(UNINSTALL)
#Runs all the functions
def main():
#This idiom means the below code only runs when executed from command line
if __name__ == '__main__':
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment