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
#--------------------------------------------Globals-------------------------------------------------------------
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:
subprocess.call(cmd, 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',
prog='install-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',
default=False)
#Option Handling passes correct parameter to runBash
options, arguments = p.parse_args()
if options.verbose:
VERBOSE=True
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":
INSTALL.append("wget http://sourceforge.net/projects/openofficeorg.mirror/files/4.0.1/binaries/en-US/Apache_OpenOffice_4.0.1_Linux_x86_install-deb_en-US.tar.gz")
elif ARCHITECTURE == "64bit":
INSTALL.append("wget http://sourceforge.net/projects/openofficeorg.mirror/files/4.0.1/binaries/en-US/Apache_OpenOffice_4.0.1_Linux_x86-64_install-deb_en-US.tar.gz")
elif options.Version == "4.1":
if PLATFORM == "Linux":
if ARCHITECTURE == "32bit":
INSTALL.append("wget http://sourceforge.net/projects/openofficeorg.mirror/files/4.1.1/binaries/en-US/Apache_OpenOffice_4.1.1_Linux_x86_install-deb_en-US.tar.gz")
elif ARCHITECTURE == "64bit":
INSTALL.append("wget http://sourceforge.net/projects/openofficeorg.mirror/files/4.1.1/binaries/en-US/Apache_OpenOffice_4.1.1_Linux_x86-64_install-deb_en-US.tar.gz")
else:
print "Wrong operating system detected."
#extract
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)
else:
p.print_help()
#Runs all the functions
def main():
controller()
#This idiom means the below code only runs when executed from command line
if __name__ == '__main__':
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment