Python Sample Script


import re
import ntpath
import glob
import subprocess

# In order to get this tool to run correctly, you'll need python installed (duh!) and graphviz
basedir = "/home/ronald-dev/allBashScript/"

'''
This function will scan a bash file, and look for any dependency to another bash file
@param String The fileName
@return Array The dependency filenames
'''
def readDependencies(fileName):
f = open(fileName, 'r')
content = f.read()
occurences = {} # {file1.sh:1, file2.sh:1, file3.sh:1}
for m in re.finditer('[\w|\/]*\.sh', content):
word = ntpath.basename(content[m.start(): m.end()])
# print str(m.start()) + " to " + str(m.end()) + ": " + word
if word not in occurences:
isComment = False
index = m.start()
while index > 0 and content[index] != "\n":
if content[index] == "\"" or content[index] == "'" or content[index] == "#" :
isComment = True
break
else:
index = index-1

if isComment == False:
occurences[word]=1
f.close()
return occurences.keys()

'''
Scan one bash file and convert it dependencies to GraphViz notation
@param String The fileName
@param Array The dependency filenames
@return String GraphViz notation "bash01.sh" -> "bash02.sh";[NEWLINE] etc
'''
def toGraphvizNotation(fileName, arrayOfDependencies):
string = ""
filename = ntpath.basename(fileName)
for dependency in arrayOfDependencies:
string += ' "' + filename + '" -> "' + dependency + "\";\n"

return string

'''
Scans all bash file, with extension .sh
@param String The directory to scan
@return Array Array of filenames
'''
def readAllBashFiles(directory):
return glob.glob(directory+"*.sh")

'''
Scan multiple bash files and convert their dependencies to GraphViz notation
@param String The directory to scan
@return String GraphViz notation "bash01.sh" -> "bash02.sh";[NEWLINE] etc
'''
def generateGraphVizFile(basedir):
bashfiles = readAllBashFiles(basedir)
#print bashfiles
graphVizFileContent = ""

for bashfile in bashfiles:
graphVizFileContent += toGraphvizNotation(bashfile, readDependencies(bashfile))

graphVizFileContent = "digraph G { \n"+ graphVizFileContent+ "}"
# print graphVizFileContent;
return graphVizFileContent

'''
Write to a content to a file
@param String The filename to be written to
@return String The content
'''
def writeGraphvizFile(filename, graphVizFileContent):
f = open(filename, 'w')
f.write(graphVizFileContent)
f.close()

writeGraphvizFile("/tmp/bashdependencies.dot", generateGraphVizFile(basedir))
subprocess.call(["/usr/bin/dot", "-T", "svg", "-o", "/tmp/allBashScript.svg", "/tmp/bashdependencies.dot"])
subprocess.call(["eog", "/tmp/allBashScript.svg"])

Enabling SSH (https) for Apache 2 in Ubuntu/Mint/Possibly other Debian distro


# Intall apache
$ sudo apt-get install apache2

# Enable SSL module
$ sudo a2enmod ssl

# Restart Apache
$ sudo service apache2 restart

# Create a directory to store the SSLCertificateFile and SSLCertificateKeyFile
$ mkdir /etc/apache2/ssl

# Generate the keys
$ sudo openssl req -x509 -nodes -days 365 -newkey rsa:2048 -keyout /etc/apache2/ssl/apache.key -out /etc/apache2/ssl/apache.crt
Generating a 2048 bit RSA private key
...................................+++
................................+++
writing new private key to '/etc/apache2/ssl/apache.key'
-----
You are about to be asked to enter information that will be incorporated
into your certificate request.
What you are about to enter is what is called a Distinguished Name or a DN.
There are quite a few fields but you can leave some blank
For some fields there will be a default value,
If you enter '.', the field will be left blank.
-----
Country Name (2 letter code) [AU]:CA
State or Province Name (full name) [Some-State]:Ontario
Locality Name (eg, city) []:Ottawa
Organization Name (eg, company) [Internet Widgits Pty Ltd]:Ronald Pringadi
Organizational Unit Name (eg, section) []:Engineering
Common Name (e.g. server FQDN or YOUR name) []:ronald-mint.com
Email Address []:webmaster@some-cool-website.com

# Edit your hosts file and add "127.0.0.1 some-cool-website.com"
$ gedit /etc/hosts

# Edit your sites-available ssl config
$ gedit /etc/apache2/sites-available/default-ssl.conf
# Make sure you add the following line under the email
ServerName some-cool-website:443
# Also replace
SSLCertificateFile /etc/apache2/ssl/apache.crt
SSLCertificateKeyFile /etc/apache2/ssl/apache.key

# Activte site
$ sudo a2ensite default-ssl

# Reload Apache
$ sudo service apache2 reload

Open your browser and point it to https://some-cool-website.com. The browser will prompt you that the website is using a self-sign certificate, and do you want to continue and accept that certificate. Answer yes and that’s all to it