-
-
Save curioswati/c9c2e91f472c702a7058c99f6dfbf2b4 to your computer and use it in GitHub Desktop.
Installer script for Jekyll 2 with Ruby 2.2 on ubuntu 18.04
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
import subprocess | |
import optparse | |
import platform | |
#-------------------------------------Globals-------------------------------------------------------- | |
install = [] | |
uninstall = ["sudo apt-get remove ruby* ruby*-dev rubygems"] | |
PLATFORM = platform.system() | |
ARCHITECTURE = platform.architecture()[0] | |
#-------------------------------------Running commands----------------------------------------------- | |
def run_commands(cmds): | |
""" | |
Function which run all commands one by one. | |
""" | |
for cmd in cmds: | |
try: | |
subprocess.call(cmd, shell=True) | |
except Exception as e: | |
print e | |
#----------------------------------------Option parsing---------------------------------------------- | |
def controller(): | |
""" | |
Function to control option parsing. | |
""" | |
global install, VERBOSE | |
#Create instance of OptionParser Module, included in Standard Library | |
p = optparse.OptionParser(description='For installing jekyll', | |
prog='install_jekyll', | |
version='install_jekyll 0.1', | |
usage= '%prog [option]') | |
p.add_option('--install','-i', action="store_true", help='install jekyll along with ruby.') | |
p.add_option('--uninstall','-u', action="store_true", help='uninstall jekyll along with ruby.') | |
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: | |
if PLATFORM == "Linux": | |
#----------------------------------------setting commands---------------------------- | |
# install build dependencies | |
install.append("sudo apt-get install gcc g++ make build-essential software-properties-common zlib1g-dev") | |
install.append("sudo apt-get install ruby-full") | |
# install Ruby Gems | |
install.append("echo '# Install Ruby Gems to ~/gems' >> ~/.bashrc") | |
install.append("echo 'export GEM_HOME=$HOME/gems' >> ~/.bashrc") | |
install.append("echo 'export PATH=$HOME/gems/bin:$PATH' >> ~/.bashrc") | |
install.append("source ~/.bashrc") | |
# install jekyll | |
install.append("gem install jekyll bundler") | |
else: | |
print "Wrong operating system detected." | |
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