Last active
January 21, 2016 22:07
-
-
Save i3visio/b079202c1b49b2d45d9b to your computer and use it in GitHub Desktop.
An unattended installer for OSRFramework.
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
# -*- coding: cp1252 -*- | |
# | |
################################################################################## | |
# | |
# Copyright 2015 Félix Brezo and Yaiza Rubio (i3visio, [email protected]) | |
# | |
# This program is Free Software. You can redistribute it and/or modify | |
# it under the terms of the GNU General Public License as published by | |
# the Free Software Foundation, either version 3 of the License, or | |
# (at your option) any later version. | |
# | |
# This program is distributed in the hope that it will be useful, | |
# but WITHOUT ANY WARRANTY; without even the implied warranty of | |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
# GNU General Public License for more details. | |
# | |
# You should have received a copy of the GNU General Public License | |
# along with this program. If not, see <http://www.gnu.org/licenses/>. | |
# | |
################################################################################## | |
import getpass | |
import urllib | |
import os | |
import sys | |
import zipfile | |
__version__ = "0.5" | |
banner = text = """ | |
___ ____ ____ _____ _ | |
/ _ \/ ___|| _ \| ___| __ __ _ _ __ ___ _____ _____ _ __| | __ | |
| | | \___ \| |_) | |_ | '__/ _` | '_ ` _ \ / _ \ \ /\ / / _ \| '__| |/ / | |
| |_| |___) | _ <| _|| | | (_| | | | | | | __/\ V V / (_) | | | < | |
\___/|____/|_| \_\_| |_| \__,_|_| |_| |_|\___| \_/\_/ \___/|_| |_|\_\ | |
Version: OSRFramework Installer """ + __version__ + """ | |
Created by: Felix Brezo and Yaiza Rubio, (i3visio) | |
""" | |
print banner | |
print "Welcome. This script will try to download and install the latest version of OSRFramework without human interaction." | |
print "All the steps found in the <https://github.com/i3visio/osrframework/README.md> file will be automatically performed." | |
url="https://github.com/i3visio/osrframework/archive/master.zip" | |
version = "osrframework-latest" | |
file_name = version + ".zip" | |
##### Checking if it is run as root in linux2 systems | |
# Changing owner in linux and macos systems | |
if sys.platform == 'linux2' or sys.platform == 'darwin' : | |
if os.geteuid() != 0: | |
print "You are NOT running this program as root." | |
print "Try:\n\tsudo python osrframework-installer.py" | |
print "The installation is exiting now." | |
sys.exit() | |
print "======" | |
print "STEP 1" | |
print "======" | |
print "Retrieving latest OSRFramework from the official Github Repository..." | |
try: | |
urllib.urlretrieve(url, file_name) | |
except Exception as e: | |
print "ERROR: Something happened in the download process:" | |
print e | |
print "The program will now exit." | |
sys.exit() | |
print "Done." | |
print "======" | |
print "STEP 2" | |
print "======" | |
# Unzipping | |
try: | |
print "Trying to unzip the file..." | |
with zipfile.ZipFile(file_name, "r") as z: | |
z.extractall("./") | |
def _chown(path, uid, gid): | |
""" | |
Function to recursively change the user id and group id. | |
""" | |
os.chown(path, uid, gid) | |
for item in os.listdir(path): | |
itempath = os.path.join(path, item) | |
if os.path.isfile(itempath): | |
os.chown(itempath, uid, gid) | |
elif os.path.isdir(itempath): | |
os.chown(itempath, uid, gid) | |
_chown(itempath, uid, gid) | |
# Changing owner in linux and macos systems | |
if sys.platform == 'linux2' or sys.platform == 'darwin': | |
#os.chown("./osrframework-master", int(os.getenv('SUDO_UID')), int(os.getenv('SUDO_GID'))) | |
_chown("./osrframework-master", int(os.getenv('SUDO_UID')), int(os.getenv('SUDO_GID'))) | |
except Exception as e: | |
print "ERROR: Something happened in the unzipping process:" | |
print e | |
print "The program will now exit." | |
sys.exit() | |
print "Done." | |
print "======" | |
print "STEP 3" | |
print "======" | |
print "The program will now try to install the latest version in the system." | |
try: | |
print "\tCurrent OS:\t" + sys.platform | |
# ----------------- | |
# Windows platforms | |
# ----------------- | |
if sys.platform == 'win32': | |
# TODO: verify that python is already found | |
# TODO: cd into the appropriate folder, instead of hard coding it. | |
# TODO: cd into the appropriate folder, instead of hard coding it. | |
cmd = "cd osrframework-master" | |
print "\tLaunching command:\t> " + cmd | |
output = os.chdir("./osrframework-master") | |
cmd = "python setup.py build" | |
print "\tLaunching command:\t> " + cmd | |
output = os.popen(cmd).read() | |
print output | |
cmd = "python setup.py install" | |
print "\tLaunching command:\t> " + cmd | |
output = os.popen(cmd).read() | |
print output | |
print "Trying to install the rest of requirements..." | |
cmd = "pip install -r requirements.txt" | |
print "\tLaunching command:\t> " + cmd | |
output = os.popen(cmd).read() | |
print output | |
cmd = "python ez_setup.py networkx" | |
print "\tLaunching command:\t> " + cmd | |
output = os.popen(cmd).read() | |
print output | |
# ------------------------- | |
# Linux and MacOS platforms | |
# ------------------------- | |
elif sys.platform == 'linux2' or sys.platform == 'darwin': | |
# TODO: cd into the appropriate folder, instead of hard coding it. | |
cmd = "cd osrframework-master" | |
print "\tLaunching command:\t> " + cmd | |
output = os.chdir("./osrframework-master") | |
cmd = "python setup.py build" | |
print "\tLaunching command:\t> " + cmd | |
output = os.popen(cmd).read() | |
print output | |
cmd = "python setup.py install" | |
print "\tLaunching command:\t> " + cmd | |
output = os.popen(cmd).read() | |
print output | |
try: | |
import pip | |
except: | |
print "ERROR: It seems that pip is not installed in the system:" | |
print "We will try to install it manually with ez_setup.py." | |
try: | |
cmd = "python ez_setup.py pip" | |
print "\tLaunching command:\t> " + cmd | |
output = os.popen(cmd).read() | |
print output | |
import pip | |
except: | |
print "We could not install pip. We will now exit." | |
sys.exit() | |
print "Trying to install the requirements..." | |
cmd = "pip install -r requirements.txt" | |
print "\tLaunching command:\t> " + cmd | |
output = os.popen(cmd).read() | |
print output | |
try: | |
import oauthlib | |
v = oauthlib.__version__.split('.') | |
parameters = [ int(x) for x in v] | |
go = False | |
if parameters[0] == 0: | |
if parameters[1] > 6: | |
go = True | |
elif parameters[1] > 1: | |
go = True | |
else: | |
go = True | |
if go == False: | |
raise ValueError("There is a problem with oauthlib in your system.") | |
except: | |
# TODO: deal with this in the setup.py file. | |
print "Try typing the following and relaunch the installer:" | |
print "\tsudo apt-get remove oauthlib" | |
print "\tsudo pip install oauthlib -U""" | |
sys.exit() | |
cmd = "python ez_setup.py networkx" | |
print "\tLaunching command:\t> " + cmd | |
output = os.popen(cmd).read() | |
print output | |
else: | |
print "The OS is not supported..." | |
print "The program will now exit." | |
sys.exit() | |
# TODO: Verify the installation importing osrframework | |
except: | |
print "ERROR: Something happened. An unexpected behaviour took place during the installation." | |
sys.exit() | |
print "======" | |
print "STEP 4" | |
print "======" | |
cmd = "cd osrframework" | |
print "\tLaunching command:\t> " + cmd | |
output = os.chdir("./osrframework") | |
print "We will try to launch usufy.py to test the installation." | |
print "------------------------------------------------------------------------------" | |
print "\tTesting the installation..." | |
print "\tWe will perform a sample launch below the dashed line." | |
cmd = "python usufy.py -n i3visio -p twitter github facebook instagram pinterest" | |
print "\tLaunching command:\t> " + cmd | |
print "------------------------------------------------------------------------------" | |
output = os.popen(cmd).read() | |
if "OSRFramework" in output: | |
print output | |
print "We will remove the results folder created as root, to avoid future errors." | |
cmd = "rm ./results -r" | |
output = os.popen(cmd).read() | |
else: | |
print "------------------------------------------------------------------------------" | |
print "\tSomething has gone wrong." | |
# ----------------- | |
# Windows platforms | |
# ----------------- | |
if sys.platform == 'win32': | |
print "Don't panic! You are running a Windows platform and this seems to be a known issue." | |
print "Try reinstalling it manually with:" | |
print "\tcd osrframework-master" | |
print "\tpython setup.py build" | |
print "\tpython setup.py install" | |
print "And then try running usufy.py again:" | |
print "\tcd osrframework" | |
print "\t"+ cmd | |
print "Anyway, revisit the dependencies and keep up posted about the issue in <http://github.com/i3visio/osrframework/issues>." | |
print "------------------------------------------------------------------------------" | |
sys.exit() | |
print "------------------------------------------------------------------------------" | |
print "\tEnd of test. You should have seen the results above." | |
print "------------------------------------------------------------------------------" | |
print "Remember that you will be able to launch the applications in the framework by browsing to:" | |
print "\t./osrframework-master/osrframework" | |
print "You can try some sample searches with:" | |
print "\tpython usufy.py -n i3visio -p twitter facebook" | |
print "\tpython mailfy.py -n i3visio" | |
print "\tpython searchfy.py -n i3visio -p all" | |
print "\tpython entify.py -r all -w http://i3visio.com" | |
# TODO: using argparse to ask for parameters: | |
# - Branch to be installed | |
# - Path to be installed | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment