#!/bin/bash

# Check if user is root
if [[ $EUID -ne 0 ]]; then
	echo "This script must be run as root" 1>&2
	exit 1
fi

# Get submodules
echo '[*] Downloading git submodules'
echo '[+] Running: git submodule init'
git submodule init
echo '[+] Running: git submodule update'
git submodule update
echo

# Install required binaries
echo '[*] Installing necessary binaries'
echo '[+] Running: apt-get update -y'
apt-get update -y
echo '[+] Running: apt-get install -y ruby smbclient gcc git ruby ruby-dev libcurl4-openssl-dev make zlib1g-dev libssl-dev default-libmysqlclient-dev nfs-common cmake qt4-qmake python xvfb python-qt4 python-pip python-dev tesseract-ocr'
apt-get install -y ruby smbclient gcc git ruby ruby-dev libcurl4-openssl-dev make zlib1g-dev libssl-dev default-libmysqlclient-dev nfs-common cmake qt4-qmake python xvfb python-qt4 python-pip python-dev tesseract-ocr
echo

# Create virtualenv
echo '[*] Creating virtualenv for Python library installations'
echo '[+] Running: pip install virtualenv'
pip install virtualenv
echo '[+] Running: virtualenv -p /usr/bin/python2.7 pm'
virtualenv -p /usr/bin/python2.7 pm
echo '[+] Running: pm/bin/pip2 install requests-futures requests python-libnmap pycurl pysnmp impacket==0.9.12 pyopenssl mysql-python python_qt_binding fuzzywuzzy selenium python-Levenshtein pyasn1 pyvirtualdisplay beautifulsoup4 rdpy pillow pytesseract netaddr paramiko'
pm/bin/pip2 install requests-futures requests python-libnmap pycurl pysnmp impacket==0.9.12 pyopenssl mysql-python python_qt_binding fuzzywuzzy selenium python-Levenshtein pyasn1 pyvirtualdisplay beautifulsoup4 rdpy pillow pytesseract netaddr paramiko
echo

#Install gems for wpscan
echo '[*] Installing Ruby gems for WPScan then updating WPScan database'
echo '[+] Running: gem install snmp'
gem install snmp
echo '[+] Running: gem install bundler'
gem install bundler
echo '[+] Running: cd tools/wpscan'
cd tools/wpscan
echo '[+] Running: bundle install'
bundle install
echo

# Update wpscan
echo '[+] Running: wpscan.rb --update'
./wpscan.rb --update
cd ../..
echo

# Install PyQt4 and SIP for eyewitness
echo '[*] Installing PyQT4 into virtualenv'
echo '[+] Running: cp -r /usr/lib/python2.7/dist-packages/PyQt4 pm/lib/python2.7/site-packages/'
cp -r /usr/lib/python2.7/dist-packages/PyQt4 pm/lib/python2.7/site-packages/
echo '[+] Running: cp -r /usr/lib/python2.7/dist-packages/sip*.so pm/lib/python2.7/site-packages/'
cp -r /usr/lib/python2.7/dist-packages/sip*.so pm/lib/python2.7/site-packages/
echo

echo '[*] Done. Run the following command before running pentest-machine: source pm/bin/activate'
echo '    When you are done with pentest-machine deactivate the virtualenv by running the command: deactivate'
