Last active
July 19, 2016 08:51
-
-
Save Cashiuus/936e635331ca74e3876f to your computer and use it in GitHub Desktop.
Setup Python 2 & 3 in Kali 2 as core dependencies and used to create 2 virtual environments: env-2.7 and env-3.4, keeping it as close to Debian style as possible.
This file contains hidden or 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
#!/bin/bash | |
#-Metadata----------------------------------------------------# | |
# Filename: setup-python.sh (Update: 09-11-2015 # | |
#-Author(s)---------------------------------------------------# | |
# cashiuus - [email protected] # | |
#-Licence-----------------------------------------------------# | |
# MIT License ~ http://opensource.org/licenses/MIT # | |
#-Notes-------------------------------------------------------# | |
# This will setup Kali to have both Python 2 & 3 using | |
# apt-get for the core dependencies, staying as pure as able. | |
# Virtual environments will be setup in the default | |
# ~/.virtualenvs directory. | |
# | |
# After script, type workon <tab> to see virtualenvs | |
#-------------------------------------------------------------# | |
INSTALL_PY3="true" | |
DEFAULT_VERSION="2" # Set to 3 for py3; Determines which is activated | |
py2version="2.7" | |
py3version="3.4" | |
## Text Colors | |
RED="\033[01;31m" # Issues/Errors | |
GREEN="\033[01;32m" # Success | |
YELLOW="\033[01;33m" # Warnings/Information | |
BLUE="\033[01;34m" # Heading | |
BOLD="\033[01;01m" # Highlight | |
RESET="\033[00m" # Normal | |
# Determine active shell to update the correct resource file | |
if [[ "${SHELL}" == "/usr/bin/zsh" ]]; then | |
SHELL_FILE=~/.zshrc | |
else | |
SHELL_FILE=~/.bashrc | |
fi | |
# Pre-requisites for compiling Python | |
echo -e "\n ${GREEN}-----------${RESET}[ Installing Python Dependencies ]${GREEN}-----------${RESET}" | |
apt-get install -y -qq build-essential python python3 python-pip virtualenvwrapper | |
# Create a PIP configuration file that specifies a cache directory | |
echo -e "\n ${GREEN}-----------${RESET}[ Creating Pip Config - Cache Settings ]${GREEN}-----------${RESET}" | |
mkdir -p ~/.pip/cache | |
cat <<EOF > ~/.pip/pip.conf | |
[global] | |
download_cache = ~/.pip/cache | |
EOF | |
# Install Python 3.4.x | |
if [ $INSTALL_PY3 == "true" ]; then | |
apt-get -y -qq install python3 | |
fi | |
echo -e "\n ${GREEN}-----------${RESET}[ Creating Virtual Environments ]${GREEN}-----------${RESET}" | |
if [ ! -e /usr/local/bin/virtualenvwrapper.sh ]; then | |
# apt-get package symlinking to where this file is expected to be | |
ln -s /usr/share/virtualenvwrapper/virtualenvwrapper.sh /usr/local/bin/virtualenvwrapper.sh | |
fi | |
source /usr/local/bin/virtualenvwrapper.sh | |
# Tweak the post-creation script for new envs to auto-install core apps | |
file=$WORKON_HOME/postmkvirtualenv | |
cat <<EOF > "${file}" | |
#!/usr/bin/env bash | |
pip install argparse | |
pip install pep8 | |
pip install requests | |
EOF | |
# Virtual Environment Setup - Python 3.4.x | |
if [ $INSTALL_PY3 == "true" ]; then | |
mkvirtualenv env-${py3version} -p /usr/bin/python${py3version} | |
fi | |
# Virtual Environment Setup - Python 2.7.x | |
mkvirtualenv env-${py2version} -p /usr/bin/python${py2version} | |
# Add lines to shell dot-file if they aren't there | |
echo -e "\n ${GREEN}-----------${RESET}[ Updating Shell Startup - ${SHELL_FILE} ]${GREEN}-----------${RESET}" | |
file=$SHELL_FILE | |
grep -q '^### Load Python Virtualenvwrapper' "${file}" 2>/dev/null || echo '### Load Python Virtualenvwrapper Script helper' >> "${file}" | |
grep -q '^[[ -e "/usr/local/bin/virtualenvwrapper.sh"' "${file}" 2>/dev/null || echo '[[ -e /usr/local/bin/virtualenvwrapper.sh ]] && source "/usr/local/bin/virtualenvwrapper.sh"' >> "${file}" | |
grep -q '^export WORKON_HOME=$HOME/.virtualenvs' "${file}" 2>/dev/null || echo 'export WORKON_HOME=$HOME/.virtualenvs' >> "${file}" | |
source "${file}" | |
# Finally, activate the desired default | |
echo -e "\n ${GREEN}-----------${RESET}[ Setup Complete - Activating Environment ]${GREEN}-----------${RESET}" | |
if [ $DEFAULT_VERSION == "3" ]; then | |
workon env-${py3version} | |
else | |
workon env-${py2version} | |
fi | |
# Install or upgrade a package to ALL virtualenvs | |
#allvirtualenv pip install django | |
#allvirtualenv pip install -U django |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment