platform: is used for getting the details of the system on which the script is running.
Here are the global variables.
install: for collecting commands for install option.
uninstall: for collecting commands for uninstall option.
PLATFORM: for identifying operating system.
ARCHITECTURE: for identifying processor.
The function to run commands one by one.
Here is the controller, which does all the command line handling. Let's take it in parts.
In this part, we first created an OptionParser object to handle command's options. Then added some custom options and their details. The option parser takes some arguments like the description of the command, the program name, version, and its usage details. Then the ad_option takes option name, its descriptive name, the action on option, (in our case to store default option value as true) and help string for option.
Here, first we have called the parse_args to parse the collected option in p. And then according to the options used, we have taken different actions. Like:
if verbose is used then set VERBOSE mode on.
if -i is used then append installation command to the global INSTALL list and call the method to run the commands.
if uninstall is used then call the run_commands method with the uninstallation command.
If no option is given then print the help menu.
Finally, call the controller in main method and main method is called automatically by the program.
And here the program ends. We have created our installer script to install apache open office. Next, You have to make the script executable.
chmod +x install_apache_open_office.py
To run the script use:
You can clone the script from Github Gists.
You can also find other installers there for installing anaconda and ruby 2.2. Just download and make them executable and run then.